[tf2tflite] Schema for additional info of Custom Op from user (#5939)
author윤현식/On-Device Lab(SR)/Principal Engineer/삼성전자 <hyunsik.yoon@samsung.com>
Thu, 1 Aug 2019 03:34:33 +0000 (12:34 +0900)
committer박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 1 Aug 2019 03:34:33 +0000 (12:34 +0900)
* [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 <hyunsik.yoon@samsung.com>
* renaming CompileInfo to CustomInfo && move ./proto/CMakeFiles.txt to ./CMakeFiles.txt

* modify DT_INT32 to 15

compiler/tf2tflite/CMakeLists.txt
compiler/tf2tflite/proto/CustomOpInfo.proto [new file with mode: 0644]

index 54d1d01..54b3175 100644 (file)
@@ -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 (file)
index 0000000..b8c4d16
--- /dev/null
@@ -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<string, AttrValue> attr = 3;
+}
+
+message CustomOpInfoDef {
+  repeated CustomOpDef custom_op = 1;
+}