🌱 Crop Disease Classifier (EfficientNetV2-S β€” 38 Classes)

A production-ready EfficientNetV2-S model fine-tuned on the PlantVillage benchmark (54,306 images across 38 disease & healthy categories spanning 14 crop species).

Achieves 99.89% validation accuracy with sub-4ms GPU inference latency and includes Grad-CAM explainability and ONNX edge deployment weights.


🎯 Benchmark Results

Model Val Accuracy Macro F1 Latency (RTX 5080) Parameters Format
EfficientNetV2-S (Ours) 99.89% ~0.999 ~3.9 ms 21.5M PyTorch + ONNX
ResNet50 (Baseline) 97.10% 0.969 ~3.8 ms 25.6M PyTorch

Trained on NVIDIA GeForce RTX 5080 (CUDA 13.2, SM_120) with cosine learning rate schedule, AdamW optimizer, label smoothing 0.1, batch size 64.


🌿 Crops & Disease Coverage (38 Classes)

The model detects specific pathologies as well as healthy leaves across 14 agricultural crop species:

  • Apple: Apple Scab, Black Rot, Cedar Apple Rust, Healthy
  • Blueberry: Healthy
  • Cherry: Powdery Mildew, Healthy
  • Corn (Maize): Cercospora / Gray Leaf Spot, Common Rust, Northern Leaf Blight, Healthy
  • Grape: Black Rot, Esca (Black Measles), Leaf Blight (Isariopsis), Healthy
  • Orange: Huanglongbing (Citrus Greening)
  • Peach: Bacterial Spot, Healthy
  • Bell Pepper: Bacterial Spot, Healthy
  • Potato: Early Blight, Late Blight, Healthy
  • Raspberry: Healthy
  • Soybean: Healthy
  • Squash: Powdery Mildew
  • Strawberry: Leaf Scorch, Healthy
  • Tomato: Bacterial Spot, Early Blight, Late Blight, Leaf Mold, Septoria Leaf Spot, Two-Spotted Spider Mite, Target Spot, Yellow Leaf Curl Virus, Mosaic Virus, Healthy

πŸ” Explainable AI: Grad-CAM

In agriculture, black-box predictions are not enough β€” agronomists and farmers need to know where the model detected symptoms. The model's activations align precisely with pathological lesions, rust pustules, and necrosis spots rather than background artifacts.


πŸš€ Quick Start (Inference)

1. Using ONNX Runtime (No PyTorch required, fast & lightweight)

pip install onnxruntime pillow numpy huggingface_hub
import json
import numpy as np
from PIL import Image
import onnxruntime as ort
from huggingface_hub import hf_hub_download

# Download model & classes
onnx_model = hf_hub_download(repo_id="BiernyVR/crop-disease-classifier", filename="efficientnet_v2_s_best.onnx")
onnx_data = hf_hub_download(repo_id="BiernyVR/crop-disease-classifier", filename="efficientnet_v2_s_best.onnx.data")
classes_file = hf_hub_download(repo_id="BiernyVR/crop-disease-classifier", filename="classes.json")

with open(classes_file, "r") as f:
    classes = json.load(f)["classes"]

# Preprocess image
img = Image.open("leaf.jpg").convert("RGB").resize((224, 224), Image.Resampling.BILINEAR)
arr = (np.array(img, dtype=np.float32) / 255.0 - [0.485, 0.456, 0.406]) / [0.229, 0.224, 0.225]
tensor = np.expand_dims(np.transpose(arr, (2, 0, 1)), axis=0).astype(np.float32)

# Run inference
session = ort.InferenceSession(onnx_model, providers=["CPUExecutionProvider"])
logits = session.run(None, {"input": tensor})[0][0]
probs = np.exp(logits - np.max(logits))
probs /= probs.sum()

top_class = classes[np.argmax(probs)]
print(f"Prediction: {top_class} ({np.max(probs)*100:.2f}%)")

2. Standalone CLI

python infer.py --image sample_leaf.jpg --topk 3

πŸ“¦ Files in this Repository

  • efficientnet_v2_s_best.pth: Full PyTorch model checkpoint.
  • efficientnet_v2_s_best.onnx + .onnx.data: ONNX exported weights for TensorRT / mobile / ONNX Runtime.
  • classes.json: Complete mapping of 38 disease and healthy classes.
  • sample_leaf.jpg: Test apple scab sample leaf image.
  • sample_gradcam.png: Grad-CAM visualization output.
  • infer.py: Self-contained evaluation script.
  • confusion_matrix.png, training_curves.png, per_class_accuracy.png: Evaluation and training metrics plots.
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Evaluation results