CerealPestAID
Deep learning models for classifying 26 cereal crop pest species from images. Three architectures are provided: EfficientNet-B6, MobileNetV3-Large, and InceptionV3, each available in PyTorch, ONNX, and TFLite formats.
Model Description
These models were trained to identify 26 species of cereal crop pests from field images. The goal is to support automated pest monitoring and integrated pest management (IPM) in cereal crop agriculture.
- Project Website: cerealpestaid.net
- Mobile App:
- Developed by: Luke Sheneman, University of Idaho
- Model type: Image classification (CNN)
- Language: English (labels)
- License: MIT
- Source code: github.com/sheneman/CerealPestAID
- Dataset: sheneman/CerealPestAID-dataset
Performance Summary
Evaluated on a held-out test set of 2,381 images:
| Model | Test Accuracy | Parameters | Input Size |
|---|---|---|---|
| EfficientNet-B6 | 92.94% | ~43M | 528x528 |
| MobileNetV3-Large | 90.09% | ~5.4M | 528x528 |
| InceptionV3 | 79.00% | ~27M | 528x528 |
Classes (26)
| Index | Species | Index | Species |
|---|---|---|---|
| 0 | Cabbage seedpod weevil | 13 | Lygus bug |
| 1 | Bird cherry oat aphid | 14 | Non-pest herbivores |
| 2 | Cabbage aphid | 15 | Occasional pest |
| 3 | Cereal grass aphid | 16 | Pea aphid |
| 4 | Cereal leaf beetle | 17 | Pea leaf weevil |
| 5 | Clickbeetles / wireworms | 18 | Pea weevil |
| 6 | Crucifer flea beetle | 19 | Predators |
| 7 | Cutworms | 20 | Rose grain aphid |
| 8 | Diamondback moth | 21 | Russian wheat aphid |
| 9 | English grain aphid | 22 | Stink bug |
| 10 | Greenbug | 23 | Striped flea beetle |
| 11 | Green peach aphid | 24 | Turnip aphid |
| 12 | Hessian fly | 25 | Wheathead armyworm |
Model Files
βββ efficientnet-b6/
β βββ best_factai_efficientnet-b6.pth (469 MB)
β βββ efficientnet-b6_simplified.onnx (155 MB)
β βββ efficientnet_b6_fp32.tflite (155 MB)
βββ inceptionv3/
β βββ best_factai_inceptionv3.pth (289 MB)
β βββ inceptionv3_simplified.onnx (83 MB)
β βββ inceptionv3_fp32.tflite (83 MB)
βββ mobilenetv3/
β βββ best_factai_mobilenetv3.pth (49 MB)
β βββ mobilenetv3_simplified.onnx (16 MB)
β βββ mobilenetv3_fp32.tflite (16 MB)
βββ label_mappings.txt
Usage
PyTorch (EfficientNet-B6)
import torch
import torch.nn as nn
from torchvision import transforms
from efficientnet_pytorch import EfficientNet
from PIL import Image
# Load model
model = EfficientNet.from_name("efficientnet-b6", num_classes=26)
state = torch.load("efficientnet-b6/best_factai_efficientnet-b6.pth", map_location="cpu")
model.load_state_dict(state["model_state_dict"])
model.eval()
# Preprocess
transform = transforms.Compose([
transforms.Resize(572),
transforms.CenterCrop(528),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])
image = Image.open("pest_image.jpg").convert("RGB")
input_tensor = transform(image).unsqueeze(0)
# Predict
with torch.no_grad():
output = model(input_tensor)
pred = torch.argmax(output, dim=1).item()
print(f"Predicted class: {pred}")
PyTorch (MobileNetV3-Large)
import torch
import torch.nn as nn
from torchvision import models, transforms
from PIL import Image
model = models.mobilenet_v3_large(weights=None)
model.classifier[3] = nn.Linear(model.classifier[3].in_features, 26)
state = torch.load("mobilenetv3/best_factai_mobilenetv3.pth", map_location="cpu")
model.load_state_dict(state)
model.eval()
transform = transforms.Compose([
transforms.Resize(572),
transforms.CenterCrop(528),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])
image = Image.open("pest_image.jpg").convert("RGB")
input_tensor = transform(image).unsqueeze(0)
with torch.no_grad():
output = model(input_tensor)
pred = torch.argmax(output, dim=1).item()
print(f"Predicted class: {pred}")
ONNX Runtime
import onnxruntime as ort
import numpy as np
from PIL import Image
session = ort.InferenceSession("efficientnet-b6/efficientnet-b6_simplified.onnx")
image = Image.open("pest_image.jpg").convert("RGB").resize((528, 528))
input_data = np.array(image, dtype=np.float32) / 255.0
input_data = (input_data - [0.485, 0.456, 0.406]) / [0.229, 0.224, 0.225]
input_data = np.transpose(input_data, (2, 0, 1))[np.newaxis, ...]
output = session.run(None, {"input": input_data.astype(np.float32)})
pred = np.argmax(output[0])
print(f"Predicted class: {pred}")
TFLite
import numpy as np
from PIL import Image
import tensorflow as tf
interpreter = tf.lite.Interpreter(model_path="efficientnet-b6/efficientnet_b6_fp32.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
h, w = input_details[0]['shape'][1], input_details[0]['shape'][2]
image = Image.open("pest_image.jpg").convert("RGB").resize((w, h))
input_data = np.expand_dims(np.array(image, dtype=np.float32) / 255.0, axis=0)
interpreter.set_tensor(input_details[0]['index'], input_data)
interpreter.invoke()
output = interpreter.get_tensor(output_details[0]['index'])
pred = np.argmax(np.squeeze(output))
print(f"Predicted class: {pred}")
Training Procedure
Hardware
All models were trained on the University of Idaho RCDS HPC cluster using SLURM, with CUDA 11.8:
| Model | GPU | Epochs Completed | Wall Time | Best Checkpoint Epoch |
|---|---|---|---|---|
| EfficientNet-B6 | NVIDIA RTX 3090 (24 GB) | 10 | ~5h 47m | 1 |
| InceptionV3 | NVIDIA RTX 4090 (24 GB) | 51 | ~6h 02m | 4 |
| MobileNetV3-Large | NVIDIA RTX 4090 (24 GB) | 79 | ~6h 04m | 5 |
All three training runs were terminated by the SLURM scheduler wall time limit. Best model checkpoints were saved based on minimum validation loss, which was achieved early in training for all models. Subsequent epochs continued to reduce training loss but showed increasing validation loss (overfitting), confirming that early checkpoint selection was appropriate.
Training Curves
Key observations:
- EfficientNet-B6 converged fastest, achieving its best validation loss (0.433) at epoch 1 with 88.8% validation accuracy. By epoch 10, training accuracy reached 98.2% while validation accuracy peaked at 92.2% (epoch 7).
- InceptionV3 achieved its best validation loss (0.578) at epoch 4. Validation accuracy plateaued around 89-90% while training accuracy continued to ~99.3%, indicating overfitting after ~15 epochs.
- MobileNetV3-Large achieved its best validation loss (0.474) at epoch 5. It trained the longest (79 epochs), reaching 99.7% training accuracy while validation accuracy stabilized around 90-92%.
Hyperparameters
- Optimizer: Adam (lr=1e-4)
- LR Schedule: ReduceLROnPlateau (factor=0.9, patience=5)
- Batch size: 8
- Max epochs: 1000 (early stopping via best validation loss)
- Loss: CrossEntropyLoss
- Class balancing: WeightedRandomSampler (inverse class frequency)
- Input resolution: 528x528 (resize to 572, then center crop for val/test)
Learning Rate Decay
The ReduceLROnPlateau scheduler reduced the learning rate by 0.9x each time validation loss failed to improve for 5 consecutive epochs:
| Model | Starting LR | Final LR | LR Reductions |
|---|---|---|---|
| EfficientNet-B6 | 1e-4 | 9e-5 | 1 |
| InceptionV3 | 1e-4 | 4.8e-5 | 8 |
| MobileNetV3-Large | 1e-4 | 2.8e-5 | 13 |
Data Augmentation (training only)
- RandomResizedCrop (528, scale 0.6-1.0)
- RandomHorizontalFlip
- RandomVerticalFlip
- RandomRotation (30 degrees)
- ColorJitter (brightness=0.2, contrast=0.2, saturation=0.2, hue=0.2)
- ImageNet normalization
Limitations
- Models were trained on a specific dataset of cereal pest images and may not generalize well to pest species not in the training set.
- The
non_pest_herbivoresclass is the most challenging across all models (66.7% accuracy at best), likely due to high intra-class visual variability. - Input images are expected to be well-lit, focused close-ups of individual insects.
Acknowledgments
This project, titled "Harnessing Artificial Intelligence for Implementing Integrated Pest Management in Small-Grain Production Systems," is funded under the U.S. Department of Agriculture No. 2021-67021-34253.
Team
- Sanford Eigenbrode - Distinguished Professor, Entomology, Plant Pathology, and Nematology, University of Idaho (PI)
- Arash Rashed - Virginia Tech Southern Piedmont Agricultural Research and Extension Center
- Marek Borowiec - Assistant Professor, Insect Systematist, Director of C. P. Gillette Museum, Colorado State University
- Subodh Adhikari - Assistant Professor, Entomology Extension Specialist, Utah State University
- Luke Sheneman - Director of Research Computing, University of Idaho
- Jennifer Hinds - Research Applications Architect, University of Idaho
- John Brunsfeld - Senior Full Stack Developer, University of Idaho
Citation
@misc{sheneman2025cerealpestaid,
author = {Sheneman, Luke},
title = {CerealPestAID: Deep Learning Models for Cereal Pest Identification},
year = {2025},
publisher = {HuggingFace},
url = {https://huggingface.co/sheneman/CerealPestAID}
}
- Downloads last month
- 24
