Back to projects
Pattern Recognition & Neural Networks · Jun – Aug 2025

A 97% model is useless on a phone in a field. So I taught a small one to think like it.

A dual-branch, lesion-aware Inception teacher guided by U-Net mask proposals, distilled into a MobileNetV3 student and quantized to INT8 — with Grad-CAM used to confirm it looks at the disease, not the background.

Grad-CAMKnowledge DistillationU-NetMobileNetV3DeiTQAT / INT8PyTorch
97.12%
Teacher accuracy — lesion-aware Inception V3
15.5ms
Student inference on CPU, 299×299, after INT8 QAT
0.966
Student F1 — statistically level with the teacher's 0.970
4 classes
Common rust, leaf blight, gray spot, healthy
The problem

Three requirements that normally trade off against each other.

Corn leaf disease has to be caught early to matter. That means diagnosis happens in a field, on a cheap device, offline — which rules out the models that are accurate enough to trust.

  • Accuracy lives in models too heavy to deploy. Inception V3 and the vision transformers score well and are far too slow for edge inference.
  • Background noise is a real failure mode. A model trained on whole photographs can learn soil and lighting instead of pathology, and nobody notices until it meets a new field.
  • Compression usually costs the fine-grained cues. Distilling into a mobile-sized student risks losing exactly the lesion detail that made the teacher accurate.
  • A confident wrong diagnosis is worse than no diagnosis. A model that can't decline to answer will always answer, including on images it has no business classifying.
The approach

Force attention onto the lesion first. Compress second. Add an escape hatch last.

01

U-Net mask proposals

A lightweight U-Net proposes lesion masks, supervised jointly with the classifier.

02

Lesion-aware dual branch

One branch sees the raw image, one sees the mask-attenuated image — forcing focus onto pathology, not background.

03

Multi-teacher ensemble

The LAIC Inception teacher plus DeiT-Small contribute complementary signal.

04

Distillation into MobileNetV3

Logit distillation, attention transfer, and GAP feature matching compress the teachers into one student.

05

QAT to INT8 + abstention

Quantization-aware training for edge latency, then temperature scaling and selective prediction validated with risk–coverage analysis.

Results

The student kept the teacher's F1 and shed most of its cost.

ModelAccuracyF1Note
Inception V3 (LAIC teacher)97.12%0.970Baseline FP32, ~40.1 s/epoch
DeiT-Small96.18%0.96Best transformer evaluated
ResNet10195.23%0.95Conventional CNN reference
ViT93.32%0.93Underperforms at this dataset size
Student MobileNetV3 (FP32)97.12%0.96618.2 ms CPU
Student INT8 (dynamic QAT)95.90%0.96615.5 ms CPU — shipped
Multi-teacher KD (LAIC + DeiT)96.16%0.951Two teachers, more signal, slightly lower F1

The FP32 student matches the teacher's accuracy exactly at a fraction of the cost. Quantizing to INT8 trades 1.2 points of accuracy for another 15% latency cut — worth it for offline field use, and the honest tradeoff to state rather than hide.

EXPLAINABILITY

Grad-CAM confirms the model looks at diseased tissue

Peak activations align consistently with lesion regions rather than background — the check that separates a model that learned pathology from one that learned the photographer's habits.

ROBUSTNESS

Stress-tested against the conditions it will actually meet

Evaluated under busy backgrounds, additive Gaussian noise, severe blur, and random rectangular occlusion to measure behaviour under real distribution shift, not just clean test images.

RELIABILITY

The model is allowed to decline

Temperature scaling plus selective prediction lets it abstain on low-confidence cases, validated with risk–coverage curves and AURC — so ambiguous images route to a human instead of getting a guess.

Note on assets

This one's charts live in the notebook.

Unlike the other two ML projects, this repository ships as a single Jupyter notebook, so the Grad-CAM overlays, reliability diagrams, and risk–coverage curves are generated at run time rather than committed as image files. Export them from the notebook into assets/img/corn/ and they can be dropped into this page in the same gallery format used on the other case studies.

Built with
PythonPyTorchtorchvisionscikit-learnOpenCVONNXRoboflowGrad-CAMMatplotlibSeaborn