| 289 | } |
| 290 | |
| 291 | void 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; |
no test coverage detected