[exo] Export TFLDepthwiseConv2D (#8396)
author박천교/On-Device Lab(SR)/Engineer/삼성전자 <ch.bahk@samsung.com>
Wed, 23 Oct 2019 00:02:07 +0000 (09:02 +0900)
committer박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 23 Oct 2019 00:02:07 +0000 (09:02 +0900)
This commit introduces export stage for TFLDepthwiseConv2D

Signed-off-by: Cheongyo Bahk <ch.bahk@samsung.com>
compiler/exo/src/TFLite/TFLOperationExporter.cpp

index e7edaf8..8f1299c 100644 (file)
@@ -56,7 +56,7 @@ public:
   void visit(locoex::TFLConcatenation *) final;
   void visit(locoex::TFLConst *) final{/* skip, everything is done in exportOpDefinedTensors */};
   void visit(locoex::TFLConv2D *) final;
-  // TODO TFLDepthwiseConv2D
+  void visit(locoex::TFLDepthwiseConv2D *) final;
   void visit(locoex::TFLDiv *) final;
   void visit(locoex::TFLMaxPool2D *) final;
   void visit(locoex::TFLMul *) final;
@@ -173,7 +173,26 @@ void OperationExporter::visit(locoex::TFLConv2D *node)
   gd._operators.push_back(op_offset);
 }
 
-// TODO TFLDepthwiseConv2D
+void OperationExporter::visit(locoex::TFLDepthwiseConv2D *node)
+{
+  uint32_t op_idx = gd.registerBuiltinOpcode(tflite::BuiltinOperator_DEPTHWISE_CONV_2D);
+
+  // Make input, output and options for operator
+  std::vector<int32_t> inputs_vec{get_tensor_index(node->input()), get_tensor_index(node->filter()),
+                                  get_tensor_index(node->bias())};
+  std::vector<int32_t> outputs_vec{get_tensor_index(static_cast<loco::Node *>(node))};
+  auto inputs = builder.CreateVector(inputs_vec);
+  auto outputs = builder.CreateVector(outputs_vec);
+  tflite::Padding padding = getOpPadding(node->padding());
+  auto options = CreateDepthwiseConv2DOptions(builder, padding, node->stride()->w(),
+                                              node->stride()->h(), node->depthMultiplier(),
+                                              to_tflite_actfunc(node->fusedActivationFunction()));
+
+  // Make DEPTHWISE_CONV_2D operator
+  auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
+                                  tflite::BuiltinOptions_DepthwiseConv2DOptions, options.Union());
+  gd._operators.push_back(op_offset);
+}
 
 void OperationExporter::visit(locoex::TFLDiv *node)
 {