All python demo codes are located at MNN_ROOT/pymnn/examples/. The resources used in demos are in attachments.

MNN engine demo

Mobilenet inference

This demo is for MNN engine, the session way to use MNN, only for inference.
code:mobilenet_demo.py
demo resources: mobilenet_demo.zip

MNN expression demo

These demos use MNN expression API to create network and train them. The MNN expression mechanism and training framework enable us to do thing like quantization-aware training, finetuning, and so on.

MNIST

code: MNIST demo
demo resources: no need. The MNIST dataset will be downloaded in the demo.

Finetune

This demo shows how to train a image classifier by finetuning on your own dataset using MobilenetV2 feature extractor.
code: mobilenet finetune demo
demo resources: train_dataset.ziptest_dataset.zipmodel.zip

Quantization-aware training

This demo shows how to do Quantization-aware training (QAT) in MNN python.
code: quantization aware training demo
demo resources: quantization_aware_training_demo.zip

Python quantization tool

https://github.com/alibaba/MNN/tree/master/tools/MNNPythonOfflineQuant
compared to C++ version, this tool can handle multi-input, non-image-input models. you can write preprocessing code in python. this tool is reconmended.
Tips:1. use relu/relu6 instead of prelu; 2. when the input shape of your model is changeable, you should set “—batch_size 1” when using the tool;