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

Method _collectFeatureMapsDistribution

tools/quantization/calibration.cpp:865–948  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

863}
864
865void Calibration::_collectFeatureMapsDistribution() {
866 for (auto& iter : _featureInfo) {
867 iter.second->resetDistribution();
868 }
869 // feed input data according to input images
870 int count = 0;
871 for (const auto& file : _calibrationFiles) {
872 count++;
873
874 for (auto& iter : _featureInfo) {
875 iter.second->setVisited(false);
876 }
877
878 for (auto& iter : _featureInfo) {
879 iter.second->resetUpdatedDistributionFlag();
880 }
881 auto netInfo = _module->getInfo();
882 std::vector<VARP> inputs;
883
884 if (_inputType == Helper::SEQUENCE) {
885 mInputs = getModuleInputs(file, netInfo, mInputNames);
886 } else {
887 auto inputTensor = (MNN::Tensor*)mInputs[0]->getTensor();
888 Helper::preprocessInput(_process.get(), _preprocessConfig, file, inputTensor, _inputType, mInputs[0]);
889 }
890 MNN::TensorCallBackWithInfo before = [&](const std::vector<MNN::Tensor*>& nTensors, const MNN::OperatorInfo* info) {
891 std::vector<std::weak_ptr<MNN::Tensor::InsideDescribe::NativeInsideDescribe>> inputsWeakPtrs;
892 for (auto t : nTensors) {
893 if (TensorUtils::getDescribe(t)->index < 0) {
894 continue;
895 }
896 auto weakPtr = std::weak_ptr<Tensor::InsideDescribe::NativeInsideDescribe>(TensorUtils::getDescribeOrigin(t)->mContent);
897 if (_featureInfo.find(weakPtr) != _featureInfo.end()) {
898 if (_featureInfo[weakPtr]->visited() == false) {
899 _featureInfo[weakPtr]->updateDistribution();
900 }
901 }
902 if (info->type() == "Raster" || info->type() == "Pooling") {
903 inputsWeakPtrs.emplace_back(weakPtr);
904 }
905 }
906
907 // store all raster input tensor
908 if (info->type() == "Raster") {
909 _rasterTensors[info->name()] = std::make_pair(inputsWeakPtrs[0], inputsWeakPtrs);
910 } else if (info->type() == "Pooling") {
911 _poolTensors[info->name()] = std::make_pair(inputsWeakPtrs[0], inputsWeakPtrs);
912 }
913 return true;
914 };
915 MNN::TensorCallBackWithInfo after = [&](const std::vector<MNN::Tensor*>& nTensors, const MNN::OperatorInfo* info) {
916 for (auto t : nTensors) {
917 if (TensorUtils::getDescribe(t)->index < 0) {
918 continue;
919 }
920 auto weakPtr = std::weak_ptr<Tensor::InsideDescribe::NativeInsideDescribe>(TensorUtils::getDescribeOrigin(t)->mContent);
921 if (_featureInfo.find(weakPtr) != _featureInfo.end()) {
922 if (_featureInfo[weakPtr]->visited() == false) {

Callers

nothing calls this directly

Calls 15

getModuleInputsFunction · 0.85
resetDistributionMethod · 0.80
setVisitedMethod · 0.80
updateDistributionMethod · 0.80
setCallBackMethod · 0.80
getInfoMethod · 0.45
getTensorMethod · 0.45
getMethod · 0.45
findMethod · 0.45
endMethod · 0.45
visitedMethod · 0.45

Tested by

no test coverage detected