UAT 462 Edge Artificial Intelligence for UAS

Worksheet 3 Quantise the model and measure the effect on accuracy

Lab 12 hAssesses CLO2

Objective

Quantise the group's model to INT8 with a representative calibration set, compare range methods and per-channel with per-tensor scales, and decide whether QAT or another compression method is needed

Equipment and materials

  • The group's ONNX model
  • A calibration set of at least 100 images covering dawn and evening, and a labelled validation set
  • Python with onnxruntime, the example code at /downloads/uat-462/, and a target board for timing

Safety

  • Desk work, no flying
  • Use permitted images with no identifiable person, and store the data set according to personal-data guidance
  • A board under full load is hot; do not touch the heat sink

Steps

  1. Quantise the model to static INT8 with at least 100 calibration images, then compare size, time and AP with the original
  2. Change the range method (MinMax, Entropy, Percentile) and compare accuracy
  3. Calibrate on one condition and test on another; report the accuracy lost
  4. Compare per-channel with per-tensor scales if the tool supports it
  5. Use Example 5 to compute M and M0 for one layer and check that the fixed-point multiply matches the floating one
  6. If accuracy is below the criterion, reduce what can be reduced first, then try QAT, pruning or distillation; record every step

Record of results

Table 1 Size, time and accuracy before and after quantisation
ModelFile size (MB)p50 (ms)p95 (ms)Validation AP
Table 2 Effect of range method, calibration set and scale type
Calibrated onRange methodPer-channel or per-tensorTested on conditionAPChange from FP32 (percentage points)
Box 3 Working for M and M0 of one layer and the fixed-point check

Questions

  1. Did the group's INT8 file shrink to exactly a quarter of FP32? If not, why? Does the time saved match the memory-bound layers found in module 1?

  2. When calibrated on one condition and tested on another, how much did AP drop? Explain with the clipping value from the calibration set, and say which images a good calibration set for the group must contain.

  3. Did the Percentile method help or hurt on the group's data? Are the rare high values in the data signal or noise, and how do you decide?

  4. Why are per-channel scales better than per-tensor ones after folding BatchNorm? Explain with the number of levels a narrow channel can use.

  5. Should the group use QAT? Give reasons from Tables 1 and 2 and the group's accuracy criterion.

Check before you hand in

What to hand in

  • Table of size, time and accuracy before and after quantisation
  • Table of the effect of range method and calibration set
  • M and M0 results with the fixed-point check
  • A conclusion on whether QAT or another method is needed, with reasons

CLO2 Convert, accelerate, compress and quantise models for edge devices and check the effect on accuracy. (CLOs are a web-team draft; the course owner sets the final ones.)

Instructors: answers and teaching notes for this worksheet are in the teaching pack