A small detector had to fit and run on a phone held in a store aisle. int8 quantisation was the obvious lever. It halved the model and tripled the speed, but the outputs became useless. The fix was to stop quantising one part of it.
The setup
Ultralytics YOLO detector, exported three ways: CoreML for iOS, ONNX Runtime for cross-platform CPU, TFLite for Android. Target was real-time inference on the scanning device itself, with no server in the loop and accuracy close enough to the fp32 baseline that downstream logic didn't have to change.
What collapsed
Quantising every layer to int8 produced a model that loaded, ran, and returned confidence scores that no longer separated anything. Detections technically existed; the ranking between them was noise. The failure is quiet. There is no exception and no warning, only a metric that falls off a cliff.
The head is where small numerical differences become large ranking differences. That's exactly what int8 is bad at.
The fix
Restrict quantisation to convolution layers and leave the head in higher precision. Nearly all of the size and latency win comes from the convolutional backbone anyway, so the trade is lopsided in your favour.
# conv-only QDQ, per-channel
quantize_static(
model_input,
model_output,
calibration_data_reader=reader,
quant_format=QuantFormat.QDQ,
op_types_to_quantize=["Conv"],
per_channel=True,
)Numbers
| Build | Size | CPU speed | Accuracy |
|---|---|---|---|
| fp32 | 1× | baseline | baseline |
| int8, all layers | ½ | n/a | collapsed |
| int8, conv-only QDQ | ½ | ~3× faster | within 1% |
When this applies
Any architecture where a small output head turns features into scores or coordinates: detectors, rankers, retrieval scorers. If accuracy falls apart after quantisation, isolate the head before you touch anything else.