In the fast-paced world of raspberry packing facilities, real-time classification of thousands of small moving fruits poses a significant challenge. Each individual raspberry, often just a few dozen pixels in size, requires careful evaluation to ensure quality and minimize waste.
The difficulties are compounded by issues such as occlusions within transparent trays, subtle color variations across ripening stages, and a stark class imbalance, with defective or "discard" fruits making up less than 3% of the total harvest. Until recently, the industry lacked a public, pixel-level dataset necessary to train and validate segmentation models under real operating conditions.
A recent and innovative publication by Mohamed Lamine Mekhalfi, Paul Chippendale, Fabio Poiesi, Samuele Bonecher, Gilberto Osler, and Nicola Zancanella demonstrated a groundbreaking approach to overcoming these complexities, opening new perspectives for automation in the berry supply chain.
The Technological Core: the “RaspGrade” Methodology
To tackle the challenge, the authors developed RaspGrade, a pioneering dataset. They photographed 200 raspberry trays (totaling 5,243 fruits) sourced from supermarkets using an Intel RealSense D456 camera and uniform LED lighting, in a setup faithfully replicating conveyor belt conditions.
Pixel-accurate masks were then manually created and ripeness labels were assigned on five distinct levels using the CVAT tool. 80% of the dataset was allocated for training, and the remaining 20% for validation.
The images were resized to 1280 × 800 pixels, and a lightweight instance segmentation model, YOLOv8-n-seg, was trained for 100 epochs with a batch size of 2. The goal was to achieve 30 frames per second (FPS) on an edge computing GPU, thereby meeting industrial real-time requirements.
Three loss function engineering variants were explored to optimize performance:
- (i) a Binary Cross-Entropy (BCE) baseline;
- (ii) a 10x higher weight assigned to the rare “Reject” class (Grade 5) to improve detection;
- (iii) maintaining the weight for Grade 5 with the addition of a robust global classification term (λ_cls = 7), or alternatively, increasing weights for both Grade 4 and Grade 5.
Performance was evaluated using metrics such as precision, recall, and mean Average Precision (mAP_50 and mAP_50-95), both for bounding boxes and segmentation masks.
Key Results: Accuracy, Speed, and Economic Impact
The results of this study are remarkable and promising for the berry industry:
- The best-performing YOLOv8-n-seg model achieved an impressive mAP of 65.5% for masks (mAP@50) across all five raspberry ripeness grades, operating at 30 FPS. This performance is critical for industry.
- Model performance varied across grades: it excelled with Grade 2 raspberries, reaching a mAP of 91.0%, but struggled most with Grade 5 ("Reject"), achieving a mAP of just 23.7%. This reflects the severe imbalance in the dataset.
- Re-weighting the loss function for underrepresented classes proved highly effective. The mAP for Grade 5 more than doubled, from 9.3% to 23.7%. Although this optimization slightly decreased performance on mid-range grades, the gain was essential.
- Tray detection accuracy was nearly perfect, reaching a 99.5% mAP. This enables reliable tray-level analysis and closed-loop sorting systems.
- The system is ready for industrial integration. Its ability to deliver coordinates and grades quickly allows for the use of pick-and-place robots to remove unsuitable fruits. Estimated labor savings are around €30,000 per year per packing line.
Towards a Future of Quality and Efficiency for European Berries
The findings of this pioneering study on raspberries demonstrate the transformative potential of Artificial Intelligence in the berry industry. The ability to classify delicate fruits in real time, with high precision and full automation, not only enhances final product quality but also delivers significant economic benefits to packing companies.
For Italian and European berry producers and exporters, where quality and efficiency are key competitiveness factors, these innovations represent a major step forward. Optimizing sorting processes and reducing waste can lead to greater sustainability and profitability.
Companies like Petiole Pro, already offering AI-based solutions for counting and analyzing blueberries and strawberries, confirm the direction of modern agriculture: smarter, more precise, and equipped to tackle the challenges of large-scale production.
While this research focuses on raspberries, the methodology and findings pave the way for similar systems for other delicate fruits, including additional berry types, ensuring that only the best reaches our tables.