Crop Disease Detector
An AI model that identifies plant diseases from a single leaf photo. MobileNetV2 + Transfer Learning trained on 87,000+ images across 38 disease classes. ~97% accuracy. Live on Hugging Face Spaces, free to use.
Crop Disease Detector is an AI that looks at a leaf photo and tells you what's wrong with the plant. Point your phone at a sick plant, upload the photo, and the model tells you which of 38 disease conditions it's likely showing — within seconds, for free.
The model is trained on the PlantVillage dataset — 87,000+ high-quality images of healthy and diseased leaves across 14 crop types. MobileNetV2 was chosen as the backbone for its efficiency: it achieves near-ResNet accuracy at a fraction of the computational cost, making it ideal for deployment on free-tier cloud infrastructure.
MobileNetV2 uses depthwise separable convolutions to drastically reduce parameter count while preserving feature extraction power. Transfer Learning from ImageNet weights means we start with powerful low-level feature detectors (edges, textures) already learned.
Standard Conv = K × K × C_in × C_out
Depthwise Sep = K × K × C_in ← depthwise
+ 1 × 1 × C_in × C_out ← pointwiseInstead of one big filter that looks at all channels at once, MobileNetV2 splits the work: first a per-channel spatial filter (depthwise), then a 1×1 filter that mixes channels (pointwise). The math works out to ~8–9× fewer multiply-adds for the same output shape — which is why MobileNetV2 runs fast on a phone CPU.
3×3 conv, 32 channels in → 64 channels out:
Standard: 3 × 3 × 32 × 64 = 18,432 params
DepthSep: 3 × 3 × 32 = 288 (depthwise)
+ 1 × 1 × 32 × 64 = 2,048 (pointwise)
= 2,336 total (≈8× fewer)Phase 1 — Feature Extraction
Freeze all MobileNetV2 layers
Train only top head | epochs=10, LR=1e-3
Phase 2 — Fine-Tuning
Unfreeze top 30 MobileNetV2 layers
Retrain with low LR | epochs=20, LR=1e-4
Augmentation: RandomFlip · RandomRotation(0.2)
RandomZoom(0.1) · RandomContrast(0.1)Two-phase training is a standard trick with pretrained models. Phase 1 warms up the new classification head without touching the ImageNet weights (so you don't immediately destroy what was learned). Phase 2 uses a tiny learning rate to gently nudge the upper layers toward leaf disease patterns — aggressive updates here would cause "catastrophic forgetting."
# TensorFlow / Keras pseudocode
# Phase 1
base_model.trainable = False
model.compile(optimizer=Adam(1e-3), ...)
model.fit(train_ds, epochs=10)
# Phase 2
for layer in base_model.layers[-30:]:
layer.trainable = True
model.compile(optimizer=Adam(1e-4), ...)
model.fit(train_ds, epochs=20)Loss = Categorical Cross-Entropy
= −Σ y_i × log(ŷ_i) for i in 1..38 classes
Validation Results
Accuracy ~97.2% Top-5 Acc ~99.8%
Precision ~96.9% Recall ~97.1%
F1-Score ~97.0% (all macro avg)Cross-entropy penalises the model based on how confident it was about the wrong class. If the true label is Tomato Blight but the model output 80% confidence for Healthy, the loss is high. This pushes the network toward being right and confident, not just vaguely correct. The macro-average F1 of 97% means the model performs consistently across rare and common disease classes, not just the easy majority ones.
# Concrete example for one prediction: true_label = [0, 0, 1, 0, ...] # class 2 = "Tomato Blight" predicted = [0.01, 0.02, 0.93, 0.01, ...] loss = −log(0.93) = 0.073 ← low, model was right # If model was uncertain: predicted = [0.10, 0.30, 0.40, 0.05, ...] loss = −log(0.40) = 0.916 ← higher penalty
The model covers 14 crop types and 38 disease conditions including healthy states. A sample of the classes:
+ 26 more classes across rice, wheat, pepper, peach, cherry, orange, and soybean. All classes include a "Healthy" baseline.