From c24e521a0eb67def333ea36f11a4cf0ef8a23690 Mon Sep 17 00:00:00 2001 From: Hyunil Date: Thu, 26 May 2022 20:04:46 +0900 Subject: [PATCH] [MachineLearning.Train] Add Load method to Model class - Add Load(string FilePath, NNTrainerModelFormat format) - Add ml_train_model_load() to interop Signed-off-by: Hyunil --- .../Interop/Interop.Model.cs | 5 ++++ .../Tizen.MachineLearning.Train/Model.cs | 30 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/Tizen.MachineLearning.Train/Interop/Interop.Model.cs b/src/Tizen.MachineLearning.Train/Interop/Interop.Model.cs index 9f2ff66..b0699b1 100644 --- a/src/Tizen.MachineLearning.Train/Interop/Interop.Model.cs +++ b/src/Tizen.MachineLearning.Train/Interop/Interop.Model.cs @@ -49,5 +49,10 @@ internal static partial class Interop /* int ml_train_model_save(ml_train_model_h model, const char *file_path, ml_train_model_format_e format) */ [DllImport(Libraries.Nntrainer, EntryPoint = "ml_train_model_save")] public static extern NNTrainerError Save(IntPtr model_handle, string file_path, NNTrainerModelFormat format); + + /* int ml_train_model_load(ml_train_model_h model, const char *file_path, ml_train_model_format_e format); */ + [DllImport(Libraries.Nntrainer, EntryPoint = "ml_train_model_load")] + public static extern NNTrainerError Load(IntPtr model_handle, string file_path, NNTrainerModelFormat format); + } } diff --git a/src/Tizen.MachineLearning.Train/Tizen.MachineLearning.Train/Model.cs b/src/Tizen.MachineLearning.Train/Tizen.MachineLearning.Train/Model.cs index 84a7aaf..afe8256 100644 --- a/src/Tizen.MachineLearning.Train/Tizen.MachineLearning.Train/Model.cs +++ b/src/Tizen.MachineLearning.Train/Tizen.MachineLearning.Train/Model.cs @@ -200,5 +200,35 @@ namespace Tizen.MachineLearning.Train NNTrainerError ret = Interop.Model.Save(_handle, FilePath, format); NNTrainer.CheckException(ret, "Failed to save model to path"); } + + /// + /// Loads the model. + /// + /// + /// Use this function to load the current model. format + /// describes various formats in which various selections of the + /// parameters of the models can be loaded. Some formats may load + /// parameters required for training. Some other formats may load model + /// configurations. Unless stated otherwise, loading model configuration requires + /// a freshly constructed model with new model() without Compile(), + /// loading model parameter requires Compile() to be called upon the model + /// before calling this function. + /// If you want to access only internal storage by using this function, + /// you should add privilege %http://tizen.org/privilege/mediastorage. Or, if you + /// want to access only external storage by using this function, you should add + /// privilege %http://tizen.org/privilege/externalstorage. If you want to access + /// both storage, you must add all the privileges. + /// + /// File path to load the file. + /// Format flag to determine which format should be used to load. + /// 10 + public void Load(string FilePath, NNTrainerModelFormat format) + { + if (string.IsNullOrEmpty(FilePath)) + NNTrainer.CheckException(NNTrainerError.InvalidParameter, "FilePath is null"); + Log.Info(NNTrainer.Tag, "FilePath: "+ FilePath); + NNTrainerError ret = Interop.Model.Load(_handle, FilePath, format); + NNTrainer.CheckException(ret, "Failed to load model to path"); + } } } -- 2.7.4