From c711598e84ecc0256ce46d5197dba7ccd6aeb769 Mon Sep 17 00:00:00 2001 From: Hyunil Date: Tue, 17 May 2022 16:48:34 +0900 Subject: [PATCH] [MachineLearning.Train] Add Compile method to Model class - Add Compile(param string[] args) - Add ml_train_model_compile_with_single_param() to interop Signed-off-by: Hyunil --- .../Interop/Interop.Model.cs | 4 ++++ .../Tizen.MachineLearning.Train/Model.cs | 27 +++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Tizen.MachineLearning.Train/Interop/Interop.Model.cs b/src/Tizen.MachineLearning.Train/Interop/Interop.Model.cs index f50d4e6..9b217d5 100644 --- a/src/Tizen.MachineLearning.Train/Interop/Interop.Model.cs +++ b/src/Tizen.MachineLearning.Train/Interop/Interop.Model.cs @@ -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); } } diff --git a/src/Tizen.MachineLearning.Train/Tizen.MachineLearning.Train/Model.cs b/src/Tizen.MachineLearning.Train/Tizen.MachineLearning.Train/Model.cs index c132fdd..bc9d769 100644 --- a/src/Tizen.MachineLearning.Train/Tizen.MachineLearning.Train/Model.cs +++ b/src/Tizen.MachineLearning.Train/Tizen.MachineLearning.Train/Model.cs @@ -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; } + + /// + /// Compiles and finalizes the neural network model with the hyperparameter. + /// + /// + /// 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. + /// Hyperparameters for train complie. + /// + /// 10 + 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"); + } } } -- 2.7.4