[MachineLearning.Train] Add Compile method to Model class
authorHyunil <hyunil46.park@samsung.com>
Tue, 17 May 2022 07:48:34 +0000 (16:48 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Tue, 23 Aug 2022 05:50:26 +0000 (14:50 +0900)
- Add Compile(param string[] args)
- Add ml_train_model_compile_with_single_param() to interop

Signed-off-by: Hyunil <hyunil46.park@samsung.com>
src/Tizen.MachineLearning.Train/Interop/Interop.Model.cs
src/Tizen.MachineLearning.Train/Tizen.MachineLearning.Train/Model.cs

index f50d4e6..9b217d5 100644 (file)
@@ -33,5 +33,9 @@ internal static partial class Interop
         /* int ml_train_model_construct_with_conf(const char *model_conf, ml_train_model_h *model)*/
         [DllImport(Libraries.Nntrainer, EntryPoint = "ml_train_model_construct_with_conf")]
         public static extern NNTrainerError ConstructWithConf(string model_conf, out IntPtr model_handle);
+
+        /* int ml_train_model_compile_with_params(ml_train_model_h model, const char *params) */
+        [DllImport(Libraries.Nntrainer, EntryPoint = "ml_train_model_compile_with_params")]
+        public static extern NNTrainerError Compile(IntPtr model_handle, string compile_params);
     }
 }
index c132fdd..bc9d769 100644 (file)
@@ -57,7 +57,7 @@ namespace Tizen.MachineLearning.Train
         {
             if (string.IsNullOrEmpty(modelConf))
                 NNTrainer.CheckException(NNTrainerError.InvalidParameter, "modelConf is null");
-
+            Log.Info(NNTrainer.Tag, "Conf path: "+ modelConf);
             NNTrainerError ret = Interop.Model.ConstructWithConf(modelConf, out _handle);
             NNTrainer.CheckException(ret, "Failed to create model instance with modelConf");
         }
@@ -105,5 +105,30 @@ namespace Tizen.MachineLearning.Train
             }
             _disposed = true;
         }
+
+        /// <summary>
+        /// Compiles and finalizes the neural network model with the hyperparameter.
+        /// </summary>
+        /// <remarks>
+        /// Use this function to initialize neural network model.Various
+        /// hyperparameter before compile the model can be set. Once compiled,
+        /// any modification to the properties of model or layers/dataset/optimizer in
+        /// the model will be restricted. Further, addition of layers or changing the
+        /// optimizer/dataset of the model will not be permitted.
+        /// <param name="hyperparameter">Hyperparameters for train complie.</param>
+        /// </remarks>
+        /// <since_tizen> 10 </since_tizen>
+        public void Compile(params string[] hyperparameter)
+        {
+            string compile_params = null;
+
+            if (hyperparameter != null) {
+                compile_params = string.Join("`", hyperparameter);
+                Log.Info(NNTrainer.Tag, "Compile hyperparameter:"+ compile_params);
+            }
+
+            NNTrainerError ret = Interop.Model.Compile(_handle, compile_params);
+            NNTrainer.CheckException(ret, "Failed to compile model");
+        }
     } 
 }