[MachineLearning.Train] Add AddLayer to Model class
authorHyunil <hyunil46.park@samsung.com>
Wed, 15 Jun 2022 00:03:54 +0000 (09:03 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Tue, 23 Aug 2022 05:50:26 +0000 (14:50 +0900)
- Add AddLayer(Layer layer)
- Add ml_train_model_add_layer() to interop
- Add some log to Model class

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

index 9487860..1833b61 100644 (file)
@@ -50,9 +50,13 @@ internal static partial class Interop
         [DllImport(Libraries.Nntrainer, EntryPoint = "ml_train_model_save")]
         public static extern NNTrainerError Save(IntPtr modelHandle, string filePath, NNTrainerModelFormat format);
 
-        /* int ml_train_model_load(ml_train_model_h model, const char *file_path, ml_train_model_format_e 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 modelHandle, string filePath, NNTrainerModelFormat format);
 
+        /* int ml_train_model_add_layer(ml_train_model_h model, ml_train_layer_h layer) */
+        [DllImport(Libraries.Nntrainer, EntryPoint = "ml_train_model_add_layer")]
+        public static extern NNTrainerError AddLayer(IntPtr modelHandle, IntPtr layerHandle);
+
     }
 }
index 9979f38..0a64465 100644 (file)
@@ -111,5 +111,10 @@ namespace Tizen.MachineLearning.Train
             NNTrainerError ret = Interop.Layer.SetProperty(handle, propertyParams);
             NNTrainer.CheckException(ret, "Failed to set property");
         }
+
+        internal IntPtr GetHandle()
+        {
+            return handle;
+        }
     } 
 }
index 8f656b0..e4cd9cd 100644 (file)
@@ -46,6 +46,7 @@ namespace Tizen.MachineLearning.Train
         {
             NNTrainerError ret = Interop.Model.Construct(out handle);
             NNTrainer.CheckException(ret, "Failed to create model instance");
+            Log.Info(NNTrainer.Tag, "Created Model");
         }
 
         /// <summary>
@@ -57,9 +58,10 @@ 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");
+            Log.Info(NNTrainer.Tag, "Created Model with Conf path: "+ modelConf);
         }
         /// <summary>
         /// Destructor of Model
@@ -230,5 +232,24 @@ namespace Tizen.MachineLearning.Train
             NNTrainerError ret = Interop.Model.Load(handle, filePath, format);
             NNTrainer.CheckException(ret, "Failed to load model to path");
         }
+
+        /// <summary>
+        /// Adds layer in neural network model.
+        /// </summary>
+        /// <remarks>
+        /// Use this function to add a layer to the model. The layer is added to
+        /// the end of the existing layers in the model. This transfers the
+        /// ownership of the layer to the network. No need to destroy the layer once it
+        /// is added to a model.
+        /// </remarks>
+        /// <param name="layer"> The instance of Layer class </param>
+        /// <since_tizen> 10 </since_tizen>
+        public void AddLayer(Layer layer)
+        {
+            if (layer == null)
+                NNTrainer.CheckException(NNTrainerError.InvalidParameter, "layer instance is null");
+            NNTrainerError ret = Interop.Model.AddLayer(handle, layer.GetHandle());
+            NNTrainer.CheckException(ret, "Failed to compile model");
+        }
     } 
 }