CoolFace
Modelpublic

sheneman/CerealPestAID

sourceHugging Facemitupdated 7mo agoView on Hugging Face
0likes22downloads
Model Card

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.

Performance Summary

Evaluated on a held-out test set of 2,381 images:

ModelTest AccuracyParametersInput Size
EfficientNet-B692.94%~43M528x528
MobileNetV3-Large90.09%~5.4M528x528
InceptionV379.00%~27M528x528

Classes (26)

IndexSpeciesIndexSpecies
0Cabbage seedpod weevil13Lygus bug
1Bird cherry oat aphid14Non-pest herbivores
2Cabbage aphid15Occasional pest
3Cereal grass aphid16Pea aphid
4Cereal leaf beetle17Pea leaf weevil
5Clickbeetles / wireworms18Pea weevil
6Crucifer flea beetle19Predators
7Cutworms20Rose grain aphid
8Diamondback moth21Russian wheat aphid
9English grain aphid22Stink bug
10Greenbug23Striped flea beetle
11Green peach aphid24Turnip aphid
12Hessian fly25Wheathead 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)

python
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)

python
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

python
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

python
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:

ModelGPUEpochs CompletedWall TimeBest Checkpoint Epoch
EfficientNet-B6NVIDIA RTX 3090 (24 GB)10~5h 47m1
InceptionV3NVIDIA RTX 4090 (24 GB)51~6h 02m4
MobileNetV3-LargeNVIDIA RTX 4090 (24 GB)79~6h 04m5

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

[image]

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:

ModelStarting LRFinal LRLR Reductions
EfficientNet-B61e-49e-51
InceptionV31e-44.8e-58
MobileNetV3-Large1e-42.8e-513

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_herbivores class 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](https://www.uidaho.edu/cals/entomology-plant-pathology-and-nematology/our-people/sanford-eigenbrode) - Distinguished Professor, Entomology, Plant Pathology, and Nematology, University of Idaho (PI)
  • —[Arash Rashed](https://www.arec.vaes.vt.edu/arec/southern-piedmont/people/arash-rashed.html) - Virginia Tech Southern Piedmont Agricultural Research and Extension Center
  • —[Marek Borowiec](https://agsci.colostate.edu/directory/bio/?user=1189) - Assistant Professor, Insect Systematist, Director of C. P. Gillette Museum, Colorado State University
  • —[Subodh Adhikari](https://extension.usu.edu/directory/adhikari-subodh) - Assistant Professor, Entomology Extension Specialist, Utah State University
  • —[Luke Sheneman](https://hpc.uidaho.edu) - Director of Research Computing, University of Idaho
  • —[Jennifer Hinds](https://hpc.uidaho.edu) - Research Applications Architect, University of Idaho
  • —[John Brunsfeld](https://hpc.uidaho.edu) - Senior Full Stack Developer, University of Idaho

Citation

bibtex
@misc{sheneman2025cerealpestaid,
  author = {Sheneman, Luke},
  title = {CerealPestAID: Deep Learning Models for Cereal Pest Identification},
  year = {2025},
  publisher = {HuggingFace},
  url = {https://huggingface.co/sheneman/CerealPestAID}
}