MNN/tools/cpp/checkInvalidValue.cpp

90 lines
2.1 KiB
C++
Raw Normal View History

- build: - unify schema building in core and converter; - add more build script for android; - add linux build script for python; - ops impl: - add floor mod support in binary; - use eltwise impl in add/max/sub/mul binary for optimization; - remove fake double support in cast; - fix 5d support for concat; - add adjX and adjY support for batch matmul; - optimize conv2d back prop filter; - add pad mode support for conv3d; - fix bug in conv2d & conv depthwise with very small feature map; - optimize binary without broacast; - add data types support for gather; - add gather ND support; - use uint8 data type in gather v2; - add transpose support for matmul; - add matrix band part; - add dim != 4 support for padding, reshape & tensor convert; - add pad type support for pool3d; - make ops based on TensorFlow Lite quantization optional; - add all & any support for reduction; - use type in parameter as output type in reduction; - add int support for unary; - add variable weight support for conv2d; - fix conv2d depthwise weights initialization; - fix type support for transpose; - fix grad outputs count for reduce grad and reshape grad; - fix priorbox & detection output; - fix metal softmax error; - python: - add runSessionWithCallBackInfo interface; - add max nodes limit (1400) for visualization tool; - fix save error in python3; - align default dim; - convert: - add extra design for optimization; - add more post converting optimizers; - add caffe v1 weights blob support; - add cast, unary, conv transpose support for onnx model; - optimize batchnorm, conv with variable weights, prelu, reshape, slice, upsample for onnx model; - add cos/sin/atan/tan support for unary for tensorflow model; - add any/all support for reduction for tensorflow model; - add elu, conv3d, pool3d support for tensorflow model; - optimize argmax, batchnorm, concat, batch to space, conv with variable weights, prelu, slice for tensorflow model; - others: - fix size computer lock; - fix thread pool deadlock; - add express & parameters in express; - rewrite blitter chooser without static map; - add tests for expr;
2019-10-29 13:37:26 +08:00
//
// checkInvalidValue.cpp
// MNN
//
// Created by MNN on 2019/10/28.
// Copyright © 2018, Alibaba Group Htargeting Limited
//
#include <assert.h>
#include <dirent.h>
#include <stdio.h>
#include <sys/stat.h>
#include <cmath>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
#define NONE "\e[0m"
#define RED "\e[0;31m"
#define GREEN "\e[0;32m"
#define L_GREEN "\e[1;32m"
#define BLUE "\e[0;34m"
#define L_BLUE "\e[1;34m"
#define Btarget "\e[1m"
int main(int argc, char* argv[]) {
if (argc < 2) {
printf("Usage: ./checkInvalidValue.out outputDir [limit]\n");
return 0;
}
// read args
printf("Compare:\n");
printf("%s\n", argv[1]);
float tolerance = 0.001;
int limit = 10;
if (argc > 2) {
limit = atoi(argv[2]);
}
printf("limit=%d\n", limit);
// open dir
DIR* root = opendir(argv[1]);
if (NULL == root) {
printf("Error to open %s\n", argv[1]);
return 0;
}
std::vector<std::string> compareFiles;
struct dirent* ent;
while ((ent = readdir(root)) != NULL) {
compareFiles.push_back(ent->d_name);
}
closedir(root);
auto limitValue = powf(10, limit);
// compare files
for (auto s : compareFiles) {
if (s.size() <= 2) {
continue;
}
std::string empty = "";
std::string targetFile = empty + argv[1] + "/" + s;
std::ifstream targetOs(targetFile.c_str());
if (targetOs.fail()) {
// printf("Can's open %s\n", targetFile.c_str());
continue;
}
int pos = 0;
bool correct = true;
float v1;
while (targetOs >> v1) {
auto absValue = fabsf(v1);
if (!isnan(v1) && absValue < limitValue) {
pos++;
continue;
}
printf(RED "Error for %s, %d, v1=%.6f\n" NONE, s.c_str(), pos, v1);
correct = false;
break;
}
if (correct) {
printf(GREEN "Correct : %s\n" NONE, s.c_str());
}
}
return 0;
}