Blame view

3rdparty/opencv-4.5.4/apps/model-diagnostics/model_diagnostics.cpp 1.89 KB
f4334277   Hu Chunming   提交3rdparty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  /*************************************************
  USAGE:
  ./model_diagnostics -m <model file location>
  **************************************************/
  #include <opencv2/dnn.hpp>
  #include <opencv2/core/utils/filesystem.hpp>
  #include <opencv2/dnn/utils/debug_utils.hpp>
  
  #include <iostream>
  
  
  using namespace cv;
  using namespace dnn;
  
  
  static
  int diagnosticsErrorCallback(int /*status*/, const char* /*func_name*/,
                               const char* /*err_msg*/, const char* /*file_name*/,
                               int /*line*/, void* /*userdata*/)
  {
      fflush(stdout);
      fflush(stderr);
      return 0;
  }
  
  static std::string checkFileExists(const std::string& fileName)
  {
      if (fileName.empty() || utils::fs::exists(fileName))
          return fileName;
  
      CV_Error(Error::StsObjectNotFound, "File " + fileName + " was not found! "
           "Please, specify a full path to the file.");
  }
  
  std::string diagnosticKeys =
          "{ model m     | | Path to the model file. }"
          "{ config c    | | Path to the model configuration file. }"
          "{ framework f | | [Optional] Name of the model framework. }";
  
  
  
  int main( int argc, const char** argv )
  {
      CommandLineParser argParser(argc, argv, diagnosticKeys);
      argParser.about("Use this tool to run the diagnostics of provided ONNX/TF model"
                      "to obtain the information about its support (supported layers).");
  
      if (argc == 1)
      {
          argParser.printMessage();
          return 0;
      }
  
      std::string model = checkFileExists(argParser.get<std::string>("model"));
      std::string config = checkFileExists(argParser.get<std::string>("config"));
      std::string frameworkId = argParser.get<std::string>("framework");
  
      CV_Assert(!model.empty());
  
      enableModelDiagnostics(true);
      skipModelImport(true);
      redirectError(diagnosticsErrorCallback, NULL);
  
      Net ocvNet = readNet(model, config, frameworkId);
  
      return 0;
  }