Fix wrong inclusion and scale value in nnapi_unittests. (#1926)
author장지섭/동작제어Lab(SR)/Engineer/삼성전자 <jiseob.jang@samsung.com>
Tue, 10 Jul 2018 07:10:52 +0000 (16:10 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Tue, 10 Jul 2018 07:10:52 +0000 (16:10 +0900)
This commit fixes wrong inclusion and scale value in nnapi_unittests.
List of fixed scale value
  - add
  - conv
  - dconv
  - mul

Signed-off-by: jiseob.jang <jiseob.jang@samsung.com>
13 files changed:
tools/nnapi_unittests/tests/add_quan_1.cpp
tools/nnapi_unittests/tests/avg_pool_quan_1.cpp
tools/nnapi_unittests/tests/cast_q_to_f_1.cpp
tools/nnapi_unittests/tests/concat_quan_1.cpp
tools/nnapi_unittests/tests/conv_quan_1.cpp
tools/nnapi_unittests/tests/dconv_quan_1.cpp
tools/nnapi_unittests/tests/fully_connected_quan_1.cpp
tools/nnapi_unittests/tests/max_pool_quan_1.cpp
tools/nnapi_unittests/tests/mul_quan_1.cpp
tools/nnapi_unittests/tests/relu6_quan_1.cpp
tools/nnapi_unittests/tests/relu_quan_1.cpp
tools/nnapi_unittests/tests/reshape_quan_1.cpp
tools/nnapi_unittests/tests/softmax_quan_1.cpp

index b8ce476..ceda77c 100644 (file)
@@ -51,7 +51,7 @@ TEST(NNAPI_Unittest_add_1, simple_test)
   nnfw::util::env::IntAccessor("SEED").access(SEED);
 
 #define INT_VALUE(NAME, VALUE) IntVar NAME##_Value(#NAME, VALUE);
-#include "add_1.lst"
+#include "add_quan_1.lst"
 #undef INT_VALUE
 
   const int32_t LEFT_N = LEFT_N_Value();
@@ -112,17 +112,18 @@ TEST(NNAPI_Unittest_add_1, simple_test)
     //
     // Q: Is this necessary?
     TfLiteQuantizationParams quantization;
-    quantization.scale = 1.0f;
     quantization.zero_point = 0;
 
     // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N)
     interp.AddTensors(3);
 
     // Configure output
+    quantization.scale = 2.0f;
     interp.SetTensorParametersReadWrite(0, kTfLiteUInt8 /* type */, "output" /* name */,
                                         {OFM_N, OFM_H, OFM_W, OFM_C} /* dims */, quantization);
 
     // Configure input(s)
+    quantization.scale = 1.0f;
     interp.SetTensorParametersReadWrite(1, kTfLiteUInt8 /* type */, "left" /* name */,
                                         {LEFT_N, LEFT_H, LEFT_W, LEFT_C} /* dims */, quantization);
 
index 08b2009..79749f8 100644 (file)
@@ -49,7 +49,7 @@ TEST(NNAPI_Unittest_avg_pool_1, simple_test)
   nnfw::util::env::IntAccessor("TOLERANCE").access(tolerance);
 
 #define INT_VALUE(NAME, VALUE) IntVar NAME##_Value(#NAME, VALUE);
-#include "avg_pool_1.lst"
+#include "avg_pool_quan_1.lst"
 #undef INT_VALUE
 
   const int32_t IFM_C = IFM_C_Value();
@@ -102,9 +102,6 @@ TEST(NNAPI_Unittest_avg_pool_1, simple_test)
     quantization.scale = 1.0f;
     quantization.zero_point = 0;
 
-    quantization.scale = 1;
-    quantization.zero_point = 0;
-
     // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N)
     interp.AddTensors(2);
 
index 23218e2..87fd79e 100644 (file)
@@ -50,7 +50,7 @@ TEST(NNAPI_Unittest_cast_1, simple_test)
   nnfw::util::env::IntAccessor("SEED").access(SEED);
 
 #define INT_VALUE(NAME, VALUE) IntVar NAME##_Value(#NAME, VALUE);
-#include "cast_1.lst"
+#include "cast_q_to_f_1.lst"
 #undef INT_VALUE
 
   const int32_t IFM_N = IFM_N_Value();
index 2dcbe1d..28b8e54 100644 (file)
@@ -51,7 +51,7 @@ TEST(NNAPI_Unittest_concat_1, simple_test)
   nnfw::util::env::IntAccessor("SEED").access(SEED);
 
 #define INT_VALUE(NAME, VALUE) IntVar NAME##_Value(#NAME, VALUE);
-#include "concat_1.lst"
+#include "concat_quan_1.lst"
 #undef INT_VALUE
 
   // TODO Allow users to set concat axis!
index dd8d01e..e0fd7d2 100644 (file)
@@ -51,7 +51,7 @@ TEST(NNAPI_Unittest_conv_1, simple_test)
   nnfw::util::env::IntAccessor("SEED").access(SEED);
 
 #define INT_VALUE(NAME, VALUE) IntVar NAME##_Value(#NAME, VALUE);
-#include "conv_1.lst"
+#include "conv_quan_1.lst"
 #undef INT_VALUE
 
   const int32_t STRIDE_H = STRIDE_H_Value();
@@ -154,12 +154,14 @@ TEST(NNAPI_Unittest_conv_1, simple_test)
     interp.AddTensors(5);
 
     // Configure OFM
-    quantization.scale = 1.0f;
+    float max_scale = (KER_N, KER_C * KER_H * KER_W) *
+                      std::numeric_limits<uint8_t>::max(); // * IFM_scale(1.0f) * kernel_scale(1.0f)
+    quantization.scale = max_scale;
     interp.SetTensorParametersReadWrite(0, kTfLiteUInt8 /* type */, "output" /* name */,
                                         {1 /*N*/, OFM_H, OFM_W, OFM_C} /* dims */, quantization);
 
     // Configure IFM
-    quantization.scale = 0.02f;
+    quantization.scale = 1.0f;
     interp.SetTensorParametersReadWrite(1, kTfLiteUInt8 /* type */, "input" /* name */,
                                         {1 /*N*/, IFM_H, IFM_W, IFM_C} /* dims */, quantization);
 
index 5a22591..63850b5 100644 (file)
@@ -51,7 +51,7 @@ TEST(NNAPI_Unittest_dconv_1, simple_test)
   nnfw::util::env::IntAccessor("SEED").access(SEED);
 
 #define INT_VALUE(NAME, VALUE) IntVar NAME##_Value(#NAME, VALUE);
-#include "dconv_1.lst"
+#include "dconv_quan_1.lst"
 #undef INT_VALUE
 
   const int32_t STRIDE_H = STRIDE_H_Value();
@@ -151,12 +151,14 @@ TEST(NNAPI_Unittest_dconv_1, simple_test)
     interp.AddTensors(4);
 
     // Configure OFM
-    quantization.scale = 1.0f;
+    float max_scale = (1 * KER_C * KER_H * KER_W) *
+                      std::numeric_limits<uint8_t>::max(); // * IFM_scale(1.0f) * kernel_scale(1.0f)
+    quantization.scale = max_scale;
     interp.SetTensorParametersReadWrite(0, kTfLiteUInt8 /* type */, "output" /* name */,
                                         {1 /*N*/, OFM_H, OFM_W, OFM_C} /* dims */, quantization);
 
     // Configure IFM
-    quantization.scale = 0.02f;
+    quantization.scale = 1.0f;
     interp.SetTensorParametersReadWrite(1, kTfLiteUInt8 /* type */, "input" /* name */,
                                         {1 /*N*/, IFM_H, IFM_W, IFM_C} /* dims */, quantization);
 
index 33c592c..60e14ba 100644 (file)
@@ -52,14 +52,14 @@ TEST(NNAPI_Unittest_fully_connected_1, simple_test)
   nnfw::util::env::IntAccessor("SEED").access(SEED);
 
 #define INT_VALUE(NAME, VALUE) IntVar NAME##_Value(#NAME, VALUE);
-#include "conv_1.lst"
+#include "fully_connected_quan_1.lst"
 #undef INT_VALUE
 
   const int32_t IFM_C = IFM_C_Value();
   const int32_t IFM_H = IFM_H_Value();
   const int32_t IFM_W = IFM_W_Value();
 
-  const int32_t KER_H = KER_N_Value();
+  const int32_t KER_H = KER_H_Value();
   const int32_t KER_W = IFM_C_Value() * IFM_H_Value() * IFM_W_Value();
 
   const int32_t OUT_LEN = KER_H;
index 0ccd48d..4c33179 100644 (file)
@@ -49,7 +49,7 @@ TEST(NNAPI_Unittest_max_pool_1, simple_test)
   nnfw::util::env::IntAccessor("TOLERANCE").access(tolerance);
 
 #define INT_VALUE(NAME, VALUE) IntVar NAME##_Value(#NAME, VALUE);
-#include "max_pool_1.lst"
+#include "max_pool_quan_1.lst"
 #undef INT_VALUE
 
   const TfLitePadding PADDING_TYPE = static_cast<TfLitePadding>(PADDING_TYPE_Value());
index b36f8f1..0b56b29 100644 (file)
@@ -101,17 +101,20 @@ TEST(NNAPI_Unittest_mul_1, simple_test)
     //
     // Q: Is this necessary?
     TfLiteQuantizationParams quantization;
-    quantization.scale = FLOAT_NEAREST_TO_1;
     quantization.zero_point = 0;
 
     // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N)
     interp.AddTensors(3);
 
     // Configure output
+    float max_scale =
+        std::numeric_limits<uint8_t>::max(); // * input1_scale(1.0f) * input2_scale(1.0f)
+    quantization.scale = max_scale;
     interp.SetTensorParametersReadWrite(0, kTfLiteUInt8 /* type */, "output" /* name */,
                                         {OFM_1D, OFM_2D, OFM_3D} /* dims */, quantization);
 
     // Configure input(s)
+    quantization.scale = 1.0f;
     interp.SetTensorParametersReadWrite(1, kTfLiteUInt8 /* type */, "left" /* name */,
                                         {LEFT_1D, LEFT_2D, LEFT_3D} /* dims */, quantization);
 
index d3f0d34..111c5a4 100644 (file)
@@ -44,7 +44,7 @@ int main(int argc, char **argv)
   nnfw::util::env::IntAccessor("TOLERANCE").access(tolerance);
 
 #define INT_VALUE(NAME, VALUE) IntVar NAME##_Value(#NAME, VALUE);
-#include "relu6_1.lst"
+#include "relu6_quan_1.lst"
 #undef INT_VALUE
 
   const int32_t IFM_H = IFM_H_Value();
index d5696d4..7bca8ec 100644 (file)
@@ -44,7 +44,7 @@ int main(int argc, char **argv)
   nnfw::util::env::IntAccessor("TOLERANCE").access(tolerance);
 
 #define INT_VALUE(NAME, VALUE) IntVar NAME##_Value(#NAME, VALUE);
-#include "relu_1.lst"
+#include "relu_quan_1.lst"
 #undef INT_VALUE
 
   const int32_t IFM_H = IFM_H_Value();
index 98f752b..84faa5b 100644 (file)
@@ -49,7 +49,7 @@ TEST(NNAPI_Unittest_reshape_1, simple_test)
   nnfw::util::env::IntAccessor("TOLERANCE").access(tolerance);
 
 #define INT_VALUE(NAME, VALUE) IntVar NAME##_Value(#NAME, VALUE);
-#include "max_pool_1.lst"
+#include "reshape_quan_1.lst"
 #undef INT_VALUE
 
   const int32_t IFM_C = IFM_C_Value();
index b50ba0e..4cae025 100644 (file)
@@ -46,7 +46,7 @@ TEST(NNAPI_Unittest_softmax_1, simple_test)
   nnfw::util::env::IntAccessor("TOLERANCE").access(tolerance);
 
 #define INT_VALUE(NAME, VALUE) IntVar NAME##_Value(#NAME, VALUE);
-#include "softmax_1.lst"
+#include "softmax_quan_1.lst"
 #undef INT_VALUE
 
   const int32_t IFM_C = 1;