[MachineLearning.Train] Add Load method to Model class
authorHyunil <hyunil46.park@samsung.com>
Thu, 26 May 2022 11:04:46 +0000 (20:04 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Tue, 23 Aug 2022 05:50:26 +0000 (14:50 +0900)
- Add Load(string FilePath, NNTrainerModelFormat format)
- Add ml_train_model_load() 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 9f2ff66..b0699b1 100644 (file)
@@ -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);
+
     }
 }
index 84a7aaf..afe8256 100644 (file)
@@ -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");
         }
+
+        /// <summary>
+        /// Loads the model.
+        /// </summary>
+        /// <remarks>
+        /// 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.
+        /// </remarks>
+        /// <param name="FilePath">File path to load the file.</param>
+        /// <param name="format">Format flag to determine which format should be used to load.</param>
+        /// <since_tizen> 10 </since_tizen>
+        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");
+        }
     } 
 }