From 38b6f65f680b55cbbd28858f1d9186c77eba6aca 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/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Fri, 1 Jun 2018 17:28:09 +0900 Subject: [PATCH] [nnapi_test] Support Int32 output compare (#1518) * [nnapi_test] Support Int32 output compare This commit revises nnapi_test to support int32 output compare. Signed-off-by: Jonghyun Park * Fix format errors --- libs/support/tflite/src/Diff.cpp | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/libs/support/tflite/src/Diff.cpp b/libs/support/tflite/src/Diff.cpp index 75616ed..8626427 100644 --- a/libs/support/tflite/src/Diff.cpp +++ b/libs/support/tflite/src/Diff.cpp @@ -154,6 +154,52 @@ bool TfLiteInterpMatchApp::run(::tflite::Interpreter &interp, ::tflite::Interpre std::map comparators; + comparators[kTfLiteInt32] = [this](int id, ::tflite::Interpreter &interp, + ::tflite::Interpreter &nnapi) { + std::vector> diffs; + + const auto expected = nnfw::support::tflite::TensorView::make(interp, id); + const auto obtained = nnfw::support::tflite::TensorView::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::make(interp, id); -- 2.7.4