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

Function channelPruneConvert

tools/converter/source/common/ChannelPruneConvert.cpp:291–366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

289}
290
291void channelPruneConvert(std::unique_ptr<MNN::NetT>& netT, MNN::Compression::Pipeline proto) {
292 bool filterPruned = false;
293 for (const auto& algo : proto.algo()) {
294 if (algo.type() == Compression::CompressionAlgo::PRUNE) {
295 auto prune_type = algo.prune_params().type();
296 auto prune_algo_type = MNN::SparseAlgo(prune_type);
297 if (prune_type == Compression::PruneParams_PruneType_FILTER) {
298 filterPruned = true;
299 break;
300 }
301 }
302 }
303
304 if (!filterPruned) {
305 return;
306 }
307
308 std::map<std::string, TensorMaskInfo> netMaskInfo;
309 for (auto tensorName : netT->tensorName) {
310 netMaskInfo[tensorName] = TensorMaskInfo();
311 }
312
313 std::set<std::string> notSafeConvNames;
314 for (auto& op : netT->oplists) {
315 analyzePruneInfo(op, netT, nullptr, netMaskInfo, notSafeConvNames);
316 }
317
318 std::set<std::string>::iterator iter;
319 if (!notSafeConvNames.empty()) {
320 for (auto& info : netMaskInfo) {
321 iter = std::find(notSafeConvNames.begin(), notSafeConvNames.end(), info.second.oriConvName);
322 if (iter != notSafeConvNames.end()) {
323 for (int i = 0; i < info.second.mask.size(); i++) {
324 if (info.second.mask[i] == 0) {
325 info.second.mask[i] = 1;
326 }
327 }
328 }
329 }
330 }
331
332 for (auto& op : netT->oplists) {
333 channelPrune(op, netT, nullptr, netMaskInfo);
334 }
335
336
337 for (auto& subgraph : netT->subgraphs) {
338 std::map<std::string, TensorMaskInfo> subgraphMaskInfo;
339 for (auto tensorName : subgraph->tensors) {
340 subgraphMaskInfo[tensorName] = TensorMaskInfo();
341 }
342
343 std::set<std::string> notSafeConvNames;
344 for (auto& op : subgraph->nodes) {
345 analyzePruneInfo(op, netT, subgraph.get(), subgraphMaskInfo, notSafeConvNames);
346 }
347
348 std::set<std::string>::iterator iter;

Callers 1

postTreatFunction · 0.85

Calls 11

SparseAlgoEnum · 0.85
TensorMaskInfoClass · 0.85
analyzePruneInfoFunction · 0.85
channelPruneFunction · 0.85
findFunction · 0.50
typeMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected