AI-powered crop disease detection for smallholder farmers in Ghana. MobileNetV2 transfer learning, 97.3% validation accuracy on PlantVillage.
# π± AgroSense
**AI-powered crop disease advisory for smallholder farmers in West Africa.**
A farmer photographs a diseased crop. Within seconds the system identifies the disease using a fine-tuned MobileNetV2 model, generates farmer-friendly treatment advice via Gemini, and stores everything for follow-up. Built mobile-first, with an SMS fallback planned for farmers without smartphones.
---
## π The Model
Two-phase transfer learning on MobileNetV2, fine-tuned on PlantVillage (54,305 images, 38 disease classes, 14 crops). Trained on a free Kaggle P100 GPU.
| Phase | What happened | Best val accuracy |
|---|---|---|
| **1** β frozen base | Train classification head only, lr = 1e-3, 10 epochs | **94.6%** |
| **2** β fine-tune | Unfreeze top 30 layers, lr = 1e-5 (100Γ smaller), 10 epochs | **97.28%** |
Final model: **2.7 MB TFLite file** with default quantization. Negligible accuracy loss vs the Keras original.
### Training curves
The dashed vertical line marks the Phase 1 β Phase 2 transition. Notice the brief training-loss spike at epoch 11 (the "fine-tuning shock" as previously-frozen weights start receiving gradients), followed by recovery and a steady climb to 97.28%.
### Predictions on held-out validation images
12 out of 12 correct on a randomly sampled batch from the validation set. Most predictions at 99β100% confidence. The model expresses appropriate uncertainty on visually ambiguous cases β e.g., the Tomato Septoria leaf spot at 53.9% β which is exactly the behavior we want for safety-critical advice.
---
## ποΈ Architecture
```
βββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββ
β Mobile / SMS ββββββΆβ FastAPI Backend β
β (planned) β β β
βββββββββββββββββββ β βββββββββββββββββββββββββββββββββββ β
β β POST /api/diagnose β β
β ββββββββββ¬βββββββββββββββββββββββββ β
β β β
β βΌ β¦