[tflchef] Support ReLU in tflchef (#2283)
author남궁석/동작제어Lab(SR)/Engineer/삼성전자 <sk.namkoong@samsung.com>
Wed, 14 Nov 2018 23:50:53 +0000 (08:50 +0900)
committer박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 14 Nov 2018 23:50:53 +0000 (08:50 +0900)
This commit will enable ReLU in tflchef

Signed-off-by: Seok NamKoong <sk.namkoong@samsung.com>
contrib/tflchef/core/src/Op/ReLU.cpp [new file with mode: 0644]
contrib/tflchef/core/src/Op/ReLU.h [new file with mode: 0644]
contrib/tflchef/core/src/OpChef.def
contrib/tflchef/core/src/OpChefs.h
contrib/tflchef/tests/relu/test.recipe [new file with mode: 0644]

diff --git a/contrib/tflchef/core/src/Op/ReLU.cpp b/contrib/tflchef/core/src/Op/ReLU.cpp
new file mode 100644 (file)
index 0000000..3fb8d3f
--- /dev/null
@@ -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<void> ReLUChef::value(flatbuffers::FlatBufferBuilder &fbb) const
+{
+  return flatbuffers::Offset<void>();
+}
+
+std::unique_ptr<OpChef> ReLUChefFactory::create(const tflchef::Operation *operation) const
+{
+  return std::unique_ptr<OpChef>{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 (file)
index 0000000..778458c
--- /dev/null
@@ -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<void> value(flatbuffers::FlatBufferBuilder &fbb) const override;
+
+private:
+  const tflchef::Operation *_operation;
+};
+
+struct ReLUChefFactory final : public OpChefFactory
+{
+  std::unique_ptr<OpChef> create(const tflchef::Operation *operation) const override;
+};
+
+#endif // __OP_RELU_H__
index d9050a5..1448af6 100644 (file)
@@ -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)
index bd2060f..9d88ebb 100644 (file)
@@ -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 (file)
index 0000000..8eaa360
--- /dev/null
@@ -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"