#include "tensorflow/contrib/lite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
+#include "util/environment.h"
+
#include <iostream>
#include <chrono>
#include <algorithm>
using namespace tflite;
using namespace tflite::ops::builtin;
+inline float diff_ratio(float lhs, float rhs)
+{
+ const auto diff = std::fabs(lhs - rhs);
+ const auto max = std::max(std::fabs(lhs), std::fabs(rhs));
+
+ return diff / max;
+}
+
inline void check(const TfLiteStatus &status) { assert(status != kTfLiteError); }
std::unique_ptr<Interpreter> build_interpreter(const FlatBufferModel &model, bool use_nnapi)
int main(const int argc, char **argv)
{
+ int verbose = 0;
+
+ nnfw::util::env::IntAccessor("VERBOSE").access(verbose);
+
const auto filename = argv[1];
StderrReporter error_reporter;
for (const auto &id : pure->outputs())
{
auto diffs = comparator.compare(*(pure->tensor(id)), *(delegated->tensor(id)));
- assert(diffs.size() == 0);
- std::cout << " Tensor #" << id << ": MATCHED" << std::endl;
+
+ if (diffs.size() == 0)
+ {
+ std::cout << " Tensor #" << id << ": MATCHED" << std::endl;
+ }
+ else
+ {
+ std::cout << " Tensor #" << id << ": UMMATCHED" << std::endl;
+
+ if (verbose != 0)
+ {
+ for (const auto &diff : diffs)
+ {
+ std::cout << " Diff at offset " << diff.offset << std::endl;
+ std::cout << " expected: " << diff.expected << std::endl;
+ std::cout << " obtained: " << diff.obtained << std::endl;
+ std::cout << " relative diff: " << diff_ratio(diff.expected, diff.obtained) << std::endl;
+ }
+ }
+
+ return 255;
+ }
}
std::cout << "[NNAPI TEST] PASSED" << std::endl;