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

Method _computeFeatureMapsRange

tools/quantization/calibration.cpp:809–863  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

807}
808
809void Calibration::_computeFeatureMapsRange() {
810 // feed input data according to input images
811 int count = 0;
812
813 auto netInfo = _module->getInfo();
814 for (const auto& file: _calibrationFiles) {
815 std::vector<VARP> inputs;
816 for (auto& iter : _featureInfo) {
817 iter.second->setVisited(false);
818 }
819 for (auto& iter : _featureInfo) {
820 iter.second->resetUpdatedRangeFlags();
821 }
822
823 if (_inputType == Helper::SEQUENCE) {
824 mInputs = getModuleInputs(file, netInfo, mInputNames);
825 } else {
826 auto inputTensor = (MNN::Tensor*)mInputs[0]->getTensor();
827 Helper::preprocessInput(_process.get(), _preprocessConfig, file, inputTensor, _inputType, mInputs[0]);
828 }
829
830 MNN::TensorCallBackWithInfo before = [&](const std::vector<MNN::Tensor*>& nTensors,
831 const MNN::OperatorInfo* info) {
832 for (auto t : nTensors) {
833 if (TensorUtils::getDescribe(t)->index < 0) {
834 continue;
835 }
836 auto weakPtr = std::weak_ptr<Tensor::InsideDescribe::NativeInsideDescribe>(TensorUtils::getDescribeOrigin(t)->mContent);
837 if (_featureInfo.find(weakPtr) != _featureInfo.end()) {
838 if (_featureInfo[weakPtr]->visited() == false) {
839 _featureInfo[weakPtr]->updateRange();
840 }
841 }
842 }
843 return true;
844 };
845 MNN::TensorCallBackWithInfo after = [&](const std::vector<MNN::Tensor*>& nTensors,
846 const MNN::OperatorInfo* info) {
847 for (auto t : nTensors) {
848 if (TensorUtils::getDescribe(t)->index < 0) {
849 continue;
850 }
851 auto weakPtr = std::weak_ptr<Tensor::InsideDescribe::NativeInsideDescribe>(TensorUtils::getDescribeOrigin(t)->mContent);
852 if (_featureInfo.find(weakPtr) != _featureInfo.end()) {
853 if (_featureInfo[weakPtr]->visited() == false) {
854 _featureInfo[weakPtr]->updateRange();
855 }
856 }
857 }
858 return true;
859 };
860 Express::Executor::getGlobalExecutor()->setCallBack(std::move(before), std::move(after));
861 auto outputs = _module->onForward(mInputs);
862 }
863}
864
865void Calibration::_collectFeatureMapsDistribution() {
866 for (auto& iter : _featureInfo) {

Callers

nothing calls this directly

Calls 12

getModuleInputsFunction · 0.85
setVisitedMethod · 0.80
setCallBackMethod · 0.80
getInfoMethod · 0.45
getTensorMethod · 0.45
getMethod · 0.45
findMethod · 0.45
endMethod · 0.45
visitedMethod · 0.45
updateRangeMethod · 0.45
onForwardMethod · 0.45

Tested by

no test coverage detected