| 318 | } |
| 319 | |
| 320 | static void _loadInputs(Module::Info* info, const std::vector<std::string>& inputs, const Net* net) { |
| 321 | auto type = net->sourceType(); |
| 322 | if (type == NetSource_TENSORFLOW || type == NetSource_TFLITE) { |
| 323 | info->defaultFormat = NHWC; |
| 324 | } else { |
| 325 | info->defaultFormat = NCHW; |
| 326 | } |
| 327 | info->inputs.resize(inputs.size()); |
| 328 | std::map<std::string, Variable::Info> allInputs; |
| 329 | for (int i=0; i<net->oplists()->size(); ++i) { |
| 330 | auto op = net->oplists()->GetAs<Op>(i); |
| 331 | if (op->type() == OpType_Input && op->main_as_Input() != nullptr) { |
| 332 | auto name = net->tensorName()->GetAsString(op->outputIndexes()->data()[0])->str(); |
| 333 | auto inputInfo = op->main_as_Input(); |
| 334 | std::vector<int> dims; |
| 335 | if (nullptr != inputInfo->dims()) { |
| 336 | dims.resize(inputInfo->dims()->size()); |
| 337 | for (int v=0; v<dims.size(); ++v) { |
| 338 | dims[v] = inputInfo->dims()->data()[v]; |
| 339 | } |
| 340 | } |
| 341 | auto dtype = Utils::revertDataType(inputInfo->dtype()); |
| 342 | Variable::Info vinfo; |
| 343 | vinfo.dim = std::move(dims); |
| 344 | vinfo.order = Utils::revertFormat(inputInfo->dformat()); |
| 345 | vinfo.type = dtype; |
| 346 | vinfo.syncSize(); |
| 347 | allInputs.insert(std::make_pair(name, std::move(vinfo))); |
| 348 | } |
| 349 | } |
| 350 | for (int i=0; i<inputs.size(); ++i) { |
| 351 | auto iter = allInputs.find(inputs[i]); |
| 352 | if (iter != allInputs.end()) { |
| 353 | info->inputs[i] = iter->second; |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | Module* Module::load(const std::vector<std::string>& inputs, const std::vector<std::string>& outputs, const char* fileName, const std::shared_ptr<MNN::Express::Executor::RuntimeManager> _rtMgr, const Module::Config* config) { |
| 359 | AutoStorage<uint8_t> buffer; |