[tflchef] Add Sub for reverse (#2697)
author윤지영/On-Device Lab./Engineer/삼성전자 <jy910.yun@samsung.com>
Mon, 17 Dec 2018 23:58:32 +0000 (08:58 +0900)
committer박종현/On-Device Lab./Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 17 Dec 2018 23:58:32 +0000 (08:58 +0900)
This will add Sub Op for tflchef-reverse

Signed-off-by: Jiyoung Yun <jy910.yun@samsung.com>
contrib/tflchef/tests/sub/test.reverse [new file with mode: 0644]
contrib/tflchef/tflite/src/Op/Sub.cpp [new file with mode: 0644]
contrib/tflchef/tflite/src/Op/Sub.h [new file with mode: 0644]
contrib/tflchef/tflite/src/TFliteOpChefs.h
contrib/tflchef/tflite/src/TFliteOpRegistry.h

diff --git a/contrib/tflchef/tests/sub/test.reverse b/contrib/tflchef/tests/sub/test.reverse
new file mode 100644 (file)
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 (file)
index 0000000..db77fdd
--- /dev/null
@@ -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 (file)
index 0000000..2168e5e
--- /dev/null
@@ -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__
index 2d3c747..c12d1ad 100644 (file)
@@ -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__
index 7383603..db21b60 100644 (file)
@@ -63,6 +63,7 @@ private:
     _tfliteop_map[tflite::BuiltinOperator_RELU] = make_unique<TFliteOpReLU>();
     _tfliteop_map[tflite::BuiltinOperator_RELU6] = make_unique<TFliteOpReLU6>();
     _tfliteop_map[tflite::BuiltinOperator_RESHAPE] = make_unique<TFliteOpReshape>();
+    _tfliteop_map[tflite::BuiltinOperator_SUB] = make_unique<TFliteOpSub>();
   }
 
 private: