A small convolutional neural network (about 0.4 million parameters), written from scratch in PyTorch, that classifies a photo of a plant leaf into one of 39 PlantVillage classes (a crop and its disease, or healthy). It was built for the King's College London 5CCSAGAP small group project and powers the public demo app.
The network has four convolutional blocks and a small classification head. Each block is a 3x3 convolution, batch normalisation, ReLU and 2x2 max pooling, with 32, 64, 128 and 256 channels. Global average pooling, dropout and a linear layer then produce 39 scores. The input is a 3 x 128 x 128 RGB image and the output is one score per class (apply a softmax for probabilities). It was trained from scratch, with no pre-trained weights.
An educational demo: upload a photo of a single plant leaf and see the five most likely classes with their probabilities, as in the demo app.
Use it as a demonstration only. Treat the top-5 list as a guide, check unusual results by eye, and consult an agronomist for real plant health decisions.
The checkpoint is a PyTorch file holding state_dict, config and classes. The model code (src/models/) comes from the project repository.
import torch
from huggingface_hub import hf_hub_download
from PIL import Image
from torchvision import transforms
from src.models.registry import build_model
path = hf_hub_download("abia13/plant-disease-baseline-cnn", "best.pt")
checkpoint = torch.load(path, map_location="cpu", weights_only=True)
classes = checkpoint["classes"]
settings = dict(checkpoint["config"]["model"])
name = settings.pop("name")
model = build_model(name, num_classes=len(classes), **settings) # same settings as training
model.load_state_dict(checkpoint["state_dict"])
model.eval()
data = checkpoint["config"]["data"]
size = data["image_size"]
mean, std = data["normalise"]["mean"], data["normalise"]["std"]
preprocess = transforms.Compose([
transforms.Resize((size, size)),
transforms.ToTensor(),
transforms.Normalize(mean, std), # required: the model was trained on normalised images
])
image = preprocess(Image.open("leaf.jpg").convert("RGB")).unsqueeze(0)
with torch.no_grad():
probabilities = torch.softmax(model(image), dim=1)[0]
top5 = probabilities.topk(5)
for probability, index in zip(top5.values, top5.indices):
print(f"{classes[index]}: {probability:.1%}")
PlantVillage (DScomp380/plant_village, licence CC0-1.0): 55,447 photos of leaves, 256 x 256 pixels, in 39 classes such as Tomato_healthy and Grape_Black_rot. The data was split 70% train, 15% validation and 15% test, stratified by class with a fixed seed, so every image is used exactly once.
Images are resized to 128 x 128 and converted to tensors, then normalised per channel with the data.normalise values from configs/default.yaml (mean 0.485, 0.456, 0.406; std 0.229, 0.224, 0.225). Skipping normalisation gives wrong predictions. Random augmentation (rotation up to 15 degrees and colour jitter of 0.2) is applied to training images only.
subset_fraction 0.25), not the full training set.About 0.4 million parameters, roughly 1.6 MB of weights. A baseline run on the 25% training subset took about 10 to 13 minutes on a Colab GPU. The uploaded run took about 12.5 minutes on one Tesla T4.
The held-out 15% test split, never used for training or for choosing settings.
Results are broken down by class.
Accuracy, top-5 accuracy, per-class precision, recall and F1, macro-F1 and a confusion matrix. Accuracy is the share of photos labelled correctly. Top-5 accuracy counts a hit if the right class is among the five best guesses. Macro-F1 averages F1 over classes, so rare classes count as much as common ones.
| Split | Accuracy | Top-5 accuracy | Macro-F1 |
|---|---|---|---|
| Validation (best epoch) | 94.1% | 99.8% | 0.93 |
Test results and per-class highlights will be added when they are completed.
Interim note: baseline runs on the 25% training subset reached 92 to 94% validation accuracy, with about 1.7 points of spread between seeds. This will be updated when the uploaded checkpoint is finalised. These scores are for lab-style photos and should not be read as field accuracy.
Carbon emissions were not measured. They can be estimated with the Machine Learning Impact calculator presented in Lacoste et al. (2019).
Four blocks of (3x3 convolution, batch normalisation, ReLU, 2x2 max pooling) with 32, 64, 128 and 256 channels, then global average pooling, dropout and a linear layer to 39 outputs. The objective is cross-entropy over the 39 classes.
Training on one NVIDIA Tesla T4 GPU in Google Colab (Linux, Python 3.13); the demo app runs inference on CPU.
PyTorch 2.14.1 and torchvision 0.29.1 (CUDA 13.0 builds) for training; inference is tested on CPU with PyTorch 2.15.0, Hugging Face Hub, Weights & Biases for experiment tracking.
The model has no paper. The dataset is described in:
BibTeX:
@article{hughes2015plantvillage,
title = {An open access repository of images on plant health to enable the development of mobile disease diagnostics},
author = {Hughes, David P. and Salath{\'e}, Marcel},
journal = {arXiv preprint arXiv:1511.08060},
year = {2015}
}
APA:
Hughes, D. P., & Salathé, M. (2015). An open access repository of images on plant health to enable the development of mobile disease diagnostics. arXiv:1511.08060.
The FiveGuys team: Shruti, Fakhriyya, Stephanie, Kaya, Jood, Anusha, Ira, Abia.