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

Function main

tools/cpp/backendTest.cpp:197–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195}
196
197int main(int argc, const char* argv[]) {
198 // read args
199 std::string cmd = argv[0];
200 std::string pwd = "./";
201 auto rslash = cmd.rfind("/");
202 if (rslash != std::string::npos) {
203 pwd = cmd.substr(0, rslash + 1);
204 }
205
206 const char* fileName = argv[1];
207
208 auto type = MNN_FORWARD_CPU;
209 if (argc > 2) {
210 type = (MNNForwardType)stringConvert<int>(argv[2]);
211 }
212 MNN_PRINT("Test forward type: %d\n", type);
213
214 float tolerance = 0.05f;
215 if (argc > 3) {
216 tolerance = stringConvert<float>(argv[3]);
217 }
218 MNN_PRINT("Tolerance Rate: %f\n", tolerance);
219
220 // create net
221 MNN_PRINT("Open Model %s\n", fileName);
222 std::shared_ptr<MNN::Interpreter> net =
223 std::shared_ptr<MNN::Interpreter>(MNN::Interpreter::createFromFile(fileName));
224 net->setSessionMode(Interpreter::Session_Debug);
225
226 // create session
227 ScheduleConfig config;
228 config.type = MNN_FORWARD_CPU;
229 auto session = net->createSession(config);
230
231 std::map<std::string, std::shared_ptr<MNN::Tensor>> inputs;
232 std::vector<std::string> inputNames;
233 do {
234 rapidjson::Document document;
235 std::ostringstream jsonNameOs;
236 jsonNameOs << pwd << "/input.json";
237 std::ifstream fileNames(jsonNameOs.str().c_str());
238 if (fileNames.fail()) {
239 break;
240 }
241 std::ostringstream output;
242 output << fileNames.rdbuf();
243 auto outputStr = output.str();
244 document.Parse(outputStr.c_str());
245 if (document.HasParseError()) {
246 MNN_ERROR("Invalid json\n");
247 break;
248 }
249 if (document.HasMember("inputs")) {
250 auto inputsInfo = document["inputs"].GetArray();
251 for (auto iter = inputsInfo.begin(); iter !=inputsInfo.end(); iter++) {
252 auto obj = iter->GetObject();
253 std::string name = obj["name"].GetString();
254 inputNames.emplace_back(name);

Callers

nothing calls this directly

Calls 15

randFunction · 0.85
_getAllOutputsFunction · 0.85
GetNetFunction · 0.85
compareForwadTypeFunction · 0.85
rfindMethod · 0.80
substrMethod · 0.80
setSessionModeMethod · 0.80
HasMemberMethod · 0.80
getSessionInputMethod · 0.80
getDimensionTypeMethod · 0.80
getModelBufferMethod · 0.80
createSessionMethod · 0.45

Tested by

no test coverage detected