From 64821e4c51c9eb804ea6032ebe57116c1ef50072 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=82=A8=EA=B6=81=EC=84=9D/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Engineer/=EC=82=BC=EC=84=B1=EC=A0=84?= =?utf8?q?=EC=9E=90?= Date: Thu, 15 Nov 2018 08:50:53 +0900 Subject: [PATCH] [tflchef] Support ReLU in tflchef (#2283) This commit will enable ReLU in tflchef Signed-off-by: Seok NamKoong --- contrib/tflchef/core/src/Op/ReLU.cpp | 27 ++++++++++++++++++++ contrib/tflchef/core/src/Op/ReLU.h | 46 ++++++++++++++++++++++++++++++++++ contrib/tflchef/core/src/OpChef.def | 1 + contrib/tflchef/core/src/OpChefs.h | 1 + contrib/tflchef/tests/relu/test.recipe | 17 +++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 contrib/tflchef/core/src/Op/ReLU.cpp create mode 100644 contrib/tflchef/core/src/Op/ReLU.h create mode 100644 contrib/tflchef/tests/relu/test.recipe diff --git a/contrib/tflchef/core/src/Op/ReLU.cpp b/contrib/tflchef/core/src/Op/ReLU.cpp new file mode 100644 index 0000000..3fb8d3f --- /dev/null +++ b/contrib/tflchef/core/src/Op/ReLU.cpp @@ -0,0 +1,27 @@ +/* + * 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 "ReLU.h" + +flatbuffers::Offset ReLUChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + return flatbuffers::Offset(); +} + +std::unique_ptr ReLUChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr{new ReLUChef{operation}}; +} diff --git a/contrib/tflchef/core/src/Op/ReLU.h b/contrib/tflchef/core/src/Op/ReLU.h new file mode 100644 index 0000000..778458c --- /dev/null +++ b/contrib/tflchef/core/src/Op/ReLU.h @@ -0,0 +1,46 @@ +/* + * 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 __OP_RELU_H__ +#define __OP_RELU_H__ + +#include "OpChef.h" + +class ReLUChef final : public OpChef +{ +public: + explicit ReLUChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_RELU; } + + tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_NONE; } + + flatbuffers::Offset value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct ReLUChefFactory final : public OpChefFactory +{ + std::unique_ptr create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_RELU_H__ diff --git a/contrib/tflchef/core/src/OpChef.def b/contrib/tflchef/core/src/OpChef.def index d9050a5..1448af6 100644 --- a/contrib/tflchef/core/src/OpChef.def +++ b/contrib/tflchef/core/src/OpChef.def @@ -9,5 +9,6 @@ OP_CHEF(Concatenation, ConcatenationChefFactory) OP_CHEF(Conv2D, Conv2DChefFactory) OP_CHEF(DepthwiseConv2D, DepthwiseConv2DChefFactory) OP_CHEF(MaxPool2D, MaxPool2DChefFactory) +OP_CHEF(ReLU, ReLUChefFactory) OP_CHEF(ReLU6, ReLU6ChefFactory) OP_CHEF(Reshape, ReshapeChefFactory) diff --git a/contrib/tflchef/core/src/OpChefs.h b/contrib/tflchef/core/src/OpChefs.h index bd2060f..9d88ebb 100644 --- a/contrib/tflchef/core/src/OpChefs.h +++ b/contrib/tflchef/core/src/OpChefs.h @@ -22,6 +22,7 @@ #include "Op/Conv2D.h" #include "Op/DepthwiseConv2D.h" #include "Op/MaxPool2D.h" +#include "Op/ReLU.h" #include "Op/ReLU6.h" #include "Op/Reshape.h" diff --git a/contrib/tflchef/tests/relu/test.recipe b/contrib/tflchef/tests/relu/test.recipe new file mode 100644 index 0000000..8eaa360 --- /dev/null +++ b/contrib/tflchef/tests/relu/test.recipe @@ -0,0 +1,17 @@ +operand { + name: "ifm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operand { + name: "ofm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operation { + type: "ReLU" + input: "ifm" + output: "ofm" +} +input: "ifm" +output: "ofm" -- 2.7.4