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

Function getModuleInputs

tools/quantization/calibration.cpp:238–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

236using namespace MNN::Express;
237
238static std::vector<VARP> getModuleInputs(std::string file, const Module::Info* netInfo, std::vector<std::string> inputNames, std::vector<VARP> varInputs = {}) {
239#define LOAD_DATA(TYPE)\
240std::ostringstream fileNameOs;\
241fileNameOs << file << "/" << inputName << ".txt";\
242auto fileName = fileNameOs.str();\
243std::ifstream inputOs(fileName.c_str());\
244if (inputOs.fail()) {\
245MNN_ERROR("TESTERROR Can't open %s\n", fileName.c_str());\
246continue;\
247}\
248for (int i=0; i<info->size; ++i) {\
249double tempValue;\
250inputOs >> tempValue;\
251ptr[i] = tempValue;\
252}\
253
254#define LOAD_DATA_SHAPE() \
255std::ostringstream file_name_os;\
256file_name_os << file << "/input.json";\
257auto file_name = file_name_os.str();\
258std::ifstream input_os(file_name.c_str());\
259if (input_os.fail()) {\
260MNN_ERROR("Error: input.json does not exit in %s, use default shape.\n", file.c_str());\
261} else {\
262rapidjson::Document document;\
263std::ostringstream json_os;\
264json_os << input_os.rdbuf();\
265document.Parse(json_os.str().c_str());\
266if (document.HasParseError()) {\
267MNN_ERROR("Invalid json: %s\n", file_name.c_str());\
268}\
269auto cfgObj = document.GetObject();\
270if (cfgObj.HasMember("inputs")) {\
271auto inputsInfo = document["inputs"].GetArray();\
272for (auto iter = inputsInfo.begin(); iter !=inputsInfo.end(); iter++) {\
273auto obj = iter->GetObject();\
274std::string name = obj["name"].GetString();\
275if (obj.HasMember("shape")) {\
276auto dims = obj["shape"].GetArray();\
277std::vector<int> shapes;\
278for (auto iter = dims.begin(); iter != dims.end(); iter++) {\
279 shapes.emplace_back(iter->GetInt());\
280}\
281dyInputShape.insert(std::make_pair(name, shapes));\
282}\
283}\
284}\
285else {\
286MNN_ERROR("input.json must have inputs infomation!\n");\
287}\
288}\
289
290 MNN_ASSERT(netInfo != nullptr || varInputs.size() > 0);
291 auto sizeInput = 1;
292 Dimensionformat dimFormat = NCHW;
293 std::vector<Variable::Info> inputsInfo;
294 if (netInfo) {
295 sizeInput = netInfo->inputs.size();

Callers 6

CalibrationMethod · 0.85
_computeQuantErrorMethod · 0.85
_quantizeModelEMAMethod · 0.85

Calls 10

_InputFunction · 0.85
_ConvertFunction · 0.85
_CastFunction · 0.50
sizeMethod · 0.45
getInfoMethod · 0.45
nameMethod · 0.45
resizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
inputMethod · 0.45

Tested by

no test coverage detected