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

Method convertModel

tools/converter/source/common/cli.cpp:560–677  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

558}
559
560bool Cli::convertModel(modelConfig& modelPath) {
561 if (modelPath.dumpInfo) {
562 dumpModelInfo(modelPath.modelFile.c_str());
563 return true;
564 }
565 std::cout << "Start to Convert Other Model Format To MNN Model..., target version: " << modelPath.targetVersion << std::endl;
566 std::unique_ptr<MNN::NetT> netT = std::unique_ptr<MNN::NetT>(new MNN::NetT());
567 int parseRes = 1;
568 std::unique_ptr<MNN::OpT> metaOp(new MNN::OpT);
569 metaOp->type = MNN::OpType_Extra;
570 metaOp->main.value = new MNN::ExtraT;
571 metaOp->main.type = MNN::OpParameter_Extra;
572 metaOp->main.AsExtra()->type = "Meta";
573 metaOp->main.AsExtra()->engine = "MNN";
574 std::vector<std::string> inputNames;
575 if (modelPath.model == modelConfig::CAFFE) {
576 parseRes = caffe2MNNNet(modelPath.prototxtFile, modelPath.modelFile, modelPath.bizCode, netT);
577 } else if (modelPath.model == modelConfig::TENSORFLOW) {
578 parseRes = tensorflow2MNNNet(modelPath.modelFile, modelPath.bizCode, netT);
579 } else if (modelPath.model == modelConfig::MNN) {
580 if (modelPath.mnn2json) {
581 if (mnn2json(modelPath.modelFile.c_str(), modelPath.MNNModel.c_str())) {
582 MNN_PRINT("MNNModel %s has convert to JsonFile %s.\n", modelPath.modelFile.c_str(), modelPath.MNNModel.c_str());
583 return true;
584 } else {
585 MNN_ERROR("[ERROR] MNN to Json failed.\n");
586 return false;
587 }
588 } else {
589 parseRes = addBizCode(modelPath.modelFile, modelPath.bizCode, netT);
590 }
591 } else if (modelPath.model == modelConfig::ONNX) {
592 parseRes = onnx2MNNNet(modelPath.modelFile, modelPath.bizCode, netT, metaOp.get(), inputNames);
593 } else if (modelPath.model == modelConfig::TFLITE) {
594 if (modelPath.mnn2json) {
595 if (dumpTflite2Json(modelPath.modelFile.c_str(), modelPath.MNNModel.c_str())) {
596 MNN_PRINT("Tflite %s has convert to JsonFile %s.\n", modelPath.modelFile.c_str(), modelPath.MNNModel.c_str());
597 return true;
598 } else {
599 MNN_ERROR("[ERROR] MNN to Json failed.\n");
600 return false;
601 }
602 } else {
603 parseRes = tflite2MNNNet(modelPath.modelFile, modelPath.bizCode, netT);
604 }
605#ifdef MNN_BUILD_TORCH
606 } else if (modelPath.model == modelConfig::TORCH) {
607 parseRes = torch2MNNNet(modelPath.modelFile, modelPath.bizCode, netT, modelPath.customOpLibs);
608#endif
609 } else if (modelPath.model == modelConfig::JSON) {
610 if (json2mnn(modelPath.modelFile.c_str(), modelPath.MNNModel.c_str())) {
611 MNN_PRINT("JsonFile %s has convert to MNNModel %s.\n", modelPath.modelFile.c_str(), modelPath.MNNModel.c_str());
612 return true;
613 } else {
614 MNN_ERROR("[ERROR] Json to MNN failed.\n");
615 return false;
616 }
617 } else {

Callers

nothing calls this directly

Calls 15

dumpModelInfoFunction · 0.85
caffe2MNNNetFunction · 0.85
tensorflow2MNNNetFunction · 0.85
addBizCodeFunction · 0.85
onnx2MNNNetFunction · 0.85
dumpTflite2JsonFunction · 0.85
tflite2MNNNetFunction · 0.85
torch2MNNNetFunction · 0.85
optimizeNetFunction · 0.85
computeUnaryBufferFunction · 0.85
_reorderInputsFunction · 0.85
writeFbFunction · 0.85

Tested by

no test coverage detected