| 984 | } |
| 985 | |
| 986 | void Calibration::_computeFeatureScaleADMM() { |
| 987 | // feed input data according to input images |
| 988 | int count = 0; |
| 989 | auto netInfo = _module->getInfo(); |
| 990 | std::vector<VARP> inputs(mInputNames.size()); |
| 991 | std::vector<const MNN::Tensor*> inputTensors(mInputNames.size()); |
| 992 | if (_inputType == Helper::IMAGE) { |
| 993 | for (int i = 0; i < inputs.size(); ++i) { |
| 994 | auto shape = mInputShape[mInputNames[i]]; |
| 995 | shape[0] = _calibrationFileNum; |
| 996 | inputs[i] = _Input(shape, netInfo->inputs[i].order, netInfo->inputs[i].type); |
| 997 | inputTensors[i] = inputs[i]->getTensor(); |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | auto dimType = MNN::Tensor::CAFFE_C4; |
| 1002 | if (netInfo->inputs[0].order == NHWC) { |
| 1003 | dimType = MNN::Tensor::TENSORFLOW; |
| 1004 | } |
| 1005 | for (const auto& file : _calibrationFiles) { |
| 1006 | if (_inputType == Helper::SEQUENCE) { |
| 1007 | inputs = getModuleInputs(file, netInfo, mInputNames); |
| 1008 | } else { |
| 1009 | auto inputPtr = inputTensors[0]->host<float>() + count * inputTensors[0]->stride(0); |
| 1010 | auto name = mInputNames[0]; |
| 1011 | std::shared_ptr<MNN::Tensor> tensor(MNN::Tensor::create(mInputShape[name], netInfo->inputs[0].type, inputPtr, dimType), MNN::Tensor::destroy); |
| 1012 | Helper::preprocessInput(_process.get(), _preprocessConfig, file, tensor.get(), _inputType, mInputs[0]); |
| 1013 | } |
| 1014 | count++; |
| 1015 | MNN_PRINT("\rProcessCalibrationFiles: %.2lf %%", (float)count * 100.0f / (float)_calibrationFileNum); |
| 1016 | fflush(stdout); |
| 1017 | } |
| 1018 | MNN_PRINT("\n"); |
| 1019 | _scales.clear(); |
| 1020 | |
| 1021 | const int totalLayers = static_cast<int32_t>(_featureInfo.size()); |
| 1022 | count = 0; |
| 1023 | |
| 1024 | MNN::TensorCallBackWithInfo before = [&](const std::vector<MNN::Tensor*>& nTensors, const MNN::OperatorInfo* info) { |
| 1025 | if (Helper::gNotNeedFeatureOp.find(info->type()) == Helper::gNotNeedFeatureOp.end()) { |
| 1026 | for (auto t : nTensors) { |
| 1027 | auto weakPtr = std::weak_ptr<Tensor::InsideDescribe::NativeInsideDescribe>(TensorUtils::getDescribeOrigin(t)->mContent); |
| 1028 | if (_featureInfo.find(weakPtr) != _featureInfo.end()) { |
| 1029 | if (_featureInfo[weakPtr]->visited() == false) { |
| 1030 | _scales[weakPtr] = _featureInfo[weakPtr]->computeScaleADMM(); |
| 1031 | count++; |
| 1032 | MNN_PRINT("\rComputeADMM: %.2lf %%", (float)count * 100.0f / (float)totalLayers); |
| 1033 | fflush(stdout); |
| 1034 | } |
| 1035 | } |
| 1036 | } |
| 1037 | } |
| 1038 | return true; |
| 1039 | }; |
| 1040 | MNN::TensorCallBackWithInfo after = [&](const std::vector<MNN::Tensor*>& nTensors, const MNN::OperatorInfo* info) { |
| 1041 | if (Helper::gNotNeedFeatureOp.find(info->type()) == Helper::gNotNeedFeatureOp.end()) { |
| 1042 | for (auto t : nTensors) { |
| 1043 | auto weakPtr = std::weak_ptr<Tensor::InsideDescribe::NativeInsideDescribe>(TensorUtils::getDescribeOrigin(t)->mContent); |
nothing calls this directly
no test coverage detected