From f62a3cf7e0625a15469c188b8350f7158d8bf8c0 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: Wed, 25 Jul 2018 10:49:40 +0900 Subject: [PATCH] [Model Parser] Prepare argument (#2068) Prepare argument input - verbose level (-v, -vv) - tensor list (-t ...) - operator list (-o ...) Signed-off-by: Hyeongseok Oh --- tools/tflitefile_tool/model_parser.py | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tools/tflitefile_tool/model_parser.py b/tools/tflitefile_tool/model_parser.py index 5e9c0d3..35b8f87 100755 --- a/tools/tflitefile_tool/model_parser.py +++ b/tools/tflitefile_tool/model_parser.py @@ -21,6 +21,42 @@ class TFLiteModelFileParser(object): # Read flatbuffer file descriptor using argument self.tflite_file = args.input_file + # Set print level (0 ~ 2) + # TODO: print information based on level + self.print_level = args.verbose + if (args.verbose > 2): + self.print_level = 2 + if (args.verbose < 0): + self.print_level = 0 + + # Set tensor index list to print information + # TODO: + # Print tensors in list only + # Print all tensors if argument used and not specified index number + if (args.tensor != None): + if (len(args.tensor) == 0): + self.print_all_tensor = True + else: + self.print_all_tensor = False + self.print_tensor_index = [] + + for tensor_index in args.tensor: + self.print_tensor_index.append(int(tensor_index)) + + # Set operator index list to print information + # TODO: + # Print operators in list only + # Print all operators if argument used and not specified index number + if (args.operator != None): + if (len(args.operator) == 0): + self.print_all_oeprator = True + else: + self.print_all_oeprator = False + self.print_operator_index = [] + + for operator_index in args.operator: + self.print_operator_index.append(int(operator_index)) + def main(self): # Generate Model: top structure of tflite model file buf = self.tflite_file.read() @@ -55,6 +91,19 @@ if __name__ == '__main__': arg_parser = argparse.ArgumentParser() arg_parser.add_argument( "input_file", type=argparse.FileType('rb'), help="tflite file to read") + arg_parser.add_argument( + '-v', + '--verbose', + action='count', + default=0, + help="set print level (0~2, default: 0)") + arg_parser.add_argument( + '-t', '--tensor', nargs='*', help="tensor ID to print information (default: all)") + arg_parser.add_argument( + '-o', + '--operator', + nargs='*', + help="operator ID to print information (default: all)") args = arg_parser.parse_args() # Call main function -- 2.7.4