[enco/tfl/frontend] ReLU6 Activation Layer (#2359)
author윤현식/동작제어Lab(SR)/Principal Engineer/삼성전자 <hyunsik.yoon@samsung.com>
Fri, 23 Nov 2018 01:04:38 +0000 (10:04 +0900)
committer박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Fri, 23 Nov 2018 01:04:38 +0000 (10:04 +0900)
* [enco/tfl/frontend] ReLU6 Activation Layer

This commit is for ReLU6 Activation Layer.

Signed-off-by: Hyun Sik Yoon <hyunsik.yoon@samsung.com>
* Pr fix: add code to op/Activation.cpp

contrib/enco/frontend/tflite/src/Op/Activation.cpp
contrib/enco/test/tflite/Conv2D_003/INFERENCE [new file with mode: 0644]
contrib/enco/test/tflite/Conv2D_003/test.recipe [new file with mode: 0644]

index ac5b053..96fe280 100644 (file)
@@ -58,7 +58,7 @@ coco::FeatureObject *build_activation(tflite::ActivationFunctionType act, coco::
   }
   case tflite::ActivationFunctionType::ActivationFunctionType_RELU:
   {
-    // Create Eval(output_obj, Relu(load(ifm)))
+    // Create Eval(output_obj, ReLU(load(ifm)))
     auto load_op = op_builder(m).load(ifm).pop();
     auto relu_op = m->entity()->op()->create<coco::ReLU>();
     relu_op->arg(load_op);
@@ -69,8 +69,21 @@ coco::FeatureObject *build_activation(tflite::ActivationFunctionType act, coco::
     block->instr()->append(eval_ins);
     break;
   }
+  case tflite::ActivationFunctionType::ActivationFunctionType_RELU6:
+  {
+    // Create Eval(output_obj, ReLU6(load(ifm)))
+    auto load_op = op_builder(m).load(ifm).pop();
+    auto relu6_op = m->entity()->op()->create<coco::ReLU6>();
+    relu6_op->arg(load_op);
+
+    auto eval_ins = instr_builder(m).eval(output_obj, relu6_op);
+
+    // Append the instruction to the block
+    block->instr()->append(eval_ins);
+    break;
+  }
   default:
-    // TODO support RELU6, TanH, etc
+    // TODO support other fused activations
     assert(false);
     break;
   }
diff --git a/contrib/enco/test/tflite/Conv2D_003/INFERENCE b/contrib/enco/test/tflite/Conv2D_003/INFERENCE
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/contrib/enco/test/tflite/Conv2D_003/test.recipe b/contrib/enco/test/tflite/Conv2D_003/test.recipe
new file mode 100644 (file)
index 0000000..30c9473
--- /dev/null
@@ -0,0 +1,45 @@
+operand {
+  name: "ifm"
+  type: FLOAT32
+  shape { dim: 1 dim: 3 dim: 3 dim: 2 }
+}
+operand {
+  name: "ker"
+  type: FLOAT32
+  shape { dim: 1 dim: 1 dim: 1 dim: 2 }
+  filler {
+    tag: "gaussian"
+    arg: "0.0"
+    arg: "1.0"
+  }
+}
+operand {
+  name: "bias"
+  type: FLOAT32
+  shape { dim: 1 }
+  filler {
+    tag: "gaussian"
+    arg: "0.0"
+    arg: "1.0"
+  }
+}
+operand {
+  name: "ofm"
+  type: FLOAT32
+  shape { dim: 1 dim: 3 dim: 3 dim: 1 }
+}
+operation {
+  type: "Conv2D"
+  conv2d_options {
+    padding: VALID
+    stride_w: 1
+    stride_h: 1
+    activation: RELU6
+  }
+  input: "ifm"
+  input: "ker"
+  input: "bias"
+  output: "ofm"
+}
+input: "ifm"
+output: "ofm"