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

Method testconvert

tools/converter/source/common/cli.cpp:758–984  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

756}
757
758int Cli::testconvert(const std::string& defaultCacheFile, const std::string& directName, float maxErrorRate, const std::string& backendConfigJson) {
759 std::map<std::string, float> inputInfo;
760 std::map<std::string, std::vector<int>> inputShape;
761 std::vector<std::string> inputNames;
762 std::vector<std::string> outputNames;
763 {
764 rapidjson::Document document;
765 std::ostringstream jsonNameOs;
766 jsonNameOs << directName << "/input.json";
767 std::ifstream fileNames(jsonNameOs.str().c_str());
768 std::ostringstream output;
769 output << fileNames.rdbuf();
770 auto outputStr = output.str();
771 document.Parse(outputStr.c_str());
772 if (document.HasParseError()) {
773 MNN_ERROR("Invalid json\n");
774 return 0;
775 }
776 if (document.HasMember("inputs")) {
777 auto inputsInfo = document["inputs"].GetArray();
778 for (auto iter = inputsInfo.begin(); iter !=inputsInfo.end(); iter++) {
779 auto obj = iter->GetObject();
780 std::string name = obj["name"].GetString();
781 inputNames.emplace_back(name);
782 MNN_PRINT("%s\n", name.c_str());
783 if (obj.HasMember("value")) {
784 float value = obj["value"].GetFloat();
785 inputInfo.insert(std::make_pair(name, value));
786 }
787 if (obj.HasMember("shape")) {
788 auto dims = obj["shape"].GetArray();
789 std::vector<int> shapes;
790 for (auto iter = dims.begin(); iter != dims.end(); iter++) {
791 shapes.emplace_back(iter->GetInt());
792 }
793 inputShape.insert(std::make_pair(name, shapes));
794 }
795 }
796 }
797 if (document.HasMember("outputs")) {
798 auto array = document["outputs"].GetArray();
799 for (auto iter = array.begin(); iter !=array.end(); iter++) {
800 std::string name = iter->GetString();
801 MNN_PRINT("output: %s\n", name.c_str());
802 outputNames.emplace_back(name);
803 }
804 }
805 }
806
807 // create session
808 MNN::ScheduleConfig config;
809 config.type = MNN_FORWARD_CPU;
810 /*modeNum means gpuMode for GPU usage, Or means numThread for CPU usage.*/
811 config.numThread = 2;
812 // If type not fount, let it failed
813 config.backupType = MNN_FORWARD_CPU;
814 BackendConfig backendConfig;
815 backendConfig.precision = static_cast<MNN::BackendConfig::PrecisionMode>(1);

Callers

nothing calls this directly

Calls 15

_InputFunction · 0.85
_ConvertFunction · 0.85
HasMemberMethod · 0.80
BeginMethod · 0.80
fixMethod · 0.80
compareOutputFunction · 0.70
loadFunction · 0.50
cloneFunction · 0.50
_CastFunction · 0.50
minFunction · 0.50
saveFunction · 0.50
c_strMethod · 0.45

Tested by

no test coverage detected