From 60ac3c10c0f53b1874006f3eea45ed098e5b85df Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=B2=9C=EA=B5=90/On-Device=20Lab=28SR=29/Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Tue, 5 Nov 2019 10:40:43 +0900 Subject: [PATCH] [exo] Export TFLMean (#8740) This commit implements export stage of TFLMean for both tflite and circle output Signed-off-by: Cheongyo Bahk --- compiler/exo/src/Circle/CircleOperationExporter.cpp | 15 +++++++++++++++ compiler/exo/src/TFLite/TFLOperationExporter.cpp | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/compiler/exo/src/Circle/CircleOperationExporter.cpp b/compiler/exo/src/Circle/CircleOperationExporter.cpp index 42820ee..7b8c636 100644 --- a/compiler/exo/src/Circle/CircleOperationExporter.cpp +++ b/compiler/exo/src/Circle/CircleOperationExporter.cpp @@ -59,6 +59,7 @@ public: void visit(locoex::TFLDepthwiseConv2D *) final; void visit(locoex::TFLDiv *) final; void visit(locoex::TFLMaxPool2D *) final; + void visit(locoex::TFLMean *) final; void visit(locoex::TFLMul *) final; void visit(locoex::TFLRelu *) final; void visit(locoex::TFLRelu6 *) final; @@ -214,6 +215,20 @@ void OperationExporter::visit(locoex::TFLMaxPool2D *node) export_pool_2d(node, circle::BuiltinOperator_MAX_POOL_2D); } +void OperationExporter::visit(locoex::TFLMean *node) +{ + uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_MEAN); + std::vector inputs_vec{get_tensor_index(node->input()), + get_tensor_index(node->reduction_indices())}; + std::vector outputs_vec{get_tensor_index(static_cast(node))}; + auto inputs = builder.CreateVector(inputs_vec); + auto outputs = builder.CreateVector(outputs_vec); + auto options = CreateReducerOptions(builder, node->keep_dims()); + auto op_offset = CreateOperator(builder, op_idx, inputs, outputs, + circle::BuiltinOptions_ReducerOptions, options.Union()); + gd._operators.push_back(op_offset); +} + void OperationExporter::visit(locoex::TFLMul *node) { uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_MUL); diff --git a/compiler/exo/src/TFLite/TFLOperationExporter.cpp b/compiler/exo/src/TFLite/TFLOperationExporter.cpp index 0a2c8f9..6a56e8b 100644 --- a/compiler/exo/src/TFLite/TFLOperationExporter.cpp +++ b/compiler/exo/src/TFLite/TFLOperationExporter.cpp @@ -59,6 +59,7 @@ public: void visit(locoex::TFLDepthwiseConv2D *) final; void visit(locoex::TFLDiv *) final; void visit(locoex::TFLMaxPool2D *) final; + void visit(locoex::TFLMean *) final; void visit(locoex::TFLMul *) final; void visit(locoex::TFLRelu *) final; void visit(locoex::TFLRelu6 *) final; @@ -214,6 +215,20 @@ void OperationExporter::visit(locoex::TFLMaxPool2D *node) export_pool_2d(node, tflite::BuiltinOperator_MAX_POOL_2D); } +void OperationExporter::visit(locoex::TFLMean *node) +{ + uint32_t op_idx = gd.registerBuiltinOpcode(tflite::BuiltinOperator_MEAN); + std::vector inputs_vec{get_tensor_index(node->input()), + get_tensor_index(node->reduction_indices())}; + std::vector outputs_vec{get_tensor_index(static_cast(node))}; + auto inputs = builder.CreateVector(inputs_vec); + auto outputs = builder.CreateVector(outputs_vec); + auto options = CreateReducerOptions(builder, node->keep_dims()); + auto op_offset = CreateOperator(builder, op_idx, inputs, outputs, + tflite::BuiltinOptions_ReducerOptions, options.Union()); + gd._operators.push_back(op_offset); +} + void OperationExporter::visit(locoex::TFLMul *node) { uint32_t op_idx = gd.registerBuiltinOpcode(tflite::BuiltinOperator_MUL); -- 2.7.4