Image Classification
timm
PyTorch
Safetensors
agriculture
plant-disease
coffee

Arabica Coffee Leaf Disease Classification — efficientnet_b0

A efficientnet_b0 (4.0M params) fine-tuned to classify 5 arabica coffee leaf conditions from close-up RGB crops.

⚠️ Read this before comparing to published numbers

The source dataset lists 58,549 images. It contains 3,756 unique images93.6% of the rows are exact byte-for-byte duplicates. One Healthy image appears 520 times. After also grouping near-duplicate crops of the same leaf (perceptual hash, hamming <= 5), only 2,891 independent images remain.

Class counts collapse dramatically, and the balance inverts — Healthy is the largest class as listed and the smallest in reality:

Class Listed rows Byte-unique Independent groups
Cerscospora 7,681 322 317
Healthy 18,983 62 48
Leaf_rust 8,336 1,042 918
Miner 16,978 1,639 923
Phoma 6,571 691 685
TOTAL 58,549 3,756 2,891

This model is trained and evaluated on the deduplicated, group-disjoint data, so no near-duplicate crop appears in more than one split.

The obvious expectation is that removing this much duplication should crater the score. It does not — and reporting that honestly matters more than a tidy story:

Split protocol n train Test accuracy Test macro-F1
Naive random split over all 58,549 rows (leaky) 40,981 1.0000 1.0000
Group-aware split over 2,891 independent images (honest) 2,628 0.9911 0.9941

The leaky protocol buys only +0.0089 accuracy / +0.0059 macro-F1. So on this dataset the duplication inflates the apparent size (58,549 vs ~2,891 real images) far more than it inflates the score. These five classes are simply easy to separate: a model trained on 2,628 images with no duplicate leakage still reaches 99.11%.

Do not read this as "leakage is harmless" in general — it is a property of this dataset's easy class boundaries. Read it as: this dataset is ~20x smaller than its row count suggests, and its headline accuracies are not evidence of much.

Results (honest split, test n=564)

Metric Score
Accuracy 0.9911
Macro-F1 0.9941

Measured with timm's canonical inference transform (224px, crop_pct=0.875, bicubic), i.e. exactly the preprocessing the Usage snippet produces.

Per-class

Class Precision Recall F1 Test support Train images
Cerscospora 1.000 1.000 1.000 48 226
Healthy 1.000 1.000 1.000 9 43
Leaf_rust 1.000 0.981 0.990 156 729
Miner 0.980 1.000 0.990 246 1147
Phoma 1.000 0.981 0.990 105 483

Intended use

Research and educational use only. Not a substitute for agronomist diagnosis. The Healthy class is supported by only 43 training images from 48 independent sources — treat its predictions with particular suspicion.

Training

  • Backbone: efficientnet_b0 (ImageNet-pretrained, via timm)
  • Data: 2628 train / 564 val / 564 test, split by near-duplicate group (70/15/15), verified zero group overlap
  • Resolution: 224x224 (source crops are mostly 128x128, so they are upscaled)
  • Optimiser: AdamW, OneCycle LR (max 3e-4), weight decay 0.05, 20 epochs, batch 64
  • Loss: cross-entropy, label smoothing 0.1, no class weighting (uniform)
  • Augmentation: random resized crop (0.6-1.0), h/v flip, colour jitter, random erasing
  • Precision: bf16 autocast. Selection: best val macro-F1.

Usage

import timm, torch
from PIL import Image

model = timm.create_model("hf-hub:Huyt/arabica-coffee-leaf-disease-efficientnet-b0", pretrained=True).eval()
cfg = timm.data.resolve_data_config({}, model=model)
tf = timm.data.create_transform(**cfg)

img = Image.open("leaf.jpg").convert("RGB")
with torch.no_grad():
    probs = model(tf(img).unsqueeze(0)).softmax(-1)[0]

idx = int(probs.argmax())
print(model.pretrained_cfg["label_names"][idx], float(probs[idx]))

Class order (index -> label):

['Cerscospora', 'Healthy', 'Leaf_rust', 'Miner', 'Phoma']

Limitations

  • The dataset is ~20x smaller than advertised. 2,891 independent images, not 58,549. Everything below follows from that.
  • Healthy is critically under-supported: 48 independent images total. Its metrics rest on 9 test images and are not trustworthy.
  • Crops, not leaves. Inputs are close-up patches (mostly 128x128), not whole leaves. The model expects similar close-ups; it is not a whole-plant or field classifier.
  • Near-duplicate grouping is a lower bound. Perceptual hashing at hamming <= 5 catches tight crops of the same lesion. Wider crops of the same leaf may survive as separate groups, so residual same-source optimism may remain even in the honest number. A nearest-neighbour probe (ImageNet embeddings, test vs train) found the honest split's residual-similarity signal to be no worse than a comparably-built rice split (+0.42 vs +0.52 excess over the same-class baseline), but that probe cannot cleanly separate leakage from a genuinely low-diversity dataset. Treat 99.11% as an upper bound on real-world performance.
  • The test set is small. 564 images; at 99.11% accuracy that is ~5 errors total. Per-class figures rest on tens of images and carry wide error bars.
  • Single-source dataset (JMuBEN / JMuBEN2, Kenya). No external validation; the lab->field gap is unmeasured.

Reproduction

coffee_dedup.py (hashing + grouping), coffee_split.py (both splits), coffee_train.py (training), coffee_eval_final.py (canonical-transform eval) are included in this repo.

Dataset citation

@article{jepkoech2021arabica,
  title={Arabica coffee leaf images dataset for coffee leaf disease detection and classification},
  author={Jepkoech, Jennifer and Mugo, David Muchangi and Kenduiywo, Benson K and Too, Edna Chebet},
  journal={Data in brief}, volume={36}, pages={107142}, year={2021}, publisher={Elsevier}
}
Downloads last month
162
Safetensors
Model size
4.06M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Dataset used to train Huyt/arabica-coffee-leaf-disease-efficientnet-b0