[Model Parse] Parsing exceptional case: tensor index (#2593)
author오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Thu, 6 Sep 2018 01:02:22 +0000 (10:02 +0900)
committer이춘석/동작제어Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>
Thu, 6 Sep 2018 01:02:22 +0000 (10:02 +0900)
Parsing exceptional case when tensor index is less than 0

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
tools/tflitefile_tool/operator_parser.py
tools/tflitefile_tool/tensor_wrapping.py

index 2efc528..9728d53 100755 (executable)
@@ -53,6 +53,9 @@ class OperatorParser(object):
     def GetTensors(self, tf_tensors_index):
         return_list = list()
         for tensor_idx in tf_tensors_index:
+            if (tensor_idx < 0):
+                return_list.append(Tensor(tensor_idx, 0, 0))
+                continue
             tf_tensor = self.tf_subgraph.Tensors(tensor_idx)
             buffer_idx = tf_tensor.Buffer()
             tf_buffer = self.tf_model.Buffers(buffer_idx)
index 34d75d3..b1fba57 100755 (executable)
@@ -23,19 +23,23 @@ class Tensor(object):
         self.tf_buffer = tf_buffer
 
     def PrintInfo(self, depth_str=""):
-        buffer_idx = self.tf_tensor.Buffer()
-        isEmpty = "Filled"
-        if (self.tf_buffer.DataLength() == 0):
-            isEmpty = " Empty"
-        shape_str = self.GetShapeString()
-        type_name = TensorTypeList[self.tf_tensor.Type()]
-
-        shape_name = ""
-        if self.tf_tensor.Name() != 0:
-            shape_name = self.tf_tensor.Name()
-
-        print_str = "Tensor {0:4} : buffer {1:4} | {2} | {3:7} | Shape {4} ({5})".format(
-            self.tensor_idx, buffer_idx, isEmpty, type_name, shape_str, shape_name)
+        print_str = ""
+        if self.tensor_idx < 0:
+            print_str = "Tensor {0:4}".format(self.tensor_idx)
+        else:
+            buffer_idx = self.tf_tensor.Buffer()
+            isEmpty = "Filled"
+            if (self.tf_buffer.DataLength() == 0):
+                isEmpty = " Empty"
+            shape_str = self.GetShapeString()
+            type_name = TensorTypeList[self.tf_tensor.Type()]
+
+            shape_name = ""
+            if self.tf_tensor.Name() != 0:
+                shape_name = self.tf_tensor.Name()
+
+            print_str = "Tensor {0:4} : buffer {1:4} | {2} | {3:7} | Shape {4} ({5})".format(
+                self.tensor_idx, buffer_idx, isEmpty, type_name, shape_str, shape_name)
         print(depth_str + print_str)
 
     def GetShapeString(self):