Integrating AI into green coffee bean quality control models? Decoding the 99% figure of the YOLOv8 model
In a batch of green coffee beans, some defects are easily recognizable: black beans, broken beans, deformed beans, or remaining fruit pulp fragments. However, there are also minor defects that inspectors can only detect by examining each bean individually under good lighting conditions.
As raw material volumes increase to tons, visual inspection becomes time-consuming and dependent on the sorter's experience. This is one of the reasons computer vision has begun to be studied as a tool to support green coffee bean quality control.
In 2024, a study using an improved YOLOv8 model reported a mAP of 99% in the task of detecting and classifying green coffee beans. This figure is impressive, but it is essential to understand exactly what it measures before considering the integration of AI into production lines.
From human inspection to computer vision systems
Traditional green coffee bean classification uses various methods. Mechanical sieves sort by size; specific gravity separators help remove groups of beans with different densities; inspectors check color and shape to detect defective beans.
Each method addresses a specific set of characteristics. Size sieving cannot identify all color defects. Density separators do not necessarily detect small discolorations. Manual inspection can vary depending on lighting, working hours, and the inspector's experience.
Computer vision approaches the problem differently: cameras capture images of individual beans, and algorithms analyze color, contours, shape, and other visual features to determine location and defect category.
Instead of merely indicating bean size, the model can identify where an object is located within the frame and classify it as normal, black, or broken.
How was the 2024 YOLOv8 study conducted?
In a study by Ji, Xu, and Yan, published on 01/11/2024 in Journal of Food Processing and Preservation, the authors developed a green coffee bean recognition system based on YOLOv8n.
The raw material used was the Catimor variety grown in Yunnan, China. The research team captured images in an environment simulating a production line, using industrial cameras with a resolution of 4,000 × 3,000 pixels.
The recognition system was built to distinguish object groups based on appearance. Data were labeled into four categories in the model: normal beans, black beans, broken beans, and a group named "cherry" by the authors.
To improve the detection of small objects, the research team adjusted the YOLOv8n model using two main components:
- WIoUv3: A loss function that helps improve object localization by adjusting learning weights based on sample characteristics.
- Atn-C3Ghost: A structure combining the ECA channel attention mechanism with C3Ghost, aiming to enhance feature extraction while controlling the number of model parameters.
This approach is significant for green coffee bean analysis because coffee beans often occupy a small area in images, may be positioned close together, and defect signs sometimes differ only in slight variations of color or contour.
99% does not mean the machine correctly classifies 99% of every coffee batch
The most notable result of the study was that the Atn-YOLOv8n model achieved a mAP@0.5 of 99.0%. This is the mean Average Precision metric at an IoU threshold of 0.5, reflecting object detection and classification performance on the test dataset.
In the same results table, the authors noted:
| Metric | Result |
|---|---|
| Precision | 96,8% |
| Recall | 97,6% |
| mAP@0.5 | 99,0% |
| mAP@0.5:0.95 | 80,5% |
| Number of model parameters | 2.0 million |
It is important to note that mAP@0.5 and mAP@0.5:0.95 are not the same metric. At an IoU threshold of 0.5, the requirement for overlap between the predicted region and the ground-truth object region is lower than when evaluating across multiple IoU thresholds from 0.5 to 0.95.
Therefore, a 99% result should not be interpreted as a claim that the machine will accurately classify 99% of all green coffee beans in every factory. This result applies to a specific task, dataset, and testing condition.
Training data determines defect detection capability
The study used images of Catimor coffee in a simulated production line environment. This facilitates lighting control and initial dataset construction, but also raises questions about applicability when raw materials change.
Actual green coffee can vary significantly in:
- Coffee variety and species: Arabica, Robusta, or other material groups.
- Processing methods: Natural, Washed, Honey, and process variations.
- Natural color, surface uniformity, and variation levels after storage.
- Moisture content, size, shape, and degree of damage.
- Lighting conditions, camera angle, conveyor speed, and bean density on the imaging background.
The authors themselves acknowledge that the model still faces challenges when processing coffee samples with diverse sizes, shapes, and colors. Data limitations may affect generalization ability, while a more complex model structure also increases computational resource requirements.
This highlights the difference between laboratory results and operational efficiency. A model may achieve high metrics on controlled images, but it still needs to be tested on new batches of coffee from various growing regions and harvests.
Comparison with another research direction: SVM on 2,873 Arabica beans
In 2022, Zhao et al. published a study on Arabica defect recognition by combining image features with the Support Vector Machine (SVM) algorithm.
The research team used 2,873 Arabica beans, including 1,500 normal beans and 1,373 defective beans across 11 categories. The system extracted 19 features from three information groups: contour, texture, and color.
The SVM model using a combination of all three feature groups achieved the following results:
| Metric | Result |
|---|---|
| Accuracy | 84,9% |
| Precision | 85,8% |
| Recall | 82,3% |
| F1-score | 84,0% |
It is inappropriate to directly compare the 84.9% SVM result with the 99.0% mAP of YOLOv8 and conclude that the latter model is better by a fixed margin. The two studies differ in data, labeling methods, number of defect categories, prediction tasks, and evaluation metrics.
A notable commonality is that both demonstrate that images contain more information than a single feature. Combining color, shape, and texture can improve defect identification compared to relying on a single indicator.
Can AI completely replace green coffee quality inspection?
The current answer is no. Computer vision is suitable for defects observable on the surface or in bean shape. However, not all quality issues are clearly evident in standard RGB images.
A bean may appear normal but still have issues with moisture content, chemical changes, or internal quality. Color cameras cannot fully determine parameters such as water activity, chemical composition, mycotoxin risk, or post-roast cupping quality.
Therefore, a reasonable quality control system should combine multiple layers of inspection:
- Computer vision: Identifies visual defects, color, shape, and foreign objects.
- Size grading and density sorting: Separates bean groups based on appropriate physical characteristics.
- Moisture and water activity meters: Monitors parameters related to storage stability.
- Spectral analysis when necessary: Provides chemical information that standard images cannot fully reveal.
- Cupping and professional evaluation: Verifies the final quality of the batch after roasting and brewing.
For exporting businesses or processing mills, the practical benefit of AI is not necessarily removing humans from the production line. Greater value lies in continuous inspection, reducing variability between shifts, recording defect data, and supporting root cause analysis when batch quality changes.
To deploy a model into operation, it must be tested on independent data from each raw material source, measuring defect miss rates, false rejection rates of good beans, and performance at increased conveyor speeds. A high mAP score is a starting point for evaluation, not a certification for the entire production line.
In green coffee quality control, computers can help human eyes work faster and more consistently. However, quality decisions must still rely on a system of physical, chemical, and sensory standards appropriate to the intended use of the coffee beans.
For more knowledge on green coffee and the production chain, visit SAVINA Coffee Knowledge.
References
- Ji, Y., Xu, J. & Yan, B. (2024). Coffee Green Bean Defect Detection Method Based on an Improved YOLOv8 Model. Journal of Food Processing and Preservation. https://doi.org/10.1155/2024/2864052
- Zhao, Y. et al. (2022). Detection of defective Arabica green coffee beans based on feature combination and SVM. Transactions of the Chinese Society of Agricultural Engineering, 38(14), 295–302. https://doi.org/10.11975/j.issn.1002-6819.2022.14.033
- Belay, A. et al. (2014). Discrimination of Defective (Full Black, Full Sour and Immature) and Nondefective Coffee Beans by Their Physical Properties. Journal of Food Process Engineering, 37, 524–532. https://doi.org/10.1111/jfpe.12113
