On-device image classifier
Image moderation prototype for a messaging app, trained on a proxy dataset (Food-101, 3 classes) and quantised into three builds for three deployment targets.
93.1%macro F1
1.24 MBsmallest build
9,714images
Problem
A messaging app needs to classify shared images without shipping them to a server. That means the model runs on the handset, so it has to be small and fast, not just accurate. Size is the binding constraint.
Approach: transfer learning, then quantisation
How it works
- Two-stage training: the ImageNet backbone is frozen for 20 epochs so only the classification head learns, then unfrozen for 3 epochs of fine-tuning with 52 BatchNorm layers held fixed, which keeps the running statistics stable on a dataset this size.
- Three classes: healthy food, unhealthy food, non-food: 3,716 / 2,998 / 3,000 images. Close enough to balanced that macro-averaged metrics are the honest ones to report.
- One model, three builds: the same trained network is exported to TFLite three ways. Dynamic-range quantisation produces the smallest artifact for constrained hardware, float16 is the mobile default, and FP32 is kept for server inference where size stops mattering.
Why it runs on the device
- At 1.24 MB the model ships inside the app bundle, with no download step, no cold start.
- Classification happens locally, so shared photos never leave the handset to be moderated.
- Works offline, and costs nothing per image at inference time.
Results
93.10%
Macro F1
92.92%
Validation accuracy
1.24 MB
Smallest build