[onert/test] Random uint8 input value generation for tflite_run (#3982)
authorHyeongseok Oh <hseok82.oh@samsung.com>
Wed, 26 Aug 2020 03:54:22 +0000 (12:54 +0900)
committerGitHub <noreply@github.com>
Wed, 26 Aug 2020 03:54:22 +0000 (12:54 +0900)
tflite_run set random value for uint8 input tensor

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
tests/tools/tflite_run/src/tflite_run.cc

index 00b8b0e..e72966d 100644 (file)
@@ -220,13 +220,16 @@ int main(const int argc, char **argv)
         // Generate unsigned 8-bit integer input
         auto tensor_view = nnfw::tflite::TensorView<uint8_t>::make(*interpreter, o);
 
-        uint8_t value = 0;
+        auto fp = static_cast<uint8_t (nnfw::misc::RandomGenerator::*)(
+            const ::nnfw::misc::tensor::Shape &, const ::nnfw::misc::tensor::Index &)>(
+            &nnfw::misc::RandomGenerator::generate<uint8_t>);
+        const nnfw::misc::tensor::Object<uint8_t> data(tensor_view.shape(),
+                                                       std::bind(fp, randgen, _1, _2));
 
         nnfw::misc::tensor::iterate(tensor_view.shape())
             << [&](const nnfw::misc::tensor::Index &ind) {
-                 // TODO Generate random values
+                 const auto value = data.at(ind);
                  tensor_view.at(ind) = value;
-                 value = (value + 1) & 0xFF;
                };
       }
       else if (tensor->type == kTfLiteBool)