This example demonstrates how to use Post-Training Quantization API from Neural Network Compression Framework (NNCF) to quantize ONNX models on the example of MobileNet v2 quantization, pretrained on Imagenette dataset.
The example includes the following steps:
- Loading the Imagenette dataset (~340 Mb) and the MobileNet v2 ONNX model pretrained on this dataset.
- Quantizing the model using NNCF Post-Training Quantization algorithm.
- Output of the following characteristics of the quantized model:
- Accuracy drop of the quantized model (INT8) over the pre-trained model (FP32)
- Performance speed up of the quantized model (INT8)
Before running this example, ensure you have Python 3.10+ installed and set up your environment:
python3 -m venv nncf_env
source nncf_env/bin/activate # On Windows: nncf_env\Scripts\activate.batpython3 -m pip install ../../../../ -r requirements.txtIt's pretty simple. The example does not require additional preparation. It will do the preparation itself, such as loading the dataset and model, etc.
python main.py