From: 최형규/동작제어Lab(SR)/Senior Engineer/삼성전자 Date: Fri, 6 Apr 2018 02:22:00 +0000 (+0900) Subject: Print out max relative difference (#473) X-Git-Tag: 0.1~402 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eab9b9f79e5c58553a76393e3bbdd7ec117bcdb5;p=platform%2Fcore%2Fml%2Fnnfw.git Print out max relative difference (#473) * Print out max non-zero observed relative difference - Print out max non-zero observed relative difference for both MATCHED and UNMATCHED Signed-off-by: Hyung-Kyu Choi * Apply review feedbacks - Apply review feedbacks Signed-off-by: Hyung-Kyu Choi --- diff --git a/tools/nnapi_test/src/nnapi_test.cc b/tools/nnapi_test/src/nnapi_test.cc index a46629c..15fda3c 100644 --- a/tools/nnapi_test/src/nnapi_test.cc +++ b/tools/nnapi_test/src/nnapi_test.cc @@ -98,6 +98,7 @@ struct TfLiteTensorDiff nnfw::util::tensor::Index index; float expected; float obtained; + float relative_diff; TfLiteTensorDiff(const nnfw::util::tensor::Index &i) : index(i) { @@ -115,7 +116,8 @@ public: public: std::vector compare(const nnfw::support::tflite::TensorView &expected, - const nnfw::support::tflite::TensorView &obtained) const; + const nnfw::support::tflite::TensorView &obtained, + TfLiteTensorDiff *max_diff = nullptr) const; private: std::function _compare_fn; @@ -123,7 +125,8 @@ private: std::vector TfLiteTensorComparator::compare(const nnfw::support::tflite::TensorView &expected, - const nnfw::support::tflite::TensorView &obtained) const + const nnfw::support::tflite::TensorView &obtained, + TfLiteTensorDiff *max_diff) const { std::vector res; @@ -133,6 +136,7 @@ TfLiteTensorComparator::compare(const nnfw::support::tflite::TensorView & { const auto expected_value = expected.at(index); const auto obtained_value = obtained.at(index); + const auto relative_diff = nnfw::util::fp32::relative_diff(expected_value, obtained_value); if (!_compare_fn(expected_value, obtained_value)) { @@ -140,9 +144,22 @@ TfLiteTensorComparator::compare(const nnfw::support::tflite::TensorView & diff.expected = expected_value; diff.obtained = obtained_value; + diff.relative_diff = relative_diff; res.emplace_back(diff); } + + // Update max_diff_index, if necessary + if (max_diff != nullptr) + { + if (max_diff->relative_diff < relative_diff) + { + max_diff->index = index; + max_diff->expected = expected_value; + max_diff->obtained = obtained_value; + max_diff->relative_diff = relative_diff; + } + } }; return res; @@ -187,8 +204,10 @@ int main(const int argc, char **argv) { const auto expected = nnfw::support::tflite::TensorView::make(*pure, id); const auto obtained = nnfw::support::tflite::TensorView::make(*delegated, id); + TfLiteTensorDiff max_diff(0); + max_diff.relative_diff = 0; - auto diffs = comparator.compare(expected, obtained); + auto diffs = comparator.compare(expected, obtained, &max_diff); if (diffs.size() == 0) { @@ -197,7 +216,19 @@ int main(const int argc, char **argv) else { std::cout << " Tensor #" << id << ": UMMATCHED" << std::endl; + } + // Print out max_diff + if (max_diff.relative_diff > 0) + { + std::cout << " Max Diff at [" << TensorIndexFormatter(max_diff.index) << "]" << std::endl; + std::cout << " expected: " << max_diff.expected << std::endl; + std::cout << " obtained: " << max_diff.obtained << std::endl; + std::cout << " relative diff: " << max_diff.relative_diff << std::endl; + } + + if (diffs.size() > 0) + { if (verbose != 0) { for (const auto &diff : diffs) @@ -205,7 +236,7 @@ int main(const int argc, char **argv) std::cout << " Diff at [" << TensorIndexFormatter(diff.index) << "]" << std::endl; std::cout << " expected: " << diff.expected << std::endl; std::cout << " obtained: " << diff.obtained << std::endl; - std::cout << " relative diff: " << nnfw::util::fp32::relative_diff(diff.expected, diff.obtained) << std::endl; + std::cout << " relative diff: " << diff.relative_diff << std::endl; } }