[NNAPI Unittest] Use random kernel/bias for conv_1 (#524)
author박종현/동작제어Lab(SR)/Senior Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 10 Apr 2018 02:43:38 +0000 (11:43 +0900)
committer서상민/동작제어Lab(SR)/Senior Engineer/삼성전자 <sangmin7.seo@samsung.com>
Tue, 10 Apr 2018 02:43:38 +0000 (11:43 +0900)
* [NNAPI Unittest] Use random kernel/bias for conv_1

This commit revises 'nnapi_unittest_conv_1' to use random kernel and
bias values for testing.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
tools/nnapi_unittests/tests/conv_1.cpp

index f045523..1629e01 100644 (file)
@@ -4,11 +4,9 @@
 
 #include "env.h"
 
-#include "util/vector/Object.h"
 #include "util/feature/IndexIterator.h"
 #include "util/feature/Object.h"
 #include "util/feature/Reader.h"
-#include "util/kernel/RandomObject.h"
 #include "util/fp32.h"
 #include "util/environment.h"
 
@@ -72,8 +70,6 @@ int main(int argc, char **argv)
   };
   const nnfw::util::feature::Shape ifm_shape{IFM_C, IFM_H, IFM_W};
   const nnfw::util::feature::Object<float> ifm{ifm_shape, ifm_gen};
-  const nnfw::util::kernel::RandomObject<float> kernel{nnfw::util::kernel::Shape{KER_N, KER_C, KER_H, KER_W}};
-  const nnfw::util::vector::Object<float> bias{KER_N, [] (uint32_t, uint32_t) { return 0.0f; }};
 
   std::cout << "Configurations:" << std::endl;
 #define PRINT_NEWLINE() { std::cout << std::endl; }
@@ -106,41 +102,32 @@ int main(int argc, char **argv)
   const uint32_t kernel_size = KER_N * KER_C * KER_H * KER_W;
   float kernel_data[kernel_size] = { 0.0f, };
 
-  // Fill kernel data in NHWC order
+  // Fill kernel data with random data
   {
-    uint32_t off = 0;
+    std::normal_distribution<float> kernel_dist(-1.0f, +1.0f);
 
-    for (uint32_t nth = 0; nth < KER_N; ++nth)
+    for (uint32_t off = 0; off < kernel_size; ++off)
     {
-      for (uint32_t row = 0; row < KER_H; ++row)
-      {
-        for (uint32_t col = 0; col < KER_W; ++col)
-        {
-          for (uint32_t ch = 0; ch < KER_C; ++ch)
-          {
-            const auto value = kernel.at(nth, ch, row, col);
-            kernel_data[off++] = value;
-          }
-        }
-      }
+      kernel_data[off++] = kernel_dist(random);
     }
-
-    assert(kernel_size == off);
   }
 
   // Configure Bias Data
-  const uint32_t bias_size = bias.size();
+  const auto bias_size = KER_N;
   float bias_data[bias_size] = { 0.0f, };
 
-  // Fill bias data
-  for (uint32_t off = 0; off < bias.size(); ++off)
+  // Fill bias data with random data
   {
-    bias_data[off] = bias.at(off);
+    std::normal_distribution<float> bias_dist(-1.0f, +1.0f);
+
+    for (uint32_t off = 0; off < bias_size; ++off)
+    {
+      bias_data[off] = bias_dist(random);
+    }
   }
 
   // Assumption on this example
   assert(IFM_C == KER_C);
-  assert(KER_N == bias.size());
 
   auto setup = [&](Interpreter &interp)
   {
@@ -185,7 +172,7 @@ int main(int argc, char **argv)
     interp.SetTensorParametersReadOnly(3,
                                        kTfLiteFloat32 /* type */,
                                        "bias" /* name */,
-                                       { bias.size() } /* dims */,
+                                       { bias_size } /* dims */,
                                        quantization,
                                        reinterpret_cast<const char *>(bias_data), bias_size * sizeof(float));