Sub topic 3
Checking accuracy after quantization and conversion
This chapter assumes you have a trained image classifier, a float32 baseline, a converted model (TensorFlow Lite or ONNX), and a labeled validation set of a few hundred images.
Measure accuracy against the float32 baseline
Quantization and conversion can each change predictions. Run the same validation images through the original model and the converted model. Compare top-1 accuracy and the agreement rate, which is the share of images where both models predict the same class. A drop of more than about one percentage point is a reason to investigate, though the acceptable limit depends on your task.
| Model | Format | Top-1 accuracy | Agreement with float32 |
|---|---|---|---|
| Baseline | float32 | 71.8% | 100% |
| Candidate | int8 TFLite | 70.9% | 96% |
These numbers are illustrative. Replace them with your own measurements.
Running the model in an app
On Android, load the .tflite file from the assets folder with the TensorFlow Lite Interpreter. On iOS, use Core ML or the TensorFlow Lite C API. Run inference on a background thread. Inference on the main UI thread freezes the interface.
Preprocessing must match training exactly: input size, channel order, normalization, and resize method. A mismatch is the most common cause of accuracy loss that appears only in the app.
Battery drain and thermal throttling
Sustained inference heats the chip. When the temperature passes a limit, the operating system lowers the clock speed, and latency rises over time. Test with a continuous loop of several minutes, not a single run. If throttling appears, lower the frame rate, skip frames, or switch to a smaller model.
Unsupported operators and CPU fallback
When a delegate (GPU or NPU) does not support an operator, the runtime runs that operator on the CPU. Each switch between processors copies data, which can make the split model slower than CPU-only execution. Check the converter log for unsupported-operator warnings and count how many operators fall back.
Packaging, delivering, and updating models
Bundle the model in the app for offline use, or download it on first launch and verify a checksum. Version the model file and its preprocessing settings together, so an update cannot pair a new model with old preprocessing.
Exercise
Your int8 model loses 3 points of top-1 accuracy against float32. Name two causes to check before retraining.
Show answer
First, confirm that the app's preprocessing matches training (input size, channel order, normalization). Second, check that the representative dataset used for calibration contains real, preprocessed images. If both are correct, consider quantization-aware training.