From a75c73782b4cd1ce22f5750ab8f7f4664be9ae01 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=98=A4=ED=98=95=EC=84=9D/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Thu, 6 Sep 2018 10:02:22 +0900 Subject: [PATCH] [Model Parse] Parsing exceptional case: tensor index (#2593) Parsing exceptional case when tensor index is less than 0 Signed-off-by: Hyeongseok Oh --- tools/tflitefile_tool/operator_parser.py | 3 +++ tools/tflitefile_tool/tensor_wrapping.py | 30 +++++++++++++++++------------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/tools/tflitefile_tool/operator_parser.py b/tools/tflitefile_tool/operator_parser.py index 2efc528..9728d53 100755 --- a/tools/tflitefile_tool/operator_parser.py +++ b/tools/tflitefile_tool/operator_parser.py @@ -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) diff --git a/tools/tflitefile_tool/tensor_wrapping.py b/tools/tflitefile_tool/tensor_wrapping.py index 34d75d3..b1fba57 100755 --- a/tools/tflitefile_tool/tensor_wrapping.py +++ b/tools/tflitefile_tool/tensor_wrapping.py @@ -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): -- 2.7.4