[tflite_run] Generate random input (#1477)
author이한종/동작제어Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Thu, 31 May 2018 11:49:14 +0000 (20:49 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Thu, 31 May 2018 11:49:14 +0000 (20:49 +0900)
When running `tflite_run` without input argument it runs with values
with 0. This commit will fill the input tensors with random values
instead, same way with `nnapi_test` does.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
include/support/tflite/Diff.h
tools/tflite_run/src/tflite_run.cc

index f17c549..c80c03e 100644 (file)
@@ -68,6 +68,11 @@ public:
 
   T operator()(const ::nnfw::util::tensor::Shape &, const ::nnfw::util::tensor::Index &)
   {
+    return (*this)();
+  }
+
+  T operator()(void)
+  {
     return _dist(_rand);
   }
 
index ede6eb4..75c3bb0 100644 (file)
@@ -127,6 +127,22 @@ int main(const int argc, char **argv)
              reinterpret_cast<const void *>(tensor_view._base), tensor->bytes);
     }
   }
+  else
+  {
+    // No input specified. So we fill the input tensors with random values.
+    for (const auto &o : interpreter->inputs())
+    {
+      TfLiteTensor *tensor = interpreter->tensor(o);
+
+      const int seed = 1; /* TODO Add an option for seed value */
+      RandomGenerator<float> randgen{seed, 0.0f, 0.2f};
+      const float *end = reinterpret_cast<const float *>(tensor->data.raw_const + tensor->bytes);
+      for (float *ptr = tensor->data.f; ptr < end; ptr++)
+      {
+        *ptr = randgen();
+      }
+    }
+  }
 
   TFLiteRun::TensorDumper tensor_dumper;
   // Must be called before `interpreter->Invoke()`