From 1779663783ee935d62c225eaa5da2f66e048bf81 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9C=A4=EC=A7=80=EC=98=81/On-Device=20Lab=2E/Engineer/?= =?utf8?q?=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Tue, 18 Dec 2018 08:58:32 +0900 Subject: [PATCH] [tflchef] Add Sub for reverse (#2697) This will add Sub Op for tflchef-reverse Signed-off-by: Jiyoung Yun --- contrib/tflchef/tests/sub/test.reverse | 0 contrib/tflchef/tflite/src/Op/Sub.cpp | 48 +++++++++++++++++++++++++++ contrib/tflchef/tflite/src/Op/Sub.h | 39 ++++++++++++++++++++++ contrib/tflchef/tflite/src/TFliteOpChefs.h | 1 + contrib/tflchef/tflite/src/TFliteOpRegistry.h | 1 + 5 files changed, 89 insertions(+) create mode 100644 contrib/tflchef/tests/sub/test.reverse create mode 100644 contrib/tflchef/tflite/src/Op/Sub.cpp create mode 100644 contrib/tflchef/tflite/src/Op/Sub.h diff --git a/contrib/tflchef/tests/sub/test.reverse b/contrib/tflchef/tests/sub/test.reverse new file mode 100644 index 0000000..e69de29 diff --git a/contrib/tflchef/tflite/src/Op/Sub.cpp b/contrib/tflchef/tflite/src/Op/Sub.cpp new file mode 100644 index 0000000..db77fdd --- /dev/null +++ b/contrib/tflchef/tflite/src/Op/Sub.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Sub.h" + +#include "Convert.h" + +namespace tflchef +{ + +void TFliteOpSub::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + // Nothing to do with filler +} + +tflchef::Operation *TFliteOpSub::build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + auto op_params = op->builtin_options_as_SubOptions(); + assert(op_params != nullptr); + + auto operation = model_recipe->add_operation(); + + operation->set_type("Sub"); + + auto op_options = operation->mutable_sub_options(); + + auto tflchef_activation = as_tflchef_activation(op_params->fused_activation_function()); + op_options->set_activation(tflchef_activation); + + return operation; +} + +} // namespace tflchef diff --git a/contrib/tflchef/tflite/src/Op/Sub.h b/contrib/tflchef/tflite/src/Op/Sub.h new file mode 100644 index 0000000..2168e5e --- /dev/null +++ b/contrib/tflchef/tflite/src/Op/Sub.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __TFLITE_OP_SUB_H__ +#define __TFLITE_OP_SUB_H__ + +#include "TFliteOpChef.h" + +namespace tflchef +{ + +/** + * @brief tflchef operator builder for Sub + */ +class TFliteOpSub : public TFliteOpChef +{ +public: + void filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; + tflchef::Operation *build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; +}; + +} // namespace tflchef + +#endif // __TFLITE_OP_SUB_H__ diff --git a/contrib/tflchef/tflite/src/TFliteOpChefs.h b/contrib/tflchef/tflite/src/TFliteOpChefs.h index 2d3c747..c12d1ad 100644 --- a/contrib/tflchef/tflite/src/TFliteOpChefs.h +++ b/contrib/tflchef/tflite/src/TFliteOpChefs.h @@ -26,5 +26,6 @@ #include "Op/ReLU.h" #include "Op/ReLU6.h" #include "Op/Reshape.h" +#include "Op/Sub.h" #endif // __TFLITE_OP_CHEFS_H__ diff --git a/contrib/tflchef/tflite/src/TFliteOpRegistry.h b/contrib/tflchef/tflite/src/TFliteOpRegistry.h index 7383603..db21b60 100644 --- a/contrib/tflchef/tflite/src/TFliteOpRegistry.h +++ b/contrib/tflchef/tflite/src/TFliteOpRegistry.h @@ -63,6 +63,7 @@ private: _tfliteop_map[tflite::BuiltinOperator_RELU] = make_unique(); _tfliteop_map[tflite::BuiltinOperator_RELU6] = make_unique(); _tfliteop_map[tflite::BuiltinOperator_RESHAPE] = make_unique(); + _tfliteop_map[tflite::BuiltinOperator_SUB] = make_unique(); } private: -- 2.7.4