From 1ba02d1cb06ec517f69496260261488bc5af1b75 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Senior=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Tue, 10 Apr 2018 11:43:38 +0900 Subject: [PATCH] [NNAPI Unittest] Use random kernel/bias for conv_1 (#524) * [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 --- tools/nnapi_unittests/tests/conv_1.cpp | 39 ++++++++++++---------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/tools/nnapi_unittests/tests/conv_1.cpp b/tools/nnapi_unittests/tests/conv_1.cpp index f045523..1629e01 100644 --- a/tools/nnapi_unittests/tests/conv_1.cpp +++ b/tools/nnapi_unittests/tests/conv_1.cpp @@ -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 ifm{ifm_shape, ifm_gen}; - const nnfw::util::kernel::RandomObject kernel{nnfw::util::kernel::Shape{KER_N, KER_C, KER_H, KER_W}}; - const nnfw::util::vector::Object 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 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 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(bias_data), bias_size * sizeof(float)); -- 2.7.4