[MachineLearning.Inference][Non-ACR] Fix the potential bug (#2547)
authorSangjung Woo <sangjung.woo@samsung.com>
Wed, 17 Feb 2021 00:51:10 +0000 (09:51 +0900)
committerGitHub <noreply@github.com>
Wed, 17 Feb 2021 00:51:10 +0000 (09:51 +0900)
* [MachineLearning.Inference] Update the version number of the shared library

This patch updates the version number of the nnstreamer library.
* libcapi-nnstreamer.so.0 -> libcapi-nnstreamer.so.1

Signed-off-by: Sangjung Woo <sangjung.woo@samsung.com>
* [MachineLearning.Inference] Remove the name comparision in TensorsInfo.Equals()

Since the name of the TensorsInfo is not used when negociating the
pipeline, the name comparison in TensorsInfo.Equals() should be removed.

Signed-off-by: Sangjung Woo <sangjung.woo@samsung.com>
* [MachineLearning.Inference] Add Clone() to TensorsInfo class for deep copy

It is not a common case but developers can modify the TensorsInfo after
creating the TensorsData. Because of this reason, TensorsData should
have a hard-copied instance of the TensorsInfo object. If not, it shows
the wrong information of TensorsData. This patch fixes this potential
bug.

Signed-off-by: Sangjung Woo <sangjung.woo@samsung.com>
src/Tizen.MachineLearning.Inference/Interop/Interop.Nnstreamer.cs
src/Tizen.MachineLearning.Inference/Tizen.MachineLearning.Inference/TensorsData.cs
src/Tizen.MachineLearning.Inference/Tizen.MachineLearning.Inference/TensorsInfo.cs

index cba86ab..2dcd22f 100755 (executable)
@@ -22,7 +22,7 @@ internal static partial class Interop
 {
     internal static partial class Libraries
     {
-        public const string Nnstreamer = "libcapi-nnstreamer.so.0";
+        public const string Nnstreamer = "libcapi-nnstreamer.so.1";
     }
 
     internal static partial class Pipeline
index ca6a6fc..330aacc 100755 (executable)
@@ -34,7 +34,7 @@ namespace Tizen.MachineLearning.Inference
         /// Creates a TensorsData instance with handle which is given by TensorsInfo.
         /// </summary>
         /// <param name="handle">The handle of tensors data.</param>
-        /// <param name="info">The handle of tensors info. (Default: null)</param>
+        /// <param name="info">The handle of tensors info.</param>
         /// <param name="isFetch">The boolean value for fetching the data (Default: false)</param>
         /// <param name="hasOwnership">The boolean value for automatic disposal (Default: true)</param>
         /// <since_tizen> 6 </since_tizen>
@@ -45,7 +45,8 @@ namespace Tizen.MachineLearning.Inference
 
             /* Set internal object */
             _handle = handle;
-            _tensorsInfo = info;
+            /* Because developers can change the TensorsInfo object, it should be stored as a deep-copied instance. */
+            _tensorsInfo = info.Clone();
 
             /* Set count */
             int count = 0;
@@ -202,6 +203,8 @@ namespace Tizen.MachineLearning.Inference
             if (disposing)
             {
                 // release managed object
+                _tensorsInfo.Dispose();
+                _tensorsInfo = null;
             }
 
             // release unmanaged objects
index d9f1d7c..2df0d49 100755 (executable)
@@ -327,10 +327,6 @@ namespace Tizen.MachineLearning.Inference
 
             for (int i = 0; i < this.Count; ++i)
             {
-                // Name
-                if (string.Compare(this.GetTensorName(i), other.GetTensorName(i)) != 0)
-                    return false;
-
                 // Type
                 if (this.GetTensorType(i) != other.GetTensorType(i))
                     return false;
@@ -343,6 +339,23 @@ namespace Tizen.MachineLearning.Inference
         }
 
         /// <summary>
+        /// Create a new TensorsInfo object cloned from the current tensors information.
+        /// </summary>
+        /// <returns>Hard-copied TensorsInfo object</returns>
+        /// <since_tizen> 9 </since_tizen>
+        internal TensorsInfo Clone()
+        {
+            TensorsInfo retInfo = null;
+            retInfo = new TensorsInfo();
+
+            foreach (TensorInfo t in _infoList) {
+                retInfo.AddTensorInfo(t.Name, t.Type, t.Dimension);
+            }
+
+            return retInfo;
+        }
+
+        /// <summary>
         /// Make TensorsInfo object from Native handle
         /// </summary>
         /// <param name="handle">Handle of TensorsInfo object</param>