| 127 | } |
| 128 | |
| 129 | int main(int argc, const char* argv[]) { |
| 130 | if (argc < 3) { |
| 131 | MNN_PRINT("Usage: ./modelCompare.out origin.mnn origin_quant.mnn [0.05]"); |
| 132 | } |
| 133 | // read args |
| 134 | std::string cmd = argv[0]; |
| 135 | std::string pwd = "./"; |
| 136 | auto rslash = cmd.rfind("/"); |
| 137 | if (rslash != std::string::npos) { |
| 138 | pwd = cmd.substr(0, rslash + 1); |
| 139 | } |
| 140 | |
| 141 | const char* fileName = argv[1]; |
| 142 | |
| 143 | const char* compareFileName = argv[2]; |
| 144 | |
| 145 | float tolerance = 0.05f; |
| 146 | if (argc > 3) { |
| 147 | tolerance = stringConvert<float>(argv[3]); |
| 148 | } |
| 149 | MNN_PRINT("Tolerance Rate: %f\n", tolerance); |
| 150 | |
| 151 | // create net |
| 152 | MNN_PRINT("Open Model %s, %s\n", fileName, compareFileName); |
| 153 | std::shared_ptr<MNN::Interpreter> net = |
| 154 | std::shared_ptr<MNN::Interpreter>(MNN::Interpreter::createFromFile(fileName)); |
| 155 | net->setSessionMode(Interpreter::Session_Debug); |
| 156 | std::shared_ptr<MNN::Interpreter> net2 = |
| 157 | std::shared_ptr<MNN::Interpreter>(MNN::Interpreter::createFromFile(compareFileName)); |
| 158 | net2->setSessionMode(Interpreter::Session_Debug); |
| 159 | |
| 160 | // create session for get input info |
| 161 | ScheduleConfig config; |
| 162 | config.type = MNN_FORWARD_CPU; |
| 163 | auto session = net->createSession(config); |
| 164 | |
| 165 | std::map<std::string, std::shared_ptr<MNN::Tensor>> inputs; |
| 166 | std::vector<std::string> inputNames; |
| 167 | do { |
| 168 | rapidjson::Document document; |
| 169 | std::ostringstream jsonNameOs; |
| 170 | jsonNameOs << pwd << "/input.json"; |
| 171 | std::ifstream fileNames(jsonNameOs.str().c_str()); |
| 172 | if (fileNames.fail()) { |
| 173 | break; |
| 174 | } |
| 175 | std::ostringstream output; |
| 176 | output << fileNames.rdbuf(); |
| 177 | auto outputStr = output.str(); |
| 178 | document.Parse(outputStr.c_str()); |
| 179 | if (document.HasParseError()) { |
| 180 | MNN_ERROR("Invalid json\n"); |
| 181 | break; |
| 182 | } |
| 183 | if (document.HasMember("inputs")) { |
| 184 | auto inputsInfo = document["inputs"].GetArray(); |
| 185 | for (auto iter = inputsInfo.begin(); iter !=inputsInfo.end(); iter++) { |
| 186 | auto obj = iter->GetObject(); |
nothing calls this directly
no test coverage detected