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 │ │
│ └────────┬────────────────────────┘ │
│ │ │
│ ▼ …