Downloads · 30 days
23
26% of all-time downloads
sheneman/CerealPestAID
CerealPestAID is a image classification model from sheneman. Use it when you need a label for an image. It is set up for pytorch. The card lists the license as mit.
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.
Downloads · 30 days
23
26% of all-time downloads
All-time downloads
89
Public
Repo size
1.4 GB
Likes
0
Public
Click a slice to open those files.
.pth845 MB · 61%
From the Hugging Face model README
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.
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.
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 |
| 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 |
├── 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
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}")
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}")
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}")
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}")
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.

Key observations:
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 |
non_pest_herbivores class is the most challenging across all models (66.7% accuracy at best), likely due to high intra-class visual variability.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.
@misc{sheneman2025cerealpestaid,
author = {Sheneman, Luke},
title = {CerealPestAID: Deep Learning Models for Cereal Pest Identification},
year = {2025},
publisher = {HuggingFace},
url = {https://huggingface.co/sheneman/CerealPestAID}
}