Add ActivationLayer to kernel test lab (#409)
author박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 4 Apr 2018 04:01:02 +0000 (13:01 +0900)
committer김정현/동작제어Lab(SR)/Senior Engineer/삼성전자 <jh0822.kim@samsung.com>
Wed, 4 Apr 2018 04:01:02 +0000 (13:01 +0900)
This will add ActivationLayer with Relu to convolution kernel test lab

Signed-off-by: SaeHie Park <saehie.park@samsung.com>
labs/kerneltesting/conv2d/nnfw_conv2d_test.cpp

index f389f84..4463d61 100644 (file)
@@ -132,8 +132,21 @@ bool convFloat32(const float* inputData, const Shape& inputShape,
               std::unique_ptr<WeightAccessor>(new WeightAccessor(filterData, filterShape)),
               std::unique_ptr<BiasAccessor>(new BiasAccessor(biasData, biasShape)),
               arm_compute::PadStrideInfo(stride_width, stride_height, padding_top, padding_bottom))
-        << Tensor(
-              std::unique_ptr<OutputAccessor>(new OutputAccessor(outputData, outputShape)));
+        ;
+  if (activation != static_cast<int32_t>(FusedActivationFunc::NONE)) {
+    arm_compute::ActivationLayerInfo::ActivationFunction actFunc =
+        arm_compute::ActivationLayerInfo::ActivationFunction::RELU;
+
+    graph << arm_compute::graph::ActivationLayer(arm_compute::ActivationLayerInfo(actFunc));
+    // Activation does not provide output Tensor and makes next layer fail to add to graph
+    // when it's the last(output) layer. To solve this, need to add a dummy layer.
+    uint32_t tso_c = getSizeOfDimension(outputShape, 0);
+    uint32_t tso_h = getSizeOfDimension(outputShape, 1);
+    uint32_t tso_w = getSizeOfDimension(outputShape, 2);
+    uint32_t tso_n = getSizeOfDimension(outputShape, 3);
+    graph << arm_compute::graph::ReshapeLayer(TensorShape(tso_w, tso_h, tso_c, tso_n));
+  }
+  graph << Tensor(std::unique_ptr<OutputAccessor>(new OutputAccessor(outputData, outputShape)))
         ;
 
   graph.run();
@@ -207,7 +220,7 @@ int test_3x3_1x1_one(void)
   int32_t padding_bottom = 0;
   int32_t stride_width = 1;
   int32_t stride_height = 1;
-  int32_t activation = 0;
+  int32_t activation = static_cast<int32_t>(FusedActivationFunc::RELU);
   float* outputData = new float[9];
   const Shape outputShape = { OperandType::FLOAT32, {1,1,1,1}, 1.0, 0 };
   float* expectData = new float[9];
@@ -271,7 +284,7 @@ int test_3x3_3x3_one(void)
   int32_t padding_bottom = 1;
   int32_t stride_width = 1;
   int32_t stride_height = 1;
-  int32_t activation = 0;
+  int32_t activation = static_cast<int32_t>(FusedActivationFunc::RELU);
   float* outputData = new float[9];
   const Shape outputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 };
   float* expectData = new float[9];
@@ -335,7 +348,7 @@ int test_3x3_3x3_seq(void)
   int32_t padding_bottom = 1;
   int32_t stride_width = 1;
   int32_t stride_height = 1;
-  int32_t activation = 0;
+  int32_t activation = static_cast<int32_t>(FusedActivationFunc::RELU);
   float* outputData = new float[9];
   const Shape outputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 };
   float* expectData = new float[9];