MCPcopy Create free account
hub / github.com/alibaba/MNN / findModelFiles

Function findModelFiles

benchmark/benchmark.cpp:54–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52#endif
53
54std::vector<Model> findModelFiles(const char* dir) {
55 std::vector<Model> models;
56#if defined(_MSC_VER)
57 WIN32_FIND_DATA ffd;
58 HANDLE hFind = INVALID_HANDLE_VALUE;
59 std::string mnn_model_pattern = std::string(dir) + "\\*.mnn";
60 hFind = FindFirstFile(mnn_model_pattern.c_str(), &ffd);
61 if (INVALID_HANDLE_VALUE == hFind) {
62 std::cout << "open " << dir << " failed: " << strerror(errno) << std::endl;
63 return models;
64 }
65 do {
66 Model m;
67 m.name = ffd.cFileName;
68 m.model_file = std::string(dir) + "\\" + m.name;
69 if(INVALID_FILE_ATTRIBUTES != GetFileAttributes(m.model_file.c_str()) && GetLastError() != ERROR_FILE_NOT_FOUND) {
70 models.push_back(std::move(m));
71 }
72 } while (FindNextFile(hFind, &ffd) != 0);
73 FindClose(hFind);
74#else
75 DIR* root;
76 if ((root = opendir(dir)) == NULL) {
77 std::cout << "open " << dir << " failed: " << strerror(errno) << std::endl;
78 return models;
79 }
80
81 struct dirent* ent;
82 while ((ent = readdir(root)) != NULL) {
83 Model m;
84 if (ent->d_name[0] != '.') {
85 m.name = ent->d_name;
86 m.model_file = std::string(dir) + "/" + m.name;
87 if (file_exist(m.model_file.c_str())) {
88 models.push_back(std::move(m));
89 }
90 }
91 }
92 closedir(root);
93#endif
94 return models;
95}
96
97void setInputData(MNN::Tensor* tensor) {
98 float* data = tensor->host<float>();

Callers 2

iosBenchAllFunction · 0.85
mainFunction · 0.85

Calls 4

file_existFunction · 0.85
stringFunction · 0.50
c_strMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected