[MachineLearning.Train] Add GetLayer to Model class
authorHyunil <hyunil46.park@samsung.com>
Wed, 15 Jun 2022 05:44:53 +0000 (14:44 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Tue, 23 Aug 2022 05:50:26 +0000 (14:50 +0900)
- Add GetLayer(string layerName, out IntPtr layerHandle)
- Add ml_train_model_get_layer() 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 1833b61..21f9b42 100644 (file)
@@ -30,7 +30,7 @@ internal static partial class Interop
         [DllImport(Libraries.Nntrainer, EntryPoint = "ml_train_model_destroy")]
         public static extern NNTrainerError Destroy(IntPtr modelHandle);
 
-        /* int ml_train_model_construct_with_conf(const char *model_conf, ml_train_model_h *model)*/
+        /* 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 modelConf, out IntPtr modelHandle);
 
@@ -58,5 +58,9 @@ internal static partial class Interop
         [DllImport(Libraries.Nntrainer, EntryPoint = "ml_train_model_add_layer")]
         public static extern NNTrainerError AddLayer(IntPtr modelHandle, IntPtr layerHandle);
 
+        /* int ml_train_model_get_layer(ml_train_model_h model, const char *layer_name, ml_train_layer_h *layer) */
+        [DllImport(Libraries.Nntrainer, EntryPoint = "ml_train_model_get_layer")]
+        public static extern NNTrainerError GetLayer(IntPtr modelHandle, string layerName, out IntPtr layer);
+
     }
 }
index e4cd9cd..f15fe28 100644 (file)
@@ -250,6 +250,26 @@ namespace Tizen.MachineLearning.Train
                 NNTrainer.CheckException(NNTrainerError.InvalidParameter, "layer instance is null");
             NNTrainerError ret = Interop.Model.AddLayer(handle, layer.GetHandle());
             NNTrainer.CheckException(ret, "Failed to compile model");
+            Log.Info("MLT", $"AddLayer:\n{layer.GetHandle()}");
+        }
+
+        /// <summary>
+        /// Gets neural network layer from the model with the given name.
+        /// </summary>
+        /// <remarks>
+        /// Use this function to get already created Neural Network Layer.
+        /// The returned layer must not be deleted as it is owned by the model.
+        /// </remarks>
+        /// <param name="layerName"> Name of the already created layer.</param>
+        /// <param name="layerHandle"> layer handle from the given description.</param>
+        /// <since_tizen> 10 </since_tizen>
+        public void GetLayer(string layerName, out IntPtr layerHandle)
+        {
+             if (string.IsNullOrEmpty(layerName))
+                NNTrainer.CheckException(NNTrainerError.InvalidParameter, "layerName is null");
+            /* FiX_ME : how to handle layerHandle */
+            NNTrainerError ret = Interop.Model.GetLayer(handle, layerName, out layerHandle);
+            NNTrainer.CheckException(ret, "Failed to get layer");
         }
     } 
 }