From 9f68818d4a0154c1309f6d37c08d7813e5ac3518 Mon Sep 17 00:00:00 2001 From: Hyunil Date: Fri, 1 Jul 2022 14:27:21 +0900 Subject: [PATCH] [MachineLearning.Train] Modify getLayer method to return layer instance - getLayer method return layer instance instead of layer handle Signed-off-by: Hyunil --- .../Tizen.MachineLearning.Train/Layer.cs | 16 +++++++++++++++- .../Tizen.MachineLearning.Train/Model.cs | 13 +++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/Tizen.MachineLearning.Train/Tizen.MachineLearning.Train/Layer.cs b/src/Tizen.MachineLearning.Train/Tizen.MachineLearning.Train/Layer.cs index 0a64465..66f4f35 100644 --- a/src/Tizen.MachineLearning.Train/Tizen.MachineLearning.Train/Layer.cs +++ b/src/Tizen.MachineLearning.Train/Tizen.MachineLearning.Train/Layer.cs @@ -33,6 +33,9 @@ namespace Tizen.MachineLearning.Train private IntPtr handle = IntPtr.Zero; private bool disposed = false; + /// if true, model will be destroy layer handle + private bool notDestroy = false; + /// /// Creates a neural network layer. /// @@ -44,6 +47,12 @@ namespace Tizen.MachineLearning.Train NNTrainer.CheckException(ret, "Failed to create model instance"); Log.Info(NNTrainer.Tag, $"Create layer with type:{type}"); } + + internal Layer(bool createdByModel) + { + notDestroy = createdByModel; + } + /// /// Frees the neural network layer. /// @@ -80,7 +89,7 @@ namespace Tizen.MachineLearning.Train // release managed object } // release unmanaged object - if (handle != IntPtr.Zero) + if (handle != IntPtr.Zero && !notDestroy) { // Destroy the neural network layer. NNTrainerError ret = Interop.Layer.Destroy(handle); @@ -116,5 +125,10 @@ namespace Tizen.MachineLearning.Train { return handle; } + + internal void SetHandle(IntPtr layerHandle) + { + handle = layerHandle; + } } } diff --git a/src/Tizen.MachineLearning.Train/Tizen.MachineLearning.Train/Model.cs b/src/Tizen.MachineLearning.Train/Tizen.MachineLearning.Train/Model.cs index 7e62522..dc8e1e1 100644 --- a/src/Tizen.MachineLearning.Train/Tizen.MachineLearning.Train/Model.cs +++ b/src/Tizen.MachineLearning.Train/Tizen.MachineLearning.Train/Model.cs @@ -16,7 +16,6 @@ using static Interop; using System; using System.IO; - namespace Tizen.MachineLearning.Train { /// @@ -261,15 +260,21 @@ namespace Tizen.MachineLearning.Train /// The returned layer must not be deleted as it is owned by the model. /// /// Name of the already created layer. - /// layer handle from the given description. + /// layer instance /// 10 - public void GetLayer(string layerName, out IntPtr layerHandle) + public Layer GetLayer(string layerName) { + IntPtr layerHandle = IntPtr.Zero; 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"); + + Layer layer = new Layer(true); + layer.SetHandle(layerHandle); + + return layer; } /// -- 2.7.4