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

Function optimizeNetImpl

tools/converter/source/optimizer/PostConverter.cpp:265–397  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

263}
264
265std::unique_ptr<MNN::NetT> optimizeNetImpl(std::unique_ptr<MNN::NetT>& originNet,
266 const std::unordered_map<std::string, VARP>& inputs) {
267 auto current = ExecutorScope::Current();
268 current->lazyEval = true;
269 current->setLazyComputeMode(Executor::LAZY_FULL);
270 current->getAttr()->externalFile = ".__convert_external_data.bin";
271
272 auto* ctx = Global<OptimizeContext>::Get();
273 MNN_ASSERT(ctx != nullptr);
274
275 if (ctx->is_training) {
276 LOG(INFO) << "convert model for training, reserve BatchNorm and Dropout";
277 }
278 if (originNet->oplists.size() <= 0) {
279 return nullptr;
280 }
281 std::vector<std::string> postConvertPass;
282 postConvertPass = {
283 // Separate Tensor for inplace op
284 "RemoveInplace",
285
286 // Remove Unuseful Op such as NoOp, Identity, Seq2Out,
287 "RemoveUnusefulOp",
288
289 // Remove Dropout, if `forTraining` flag is set, Dropout will be reserved
290 "RemoveDropout",
291
292 // Remove Dup op
293 "FuseDupOp",
294
295 // Remove Invalid Cast
296 "RemoveInvalidCast",
297
298 // Turn InnerProduct from Caffe / Onnx to Convolution
299 "TransformInnerProduct",
300
301 // Turn Im2Seq from Caffe to Reshape
302 "TransformIm2Seq",
303
304 // Turn Caffe's ShuffleChannel to compose op
305 "TransformShuffleChannel",
306
307 "MoveUnaryOpBeforeReshape",
308
309 };
310 if (ctx->is_training) {
311 std::vector<std::string>::iterator iter = postConvertPass.begin();
312 while (iter != postConvertPass.end()) {
313 if (*iter == "RemoveDropout") {
314 iter = postConvertPass.erase(iter);
315 }
316 else {
317 iter++;
318 }
319 }
320 }
321 RunNetPass(postConvertPass, originNet);
322 std::vector<std::string> midOptPass = {

Callers 1

fuseConstIntoSubgraphFunction · 0.85

Calls 10

RunNetPassFunction · 0.85
RunExtraPassFunction · 0.85
RunMergePassFunction · 0.85
setLazyComputeModeMethod · 0.80
GetFunction · 0.50
getAttrMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected