[MachineLearning.Train] Add run method to Model class
authorHyunil <hyunil46.park@samsung.com>
Wed, 25 May 2022 02:41:17 +0000 (11:41 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Tue, 23 Aug 2022 05:50:26 +0000 (14:50 +0900)
- Add Run(param string[] args)
- Add ml_train_model_run_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 9b217d5..63a30c8 100644 (file)
@@ -35,7 +35,11 @@ internal static partial class Interop
         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")]
+        [DllImport(Libraries.Nntrainer, EntryPoint = "ml_train_model_compile_with_single_param")]
         public static extern NNTrainerError Compile(IntPtr model_handle, string compile_params);
+
+        /* int ml_train_model_run(ml_train_model_h model, ...) */
+        [DllImport(Libraries.Nntrainer, EntryPoint = "ml_train_model_run_with_single_param")]
+        public static extern NNTrainerError Run(IntPtr model_handle, string run_params);
     }
 }
index bc9d769..f7e596c 100644 (file)
@@ -123,12 +123,36 @@ namespace Tizen.MachineLearning.Train
             string compile_params = null;
 
             if (hyperparameter != null) {
-                compile_params = string.Join("`", hyperparameter);
+                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");
         }
+
+        /// <summary>
+        /// Trains the neural network model with the hyperparameter.
+        /// </summary>
+        /// <remarks>
+        /// Use this function to train the compiled neural network model with
+        /// the passed training hyperparameters. This function will return once the
+        /// training, along with requested validation and testing, is completed.
+        /// </remarks>
+        /// <param name="hyperparameter">Hyperparameters for train model.</param>
+        /// <since_tizen> 10 </since_tizen>
+        public void Run(params string[] hyperparameter)
+        {
+            string run_params = null;
+
+            if (hyperparameter != null) {
+                run_params = string.Join("|", hyperparameter);
+                Log.Info(NNTrainer.Tag, "Run hyperparameter:"+ run_params);
+            }
+
+            NNTrainerError ret = Interop.Model.Run(_handle, run_params);
+            NNTrainer.CheckException(ret, "Failed to run model");
+        }
+
     } 
 }