Computer Vision · Advanced level

Advanced level · Module 2: Transfer Learning and Model Optimization · Lesson 3 of 3

Post-Training Quantisation

Learners quantise a model from 32-bit floating point to 8-bit integers, measure the effect and understand when calibration data is needed.

In this lesson you will

  • Explain quantisation and its trade-offs
  • Quantise a model and measure size, speed and accuracy

Key concepts

FP32 vs INT8dynamic quantisationstatic quantisation with calibrationquantisation-aware trainingaccuracy drop

The lesson

Quantisation stores weights (and sometimes activations) as 8-bit integers instead of 32-bit floats, which makes models about four times smaller and often faster on CPUs.

Dynamic quantisation converts weights ahead of time and activations on the fly; it is easy but helps convolution-heavy models less. Static quantisation also quantises activations, using a small calibration set of representative images to choose ranges. Quantisation-aware training simulates quantisation during training for the best accuracy.

In this programme, quantisation for deployment is done on the exported ONNX model with ONNX Runtime (Modules 9 and 10). Here learners measure the idea in PyTorch and check accuracy on the local test set, because errors can grow on unusual images.

Step by step

  1. Measure FP32 model size, latency and accuracy.
  2. Apply PyTorch dynamic quantisation to the linear layers.
  3. Re-measure all three.
  4. Prepare a calibration set of 100 representative local images for later static quantisation.

Practice activity

Measure the effect of quantisation and prepare a calibration set.

Expected result: A before/after table and a documented calibration set.

Check your understanding

  1. Roughly how much smaller is an INT8 model than FP32?

    Show answer

    About four times smaller.

  2. What is calibration data used for in static quantisation?

    Show answer

    To choose the value ranges for quantising activations.

Further learning

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.