From 245f8ba0d313c244d22075b38189090ab41d80e2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9C=A4=ED=98=84=EC=8B=9D/On-Device=20Lab=28SR=29/Princip?= =?utf8?q?al=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Thu, 1 Aug 2019 12:34:33 +0900 Subject: [PATCH] [tf2tflite] Schema for additional info of Custom Op from user (#5939) * [tf2tflite] Schema for additional info of Custom Op from user This is a schema for additional info of Custom Op from user. It was committed into _moco-tf_ but moved to here. The name was renamed to CompileInfo.pbtxt (Previous name was Model.MetaInfo.pbtxt), which seems more friendlier. :-) Signed-off-by: Hyun Sik Yoon * renaming CompileInfo to CustomInfo && move ./proto/CMakeFiles.txt to ./CMakeFiles.txt * modify DT_INT32 to 15 --- compiler/tf2tflite/CMakeLists.txt | 17 +++++++++ compiler/tf2tflite/proto/CustomOpInfo.proto | 57 +++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 compiler/tf2tflite/proto/CustomOpInfo.proto diff --git a/compiler/tf2tflite/CMakeLists.txt b/compiler/tf2tflite/CMakeLists.txt index 54d1d01..54b3175 100644 --- a/compiler/tf2tflite/CMakeLists.txt +++ b/compiler/tf2tflite/CMakeLists.txt @@ -13,6 +13,23 @@ if(NOT TARGET exo_tflite) return() endif(NOT TARGET exo_tflite) +nncc_find_package(Protobuf QUIET) + +if(NOT Protobuf_FOUND) + return() +endif(NOT Protobuf_FOUND) + +# generating and building schema for CustomOp.info +Protobuf_Generate(CUSTOMOP_INFO_PROTO + "${CMAKE_CURRENT_BINARY_DIR}/generated" + "./proto" + CustomOpInfo.proto) + +add_library(tf2tflite_customop_info_proto STATIC ${CUSTOMOP_INFO_PROTO_SOURCES}) +set_target_properties(tf2tflite_customop_info_proto PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_include_directories(tf2tflite_customop_info_proto PUBLIC ${CUSTOMOP_INFO_PROTO_INCLUDE_DIRS}) +target_link_libraries(tf2tflite_customop_info_proto PUBLIC libprotobuf) + file(GLOB_RECURSE SOURCES "src/*.cpp") add_executable(tf2tflite ${SOURCES}) diff --git a/compiler/tf2tflite/proto/CustomOpInfo.proto b/compiler/tf2tflite/proto/CustomOpInfo.proto new file mode 100644 index 0000000..b8c4d16 --- /dev/null +++ b/compiler/tf2tflite/proto/CustomOpInfo.proto @@ -0,0 +1,57 @@ +syntax = "proto3"; + +package tf2tflite; +option cc_enable_arenas = true; + + /* example of prototxt file + custom_op { + name: "my/customOp/000" + op: "new_custom_op" + attr { + key: "output_shape" + value { + shape { + dim { size: 1 } + dim { size: 2 } + dim { size: 1 } + dim { size: 2 } + } + } + } + } +*/ + +enum DataType { + // Not a legal value for DataType. Used to indicate a DataType field + // has not been set. + DT_INVALID = 0; + + DT_FLOAT = 1; + DT_INT32 = 15; // Set to 15, considering possibility for reordering. 10 for INT, 10+N for INT 2^N + // TODO Support more types +} + +message ShapeProto { + message Dim { + int64 size = 1; // tensorflow uses int64 + }; + + repeated Dim dim = 2; +} + +message AttrValue { + oneof value { + ShapeProto shape = 1; + DataType type = 2; + } +} + +message CustomOpDef { + string name = 1; + string op = 2; + map attr = 3; +} + +message CustomOpInfoDef { + repeated CustomOpDef custom_op = 1; +} -- 2.7.4