AIMS KTT Hackathon T2.1 - Compressed crop disease classifier (MobileNetV3 INT8 ONNX <10MB) + FastAPI service + USSD fallback for Rwandan smallholders.
# Compressed Crop Disease Classifier (T2.1)
> AIMS KTT Hackathon · Tier 2 · Edge-AI for Offline Crop Diagnostics
> 5 classes · MobileNetV3-Small backbone · **INT8 ONNX, 4.34 MB** · macro-F1 **1.000 clean / 0.987 field-noisy** · FastAPI service · Grad-CAM rationale · USSD fallback
**Model on Hugging Face Hub →** `DrUkachi/ktt-crop-disease-classifier`
A compact image classifier that tells a farmer whether a maize, cassava, or
bean leaf is **healthy**, has **maize_rust**, **maize_blight**,
**cassava_mosaic**, or **bean_spot** — and a non-smartphone delivery path so
the diagnosis still lands when the user has only a feature phone.
---
## Reproduce in ≤ 2 commands (free Colab CPU)
```bash
pip install -r requirements.txt
python generate_dataset.py --out data/ && python train.py && python export_onnx.py
```
`train.py` auto-detects the device (`cuda` if a GPU is attached, else `cpu`) so
the same commands work on Colab CPU free-tier (~30 min end-to-end). Inference
and the `/predict` service are CPU-only via ONNX Runtime regardless.
---
## How to use
Three paths — pick the one that matches what you want to verify.
> **Full vs lightweight mode.** The FastAPI service picks its mode automatically
> at startup based on what's on disk — there is no flag to set.
>
> - **Full mode** (Grad-CAM rationale in the `/predict` JSON) requires both
> `checkpoints/best.pt` *and* PyTorch installed. Path A (which trains the
> model) produces `best.pt`; `pip install -r requirements.txt` installs torch.
> `GET /health` returns `"rationale_mode": "full"`.
> - **Lightweight mode** (ONNX Runtime only, class-cue rationale) runs whenever
> the checkpoint is missing OR PyTorch isn't installed. A fresh `git clone`
> starts in lightweight mode — `checkpoints/` is gitignored. Paths B, C, and
> the Docker image ship lightweight by default. `GET /health` returns
> `"rationale_mode": "lightweight"`.
>
> The label / confidence / top3 / latency numbers are bit-identical across modes
> …