P25 — Knowledge Distillation for On-Device Image Classification (CIFAR-100)
Final models of course project P25 (Section B, Team 25): a ResNet-50 teacher distilled (Hinton et al., 2015; T = 2, α = 0.9) into MobileNet students, exported to TensorFlow Lite and measured on an Android phone. Code, full results and the report: https://github.com/PSKprem/kd-ondevice-image-classification Full backup of all 65 training checkpoints, exports and logs (Google Drive): https://drive.google.com/drive/folders/1x28bGIncOd_HTx_T96uGU1_t1ghtlG_t
Models
| Folder | Model | Params (M) | Baseline test top-1, 3 seeds | KD test top-1, 3 seeds | This checkpoint (seed 42), PyTorch | This checkpoint, TFLite INT8-mixed | .tflite size FP32 / INT8-mixed (MiB) | Phone latency FP32 / INT8-mixed (ms, 1 thread) |
|---|---|---|---|---|---|---|---|---|
mbv2_w0.5_kd | MobileNetV2 w0.5, distilled | 0.82 | 74.71 ± 0.16 | 75.17 ± 0.15 | 75.03 | 74.67 | 3.12 / 1.00 | 10.05 / 8.71 |
mbv3_small_kd | MobileNetV3-Small, distilled | 1.62 | 78.24 ± 0.26 | 79.77 ± 0.50 | 80.02 | 79.52 | 6.22 / 1.89 | 8.45 / 6.95 |
mbv2_w1.0_kd | MobileNetV2 w1.0, distilled | 2.35 | 80.82 ± 0.07 | 81.63 ± 0.18 | 81.71 | 81.78 | 8.95 / 2.62 | 24.11 / 17.98 |
mbv2_w1.4_kd | MobileNetV2 w1.4, distilled | 4.50 | 82.36 ± 0.02 | 84.06 ± 0.40 | 83.61 | 83.55 | 17.10 / 4.79 | 42.30 / 28.99 |
resnet50_teacher | ResNet-50 teacher | 23.71 | — | — | 85.46 | — | 90.39 / — | 225.35 / — |
- Accuracy: top-1 % on the official CIFAR-100 test set (10 000 images); the checkpoint was chosen on a held-out validation split (5 000 images), never on test. "3 seeds" = mean ± std of seeds 42 / 0 / 1 (the files here are the seed-42 models).
- INT8-mixed: regular convolutions and the classifier in int8, depthwise convolutions kept in float32 (plain INT8 lost 3.4 pp on w0.5 and broke MobileNetV3-Small).
- Latency: Samsung Galaxy F22 (Android 13, MediaTek Helio G80), TFLite
benchmark_model, CPU + XNNPACK, 1 thread, median of 3 repetitions × 100 runs. - The teacher has no INT8 file here (its INT8 version was not evaluated).
Files per model
| File | Content |
|---|---|
model.safetensors | PyTorch weights (state_dict of the best-by-validation checkpoint; optimizer state removed) |
config.json | architecture, preprocessing, training recipe, results |
model_fp32.tflite | TFLite float32 (identical predictions to PyTorch on all checked test images) |
model_int8_mixed.tflite | TFLite INT8-mixed (students only) |
classes.json gives the 100 class names in label order.
Input / preprocessing
Resize the shorter side to 147 px, centre-crop 128 × 128, scale to [0, 1], normalize with ImageNet mean (0.485, 0.456, 0.406)
and std (0.229, 0.224, 0.225). PyTorch expects NCHW; the .tflite files expect NHWC float32 [1, 128, 128, 3]. Output: 100 logits.
Usage
PyTorch (model definitions from the GitHub repository, src/models.py):
from safetensors.torch import load_file
from src.models import build_model
model = build_model("mobilenetv2", num_classes=100, width_mult=1.0, pretrained=False) # see config.json of each folder
model.load_state_dict(load_file("models/mbv2_w1.0_kd/model.safetensors"))
model.eval()
TFLite:
import numpy as np
from ai_edge_litert.interpreter import Interpreter # or tf.lite.Interpreter
it = Interpreter(model_path="models/mbv2_w1.0_kd/model_int8_mixed.tflite")
it.allocate_tensors()
x = np.zeros((1, 128, 128, 3), np.float32) # preprocessed image, NHWC
it.set_tensor(it.get_input_details()[0]["index"], x)
it.invoke()
logits = it.get_tensor(it.get_output_details()[0]["index"])
Limitations
Research / course models trained on CIFAR-100 (32 × 32 images upsampled to 128 × 128); not intended for real-world use. Single phone, CPU only. See the report in the GitHub repository (Section 9) for all limitations.
References
- G. Hinton, O. Vinyals, J. Dean. Distilling the Knowledge in a Neural Network. arXiv:1503.02531, 2015.
- M. Sandler et al. MobileNetV2: Inverted Residuals and Linear Bottlenecks. CVPR 2018. arXiv:1801.04381.