Abstract
We present a machine vision-based database named GrainSet for the purpose of visual quality inspection of grain kernels. The database contains more than 350K single-kernel images with experts' annotations. The grain kernels used in the study consist of four types of cereal grains including wheat, maize, sorghum and rice, and were collected from over 20 regions in 5 countries. The surface information of each kernel is captured by our custom-built device equipped with high-resolution optic sensor units, and corresponding sampling information and annotations include collection location and time, morphology, physical size, weight, and Damage & Unsound grain categories provided by senior inspectors. In addition, we employed a commonly used deep learning model to provide classification results as a benchmark. We believe that our GrainSet will facilitate future research in fields such as assisting inspectors in grain quality inspections, providing guidance for grain storage and trade, and contributing to applications of smart agriculture.
Introduction
Ensuring the quality of cereal grains is a cornerstone of global food safety and trade. Currently, this relies heavily on Grain Appearance Inspection (GAI), where human inspectors manually examine samples for defects like mold, insect damage, or broken kernels. This process is labor-intensive, subjective, and prone to inconsistency between inspectors of different experience levels. While machine learning offers a potential solution, existing datasets are often limited in scale, species variety, or lack the high-quality expert labels required for reliable model training. GrainSet addresses these gaps by providing a large-scale, multi-species, and expertly annotated benchmark for automated grain quality inspection.
Methodology
Custom Hardware and Dual-View Imaging
A central innovation of this work is the development of a custom imaging prototype. Unlike traditional single-view systems, this device captures both UP and DOWN images of each kernel simultaneously using a transparent plate. This dual-view capability is critical because many grain defects are localized; capturing both sides significantly reduces the "false normal" rate that occurs when defects are hidden on the underside of a kernel.
Data Collection and Annotation Pipeline
The researchers implemented a rigorous multi-stage pipeline to ensure data quality and expert-level ground truth:
- Sample Collection: Grains were sampled from trucks and subjected to multiple filtering stages—including wide-mesh sieves, fine-mesh sieves, and high-power fans—to remove impurities before being stored in optimal conditions.
- Pre-processing: Inspectors manually sorted grains into eight categories: Normal, six types of Damage/Unsound (e.g., moldy, broken, sprouted), and Impurities. These were then batched by precise physical weight at 1mg intervals.
- Post-processing: Every kernel in the high-resolution images was manually localized with polygon boxes. Inspectors then paired the UP and DOWN views to create a complete visual profile for each kernel.
The GrainSet Dataset
GrainSet is composed of four primary sub-datasets, totaling over 350,000 images:
- Wheat: 200,000 images (sourced from China, Canada, Australia, and the USA).
- Maize: 19,000 images.
- Sorghum: 102,700 images.
- Rice: 31,000 images.
To facilitate different research needs, the authors also provided GrainSet-tiny (a 2% preview) and GrainSet-raw (5% of uncropped images) to provide context for the acquisition process.
Technical Validation and Results
To validate the dataset, a benchmark model was trained using a ResNet-50 backbone enhanced with a Squeeze-and-Excitation (SE) attention module. This architecture allows the model to focus on discriminative regions, such as small fungal discolorations or tiny insect holes.
- High Accuracy: The models achieved average F1-scores exceeding 94% across all four grain types, with wheat reaching a near-perfect 99.9%.
- Feature Discriminability: t-SNE visualizations confirmed that different damage categories formed distinct clusters in the model's feature space, demonstrating the dataset's high quality and discriminative power.
- Interpretability: Grad-CAM visualizations confirmed that the models correctly focused on relevant morphological features rather than background noise.
Conclusion
While GrainSet represents a significant advancement, limitations remain. Approximately 2% of the surface area remains uncaptured due to kernel geometry, and extreme class imbalance reflects the rarity of certain defects in specific regions. Future work will focus on expanding the variety of grain species and regional samples to improve global generalizability. GrainSet provides a robust foundation for the development of objective, automated inspection tools in smart agriculture.
Reference: Fan, L., et al. (2023). An annotated grain kernel image database for visual quality inspection. Scientific Data. https://doi.org/10.1038/s41597-023-02660-8
Summary updated