nnfw::util::tensor::Index index;
float expected;
float obtained;
+ float relative_diff;
TfLiteTensorDiff(const nnfw::util::tensor::Index &i) : index(i)
{
public:
std::vector<TfLiteTensorDiff> compare(const nnfw::support::tflite::TensorView<float> &expected,
- const nnfw::support::tflite::TensorView<float> &obtained) const;
+ const nnfw::support::tflite::TensorView<float> &obtained,
+ TfLiteTensorDiff *max_diff = nullptr) const;
private:
std::function<bool (float lhs, float rhs)> _compare_fn;
std::vector<TfLiteTensorDiff>
TfLiteTensorComparator::compare(const nnfw::support::tflite::TensorView<float> &expected,
- const nnfw::support::tflite::TensorView<float> &obtained) const
+ const nnfw::support::tflite::TensorView<float> &obtained,
+ TfLiteTensorDiff *max_diff) const
{
std::vector<TfLiteTensorDiff> res;
{
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))
{
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;
{
const auto expected = nnfw::support::tflite::TensorView<float>::make(*pure, id);
const auto obtained = nnfw::support::tflite::TensorView<float>::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)
{
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)
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;
}
}