[nnapi_test] Support Int32 output compare (#1518)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Fri, 1 Jun 2018 08:28:09 +0000 (17:28 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Fri, 1 Jun 2018 08:28:09 +0000 (17:28 +0900)
* [nnapi_test] Support Int32 output compare

This commit revises nnapi_test to support int32 output compare.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
* Fix format errors

libs/support/tflite/src/Diff.cpp

index 75616ed..8626427 100644 (file)
@@ -154,6 +154,52 @@ bool TfLiteInterpMatchApp::run(::tflite::Interpreter &interp, ::tflite::Interpre
 
   std::map<TfLiteType, Comparator> comparators;
 
+  comparators[kTfLiteInt32] = [this](int id, ::tflite::Interpreter &interp,
+                                     ::tflite::Interpreter &nnapi) {
+    std::vector<nnfw::util::tensor::Diff<int32_t>> diffs;
+
+    const auto expected = nnfw::support::tflite::TensorView<int32_t>::make(interp, id);
+    const auto obtained = nnfw::support::tflite::TensorView<int32_t>::make(nnapi, id);
+
+    assert(expected.shape() == obtained.shape());
+
+    using nnfw::util::tensor::zip;
+    using nnfw::util::tensor::Index;
+
+    zip(expected.shape(), expected, obtained)
+        << [&](const Index &index, int32_t expected_value, int32_t obtained_value) {
+             if (expected_value != obtained_value)
+             {
+               diffs.emplace_back(index, expected_value, obtained_value);
+             }
+           };
+
+    // TODO Unify summary generation code
+    if (diffs.size() == 0)
+    {
+      std::cout << "  Tensor #" << id << ": MATCHED" << std::endl;
+    }
+    else
+    {
+      std::cout << "  Tensor #" << id << ": UNMATCHED" << std::endl;
+      std::cout << "    " << diffs.size() << " diffs are detected" << std::endl;
+    }
+
+    if (diffs.size() > 0 && _verbose != 0)
+    {
+      std::cout << "    ---- Details ---" << std::endl;
+      for (const auto &diff : diffs)
+      {
+        std::cout << "    Diff at [" << nnfw::util::tensor::IndexFormatter(diff.index) << "]"
+                  << std::endl;
+        std::cout << "      expected: " << diff.expected << std::endl;
+        std::cout << "      obtained: " << diff.obtained << std::endl;
+      }
+    }
+
+    return diffs.size() == 0;
+  };
+
   comparators[kTfLiteFloat32] = [this](int id, ::tflite::Interpreter &interp,
                                        ::tflite::Interpreter &nnapi) {
     const auto expected = nnfw::support::tflite::TensorView<float>::make(interp, id);