Multi-module fusion target detection system for automatic grading of green coffee beans
By improving the YOLOv8 architecture and combining it with multi-module fusion target detection technology, the problems of low efficiency and insufficient accuracy in coffee bean grading have been solved, achieving high-precision, real-time automatic grading results, which are suitable for edge computing devices.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-29
- Publication Date
- 2026-04-03
AI Technical Summary
Existing methods for grading green coffee beans rely on manual labor or traditional machinery, which are inefficient, lack the ability to identify subtle texture features, and the general YOLO model is difficult to achieve real-time high-precision grading on edge devices, especially in scenarios with multi-target occlusion and class imbalance.
Design a multi-module fusion object detection system, including improving the YOLOv8 architecture, introducing MogaBlock, ScConv, MFM, SimAM and LQE modules, and combining Fusion Loss to optimize feature extraction and localization quality, adapt to dense multi-bean scenes and solve class imbalance.
It achieves high-precision automatic grading of Yunnan small-bean coffee beans, with an average accuracy of 98.5% and a recall rate of 97.3%. It significantly reduces model parameters and computational complexity, making it suitable for edge computing devices and meeting the real-time needs of industrial production lines.
Smart Images

Figure CN121788801A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer vision, pattern recognition, deep learning, and intelligent detection technology for agricultural products, specifically to a multi-module fusion target detection system for automatic grading of green coffee beans. Background Technology
[0002] Coffee is the world's second-largest commodity by trade volume, after oil, and its industrial chain covers planting, primary processing, advanced processing, and consumption. Yunnan Province in China is a major coffee-producing region, accounting for over 98% of the country's Arabica coffee production. With the rise of specialty coffee, the market's requirements for the quality of green coffee beans are becoming increasingly stringent. The quality of green beans depends not only on conventional physical indicators such as bean size, color, and moisture content, but also on the amount of silverskin residue and minor surface defects (such as insect infestation, breakage, and moldy black beans).
[0003] Silverskin is a thin film adhering to the surface of coffee beans, rich in chlorogenic acid, cellulose, and their derivatives. During roasting, silverskin undergoes the Maillard reaction and caramelization. Excessive silverskin residue leads to uneven roasting, producing a burnt, bitter, and astringent taste, severely impacting the flavor profile and cleanliness of the coffee. Therefore, accurately detecting and removing green beans with excessive silverskin residue is a crucial step in producing high-quality specialty coffee. Existing SCA (Specialty Coffee Association) standards and related enterprise standards all have strict regulations regarding the defect rate of green beans.
[0004] Currently, the grading of green coffee beans mainly relies on manual selection or traditional mechanical sieving (by particle size) and color sorting (by color). Manual grading suffers from problems such as high subjectivity, low efficiency, and a high rate of missed detection due to eye fatigue; traditional mechanical sieving cannot identify surface texture defects; although color sorting machines can remove discolored beans (such as black beans), their ability to identify subtle texture features such as silverskin residue (the silverskin color is similar to the bean color and is distributed in a mottled pattern) is limited, making it difficult to achieve refined grading based on silverskin coverage (such as distinguishing between grade 1 and grade 2 beans).
[0005] In recent years, deep learning technology has made significant progress in the field of agricultural product testing. Convolutional Neural Network (CNN)-based methods have demonstrated excellent performance in feature extraction. The YOLO (You Only Look Once) series of algorithms, due to their fast end-to-end detection speed and high accuracy, has become the preferred choice for industrial testing. However, directly applying general YOLO models (such as YOLOv5 and YOLOv8) to the grading of Yunnan small-bean coffee still faces the following serious challenges:
[0006] (1) Difficulty in extracting fine-grained features: The main difference between normal beans of different grades (grade 1, grade 2, grade 3) lies in the coverage of silver skin (e.g., <10%, 10%-20%, >20%). The texture of the silver skin is fine and irregular, and has low contrast with the background of the bean body. After multiple downsampling by deep networks, these fine-grained texture features are easily lost, leading to grade confusion.
[0007] (2) Dense Occlusion of Multiple Targets: On industrial conveyor belts, coffee beans typically pass through the camera's field of view in a high-density flow, resulting in severe overlap and occlusion between beans. When dealing with dense small targets, the general YOLO model is prone to missed detections or bounding box drift, making it difficult to accurately count and classify them.
[0008] (3) The contradiction between lightweight model and real-time performance: In order to improve detection accuracy, it is often necessary to deepen the number of network layers or increase the number of channels, which leads to a surge in the number of model parameters and floating-point operations (FLOPs), making it difficult to achieve real-time inference (FPS > 100) on edge devices with limited computing power (such as embedded industrial control computers and Jetson series).
[0009] (4) Severe class imbalance: In actual production, high-quality beans account for the majority, while defective samples such as black beans and severely damaged beans are extremely rare. This long-tailed distribution causes the model to tend to optimize the majority class during training, while its ability to identify a few key defect categories is insufficient.
[0010] Therefore, in order to solve the above problems, this paper proposes a multi-module fusion target detection system for automatic grading of green coffee beans. Summary of the Invention
[0011] The purpose of this invention is to design a multi-module fusion target detection system for automatic grading of green coffee beans, which can accurately identify minute surface defects of green coffee beans (especially silverskin residue) and adapt to dense multi-bean scenarios. Based on YOLOv8n, this system introduces MogaBlock to enhance fine-grained features, ScConv to suppress redundant calculations, MFM to optimize multi-scale fusion, SimAM to enhance attention, and LQE to optimize localization quality, and uses Fusion Loss to solve class imbalance.
[0012] To achieve the above-mentioned technical effects, the present invention is implemented through the following technical solution: a multi-module fusion target detection system for automatic grading of green coffee beans, characterized by comprising the following steps:
[0013] S1. Construct a Yunnan small-bean green coffee bean grading standard dataset with multi-scale and fine-grained features: Collect images of green coffee beans of different grades and defect categories, including Grade 1 normal beans, Grade 2 normal beans, Grade 3 normal beans, black beans, and damaged beans; Perform multi-stage preprocessing on the collected images, including grayscale processing, bilateral filtering for noise reduction, Canny edge detection, and outer contour extraction, to accurately separate the bean body from the background and quantify the extraction of silver skin region features; Expand the dataset using a hybrid data augmentation strategy, including geometric transformation and noise introduction for single beans, and geometric transformation and multi-image stitching enhancement for multi-bean scenarios; Divide the dataset into training set, validation set, and test set according to a preset ratio;
[0014] S2. Construct a lightweight multi-module fusion object detection model MFASL-ListV8 based on the improved YOLOv8 architecture: This model is based on the YOLOv8n architecture and introduces customized specific extraction and fusion modules in specific layers of the backbone network and the neck network respectively.
[0015] S3. In the mid-to-high-level semantic feature extraction stage of the backbone network and neck network, a C2f-MogaBlock module is designed and implanted: The C2f-MogaBlock module retains the parallel branch topology of C2f, replaces the bottleneck unit (Bottleneck) with the multi-level gated aggregation unit (MogaBlock), uses multi-scale dilated convolution and gating mechanism for spatial aggregation, and uses depthwise separable convolution for channel aggregation, so as to enhance the representation ability of fine-grained texture features such as silver skin residue and tiny broken edges on the surface of coffee beans;
[0016] S4. In the shallow and low-level feature extraction stages of the backbone network and neck network, a C2f-ScConv module is designed and implanted. Three cascaded self-calibrating convolutional units (Bottleneck_ScConv) are integrated in the parallel branch of C2f. Spatial redundancy features are suppressed by the spatial recalibration unit (SRU) and the interaction between channels is optimized by the channel redistribution unit (CRU) to reduce computational complexity and retain key geometric contour information.
[0017] S5. In the multi-scale feature fusion node of the neck network, design and implant a multi-feature mixer (MFM) module to replace the original concat operation; the MFM module generates dynamic weights through global context modeling and performs adaptive weighted fusion of feature branches from different scales to solve the feature aliasing and missed detection problems of small targets and occluded targets in scenarios with multiple overlapping and dense distribution.
[0018] S6. At the end feature output position of the backbone network, embed the parameterless attention mechanism SimAM; the SimAM module directly calculates the attention weight of each neuron in the feature map based on the energy function, enhances the model's attention to the differences between the bean body and the background, and between the silver skin and the smooth surface, without adding additional model parameters.
[0019] S7. Construct a Detect_LQE detection head that includes a localization quality estimation branch; Based on the original classification and regression branches, introduce an LQE branch with shared convolutional features to predict the IoU value between the predicted box and the ground truth box, which is used to calibrate the classification confidence during the inference stage and improve the bounding box regression accuracy and localization quality.
[0020] S8. Define a composite loss function, Fusion Loss, for class imbalance and difficult-to-classify samples; combine FocalLoss and Cross-Entropy Loss, and adjust the weight coefficients to balance the learning ratio of positive and negative samples and easy and difficult samples, thereby optimizing the model's classification performance for minority class defective beans (black beans, broken beans) and critical grade beans.
[0021] S9. The constructed MFASL-LiteV8 model is trained end-to-end using the training set. The model parameters are iteratively updated using a stochastic gradient descent (SGD) optimizer until the loss function converges to obtain the optimal detection model. The model is then deployed on edge computing devices or embedded terminals for real-time hierarchical detection.
[0022] Furthermore, in S1, during the dataset annotation stage, the grading standard for green coffee beans integrates both physical particle size and silverskin coverage. The specific quantitative standards are as follows: Grade 1 normal beans have a particle size greater than 6.30 mm and a silverskin coverage of less than 10%; Grade 2 normal beans have a particle size greater than 5.6 mm and a silverskin coverage of 10%-20%; Grade 3 normal beans have a particle size greater than 4.75 mm and a silverskin coverage of greater than 20%. Defective beans include black beans with moldy, grayish-black surfaces and broken beans with incomplete shapes or obvious cracks.
[0023] Furthermore, in S1, the data preprocessing specifically includes: setting the grayscale contrast to 0.9 for grayscale conversion; using bilateral filtering with a diameter d=4, color space standard deviation sigmaColor=15, and coordinate space standard deviation sigmaSpace=15; setting a low threshold of 50 and a high threshold of 150 for Canny edge detection; and binarization color inversion and outer contour extraction.
[0024] Furthermore, in S1, the dataset is expanded using a hybrid data augmentation strategy as follows:
[0025] Basic enhancements: horizontal / vertical flipping and rotation to simulate the random posture of beans on a conveyor belt;
[0026] Noise enhancement: Salt-and-pepper noise and Gaussian noise to simulate sensor noise and dust interference in industrial cameras;
[0027] Occlusion enhancement: Random occlusion simulates mutual occlusion between beans;
[0028] Hybrid Enhancement: Mosaic four-image stitching simulates a "high-density occlusion" scene by randomly scaling, cropping, and arranging four images. This significantly increases the number of targets and background complexity in a single image, improving the model's ability to detect small targets and its robustness to BN layers.
[0029] Furthermore, in S3, the specific structural configuration of the C2f-MogaBlock module is as follows: based on the C2f module architecture of YOLOv8, the number of input channels is compressed through a pre-convolution of 1x1, and the feature map is divided into two branches along the channel dimension, one of which passes through... One branch is processed by a series of MogaBlock units, and another branch is connected via a shortcut. Finally, the output is fused with a 1x1 convolution through concatenation. The spatial aggregation stage of the MogaBlock unit includes: extracting features using multi-scale dilated convolutions with kernel sizes of 3x3, 5x5, and 7x7, and performing gated aggregation through channel segmentation and non-linear activation. The C2f-MogaBlock module is specifically deployed in the high-level stage of the MFASL-LiteV8 network architecture to specifically enhance the texture details in the mid-to-high-level semantics.
[0030] Furthermore, in S4, the specific structural configuration of the C2f-ScConv module is as follows: In the architecture of the C2f module, the main branch contains three cascaded Bottleneck_ScConv units; the core of each Bottleneck_ScConv unit is a self-calibrating convolution (ScConv), which contains parallel SRU and CRU; the SRU first performs group normalization on the input features, uses the Sigmoid function to generate gate weights, separates the features into informative features and redundant features, and only reconstructs the informative features; the CRU uses a "segmentation-transformation-fusion" strategy to extract features through the 1x1 convolution of the upper branch and the 3x3 convolution of the lower branch, and then fuses them through Softmax weighted fusion; the C2f-ScConv module is specifically deployed in the low-level stage of the network architecture to maximize the compression of redundant computation in shallow networks while maintaining accuracy.
[0031] Furthermore, in S5, the fusion calculation process of the MFM module specifically includes:
[0032] S5.1 Input Projection: Let the input feature branch be... Apply a 1x1 convolution to each branch to uniformly adjust its channel count. ;
[0033] S5.2 Feature Stacking: The adjusted feature maps are stacked along the channel dimension to form a combined feature map. ;
[0034] S5.3, Weight Generation: For Global average pooling is performed, and normalized attention weight vectors for each branch are generated through two fully connected layers (MLP) and a softmax activation function. ;
[0035] S5.4 Weighted Fusion: The input branch is summed element-by-element using the weights mentioned above. The calculation formula is as follows: The fused feature map is output; the MFM module is deployed at all nodes in the neck network where multi-scale feature convergence occurs, replacing the original Concat operation.
[0036] Furthermore, in S6, the energy function of the SimAM attention mechanism The formula for calculating its weight is as follows:
[0037] For the input feature map For each channel in the algorithm, calculate the location of each neuron. energy value :
[0038]
[0039] in, For the target neuron, For other neurons, and This represents the objective value of the corresponding linear transformation; minimizing this energy function yields the analytical weights for each neuron.
[0040]
[0041] In the formula, and These represent the mean and variance of all neurons within the channel, respectively. Here is the regularization coefficient; the final output feature map is... ,in For all The energy matrix formed This indicates element-wise multiplication; the SimAM module is embedded after the SPPF module in the 9th layer of the backbone network, serving as an enhancement step before the features enter the neck network.
[0042] Furthermore, in S7, the workflow of the Detect_LQE detection head is as follows:
[0043] S7.1 Feature Decoupling: The feature maps output by the neck network are fed into the classification branch (Cls Branch) and the regression branch (Reg Branch) respectively.
[0044] S7.2, LQE branch embedding: After the convolutional layer of the regression branch, a parallel LQE branch is introduced. This branch consists of a 1x1 convolutional layer with an output dimension of 1. After Sigmoid activation, it represents the IoU estimate between the predicted box and the ground truth box.
[0045] S7.3 Inference Calibration: During the inference phase, the final confidence score... The calculation formula is:
[0046]
[0047] In the formula, The output of the classification branch is the class probability. The positioning quality score output by the LQE branch. This is the balance coefficient;
[0048] S7.4, Non-maximum suppression (NMS): Using calibrated... When performing NMS operations, prioritize retaining the detection bounding boxes with more accurate positioning.
[0049] Furthermore, in S8, Fusion Loss ( The specific mathematical expression of ) is:
[0050]
[0051] In the formula, This represents the model's predicted probability for the target category. To balance the adjustment factors for positive and negative samples; This is the focusing parameter for Focal Loss, used to reduce the weight of easily classified samples; One-hot encoding for the true category label, For the first Predicted probability of the category; and These are the weight coefficients of the Focal Loss and Cross-Entropy Loss terms, respectively. Through joint optimization, the model can converge quickly in the early stage of training by utilizing cross-entropy, and in the later stage, Focal Loss can be used to tackle difficult samples such as black beans and broken beans.
[0052] Another object of the present invention is to provide an apparatus for an automatic grading system for green coffee beans using a multi-module fusion target detection system, characterized in that the apparatus comprises:
[0053] Image acquisition unit: used to acquire RGB images of green coffee beans on an industrial conveyor belt, equipped with an LED ring light source and a diffuse reflection backplate;
[0054] Edge computing unit: It has a built-in trained MFASL-LiteV8 model to receive images and output the category label (level 1, level 2, level 3, black bean, damaged bean) and location coordinates of each coffee bean in real time;
[0055] Hierarchical execution unit: Based on the coordinates and category instructions output by the edge computing unit, it controls the pneumatic nozzles or mechanical paddles to divert different types of coffee beans to the corresponding feed troughs; the edge computing unit uses TensorRT or ONNXRuntime inference engines to accelerate the deployment of the MFASL-LiteV8 model.
[0056] Another object of the present invention is to provide a computer-readable storage medium storing a multi-module fusion target detection system for automatic grading of green coffee beans, characterized in that it stores a computer program thereon, which, when executed by a processor, implements the steps of the multi-module fusion target detection system for automatic grading of green coffee beans.
[0057] The beneficial effects of this invention are:
[0058] On a self-built Yunnan small-bean green coffee bean dataset, the MFASL-LiteV8 model achieved an average precision of 98.5%, a 3.2 percentage point improvement over the baseline YOLOv8n model. Precision reached 97.3%, and recall reached 97.5%, representing improvements of 4.7% and 2.2% respectively. It demonstrated extremely high discriminative power in fine-grained classification of first, second, and third-grade beans, effectively solving the problem of difficulty in recognizing fine-grained silver skin features. By introducing lightweight modules such as ScConv, the model's parameter count was reduced to 2.602M (a 13% reduction compared to the baseline), and floating-point operations were reduced to 501.9G (a 5% reduction). While maintaining high precision, this significantly reduced hardware computing power requirements, making it suitable for deployment on edge computing devices. Inference speeds exceeding 100 FPS on a single RTX 4090 GPU fully meet the high-speed grading requirements of industrial production lines.
[0059] Thanks to the MFM and SimAM modules, the model can maintain stable detection performance even in complex environments such as multiple overlapping beans, occlusion, and changes in lighting. The false negative rate and false positive rate are significantly lower than those of traditional models. At the same time, based on the improved YOLOv8 architecture, it supports the export of mainstream inference engines such as ONNX and TensorRT, and can be seamlessly deployed on edge computing devices such as Jetson Orin and Raspberry Pi, reducing the hardware cost of hierarchical devices. Attached Figure Description
[0060] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0061] Figure 1 This is a flowchart of a multi-module fusion target detection system for automatic grading of green coffee beans according to the present invention;
[0062] Figure 2 This is a schematic diagram of the C2f-MogaBlock module in this invention;
[0063] Figure 3 This is a detailed structural diagram of the MogaBlock unit in this invention;
[0064] Figure 4 This is a schematic diagram of the C2f-ScConv module in this invention;
[0065] Figure 5 This is a structural diagram of the MFM (Multi-Feature Mixer) feature fusion module in this invention;
[0066] Figure 6 This is a schematic diagram of the energy function calculation and three-dimensional weight generation of the SimAM parameterless attention mechanism in this invention;
[0067] Figure 7 This is a structural diagram of the Detect_LQE detection head in this invention;
[0068] Figure 8 These are morphological examples of different grades of Yunnan small-bean coffee beans in embodiments of the present invention;
[0069] Figure 9 This is a schematic diagram of a data-enhanced sample in an embodiment of the present invention;
[0070] Figure 10This is a comparison chart of the loss variation curves of the system of this invention and mainstream models such as YOLOv5n, YOLOv8n, and Faster R-CNN on the test set;
[0071] Figure 11 This is a comparison chart of the accuracy change curves of the system of this invention and mainstream models such as YOLOv5n, YOLOv8n, and Faster R-CNN on the test set;
[0072] Figure 12 This is a visualization of the detection results of the system of the present invention in a densely mixed scene;
[0073] Figure 13 This is a flowchart of a multi-module fusion target detection system for automatic grading of green coffee beans, as described in this invention. Detailed Implementation
[0074] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0075] Example 1
[0076] A multi-module fusion target detection system (MFASL-LiteV8) for automatic grading of green coffee beans includes the following steps:
[0077] Step 1: Construction and Augmentation of the Yunnan Small-Grain Coffee Bean Dataset
[0078] 1. Sample Collection and Standard Definition: The samples were obtained from a coffee company in Yunnan Province. Based on the SCA standard and the company's internal control standards, green coffee beans were divided into the following five categories, as follows:
[0079] First Level: High-quality beans, with a diameter > 6.30mm, light blue / light green / light brown color, round shape, and silver skin coverage < 10%.
[0080] Second Level: Medium-quality beans, with a diameter > 5.6mm and a silver skin coverage of 10%-20%.
[0081] Third Level: Low-quality beans, with a diameter > 4.75mm and silver skin coverage > 20%.
[0082] Black beans: Surface mold and grayish-black color are serious defects.
[0083] Damaged beans: The shape is incomplete, with obvious gaps or cracks.
[0084] It is important to note that the model predicts the grade category of beans directly by learning from a large number of samples with silver labels, without needing to explicitly calculate the coverage during the inference stage.
[0085] 2. The data acquisition equipment uses an industrial-grade CMOS camera (model: Xin Sitong AF 1600) equipped with a high-definition fixed-focus lens; the shooting distance is fixed at 200mm, and a white diffuser with high reflectivity (≥95%) is used as the background to maximize the contrast between the bean and the background. The light source uses a ring light source composed of 4 high color rendering LEDs to simulate midday natural light (color temperature 5500K) to ensure uniform lighting without shadows. Camera parameter settings: ISO 100, shutter speed 1 / 100s, automatic white balance;
[0086] A total of 1454 original images were collected, including:
[0087] Single-bean images: Normal beans (Grade 1: 216 images, Grade 2: 166 images, Grade 3: 270 images), Defective beans (242 images, Black beans: 222 images);
[0088] Multi-grain mixed images: 338 images, simulating actual production line scenarios, divided into three densities: sparse distribution (4-6 grains), uniform distribution (~10 grains), and dense stacking (~20 grains);
[0089] 3. Image Preprocessing Workflow: To assist in manual annotation and extraction of silver skin features, a series of preprocessing steps were performed on the original image (such as...). Figure 2 (as shown)
[0090] Step A: Grayscale conversion: Convert the RGB image to a grayscale image and adjust the grayscale contrast to 0.9 to enhance the dynamic range of the image;
[0091] Step B: Bilateral filtering: Parameters set to... , Bilateral filtering can effectively preserve the edge information of the bean while removing high-frequency noise from the sensor, preventing edge blurring.
[0092] Step C: Canny edge detection: Set a low threshold of 50 and a high threshold of 150 to extract the edge gradient map of the bean body and silver skin texture;
[0093] Step D: Binarization and Morphological Operations: Binarization is performed using the OTSU thresholding method, followed by color inversion to obtain a mask with a black background and white beans. Morphological closing operations are then used to fill the cavities inside the bean.
[0094] Step E: Contour Extraction and Silver Skin Calculation: Use cv2.findContours to extract the outer contour and calculate the pixel area of the bean-shaped body. Within the ROI region, calculate the pixel area of the silver-colored area. Calculate the silver skin coverage. This serves as a quantitative basis for labeling truth values;
[0095] Data annotation was performed manually using LabelImg software: the bounding box was placed tightly against the outer edge of the bean, and the category label was strictly selected based on the above physical indicators and the silver skin coverage calculation results. For multi-bean images, it was ensured that each bean was labeled.
[0096] To prevent overfitting and improve robustness to environmental changes, a hybrid data augmentation strategy was employed, combining offline and online methods to expand the training set to five times its original size (approximately 5815 images).
[0097] 4. Geometric Transformation: Horizontal and vertical flipping to simulate the camera's installation angle and the random orientation of the beans.
[0098] 5. Noise injection:
[0099] ① Salt and pepper noise: Noise ratio 0.75, salt and pepper ratio 0.5, simulating transmission signal interference.
[0100] ② Gaussian noise: mean 0, standard deviation 80, simulating illumination noise.
[0101] 6. Random Occlusion: A black rectangular block is randomly generated in the image, with an area of 0.01-0.04 and an aspect ratio of 0.7-1.6. This forces the model to use local features (such as the unoccluded half of the bean) for recognition, thus enhancing its resistance to occlusion.
[0102] 7. Mosaic Enhancement: Performed online during training, four training images are randomly selected, scaled, cropped, and rearranged to create a new image. Mosaic enhancement greatly enriches the detection scenarios, allowing the model to see more diverse combinations of targets and backgrounds in a single iteration. This significant scaling operation naturally improves the model's ability to detect small targets (such as distant beans or beans with high density occlusion).
[0103] Example 2
[0104] A detailed description of the model architecture of a multi-module fusion target detection system (MFASL-LiteV8) for automatic grading of green coffee beans is as follows:
[0105] The overall system architecture follows the YOLOv8 CSPDarknet approach, but key components have undergone targeted replacements and upgrades (see...). Figure 1 ).
[0106] 1. Backbone: The backbone is responsible for extracting general image features.
[0107] 2. P1-P2 layers (shallow layers): Maintain the Conv and C2f structure of YOLOv8 for fast dimensionality reduction.
[0108] 3. P3 layer (low-level features): Introduces C2f-ScConv; This layer has a high feature map resolution (e.g., 80x80), containing a lot of spatial details but with high redundancy; ScConv uses the SRU (spatial recalibration) module to calculate the spatial variance of the feature map using group normalization. Regions with large variance are considered to be information-rich (e.g., bean-shaped edges), while regions with small variance (e.g., smooth backgrounds) are suppressed; This is equivalent to having "attention" built into the feature extraction stage, reducing the processing of background noise in subsequent calculations; The CRU (channel redistribution) module fuses the retained features through lightweight convolution (1x1 + 3x3).
[0109] 4. P4-P5 layers (medium to high-level features): C2f-MogaBlock is introduced; as the network deepens, the feature map resolution decreases (40x40, 20x20), and fine-grained textures are easily lost.
[0110] MogaBlock utilizes multi-scale dilated convolution (dilation rate) to achieve... Parallel feature extraction; dilated convolution expands the receptive field without increasing the number of parameters, enabling the convolution kernel to cover the entire bean body (determine shape) and capture the fine silver spots on the surface of the bean body (determine grade); the subsequent gating aggregation mechanism dynamically fuses these multi-scale features based on the similarity of feature content, enhancing the discriminative power of texture.
[0111] 5. End-of-Layer Enhancement (SimAM): After the P5 layer output, an SPPF (Spatial Pyramid Pooling-Fast) module is connected, followed by the embedding of SimAM. SimAM is based on the energy function:
[0112]
[0113] This formula assesses the importance of the target neuron by calculating the linear separability between the target neuron and surrounding neurons; the calculated weight matrix Multiply back directly to the original feature map; this step requires no training parameters but can significantly enhance the feature response values of defective areas (such as mold spots on black beans).
[0114] 6. Neck Network: The Neck adopts the PANet (Path Aggregation Network) structure, which includes two paths: top-down and bottom-up.
[0115] ① Upsampling and Fusion: In the Top-down path, deep semantic features are upsampled and then fused with shallow features. The traditional Concat method is abandoned in favor of MFM (Multi-Feature Mixer). MFM first aligns the feature channels of the two branches, then stacks them, and compresses them using global average pooling (GAP). The descriptor is then used by the MLP to generate weight vectors for the two branches. (satisfy ); Final output This dynamic weighting mechanism enables the model to automatically assign higher weights to shallow geometric features when detecting heavily occluded beans, and to complete the localization using contour information.
[0116] ② Module Consistency: The feature processing modules in Neck maintain a consistent strategy with Backbone: C2f-MogaBlock (layers 13 and 15) is used for paths connecting deep features, and C2f-ScConv (layers 18 and 21) is used for paths connecting shallow features, ensuring the efficiency and consistency of feature extraction.
[0117] 7. Head Network: The Head part is responsible for the final prediction;
[0118] ① Decoupled design: Continuing the decoupled head design of YOLOv8, the classification (Cls) and regression (Reg) branches are separated.
[0119] Detect_LQE: In the Reg branch Then, a parallel introduction was made. The LQE branch, with an output dimension of 1, is activated by a Sigmoid function to obtain the IoU prediction value. This value represents the model's "confidence" in the quality of its predicted bounding boxes.
[0120] Inference Strategy: In the NMS stage, traditional methods only rank based on classification confidence, which may result in the retention of bounding boxes with high classification scores but skewed locations. Introducing LQE improves the ranking score... In this way, boxes that are both accurately classified and precisely located will be ranked higher, effectively eliminating redundant boxes in dense scenes.
[0121] Example 3
[0122] This embodiment details the Fusion Loss function as follows:
[0123] The Fusion Loss function is expressed as follows:
[0124]
[0125] In the formula, CIoU Loss is used for bounding box regression. For Distribution Focal Loss;
[0126] The core improvement lies in classification loss. :
[0127]
[0128] Focal Loss item:
[0129] ;
[0130] set up This feature primarily targets hard-to-distinguish samples; for example, beans with a silver skin coverage of around 10% are easily misclassified as first- or second-grade beans; black beans are easily confused with the background when there is insufficient light. Focal Loss can automatically reduce the loss contribution of a large number of easily distinguishable samples (typically first-grade beans), allowing gradient updates to focus on these hard examples.
[0131] Cross-Entropy item: This provides global, stable gradient guidance, preventing non-convergence caused by Focal Loss focusing excessively on noise points in the early stages of training.
[0132] Weight balancing: Experiments show that setting This combination achieves the best results when the model is in use. It ensures both sensitivity to the minority class (defective beans) and maintains the overall convergence stability of the model.
[0133] Example 4
[0134] Training and validation of a multi-module fusion target detection model (MFASL-LiteV8 model) for automatic grading of green coffee beans; details are as follows:
[0135] 1. Experimental Setup
[0136] ① Platform: AutoDL cloud server, GPU is NVIDIA RTX 4090 (24GB), CPU is Intel Xeon Platinum (16 cores).
[0137] ② Framework: PyTorch 2.5.1, Python 3.12, CUDA 12.4.
[0138] ③ Hyperparameters: Input dimensions Batch Size 64, Epochs 300. Optimizer: SGD, Momentum 0.937, Weight Decay 0.0005. Initial learning rate: 0.01, with cosine annealing used to decay the learning rate.
[0139] ④ Training strategy: Warm up the model for the first 3 epochs. Turn off Mosaic enhancements for the last 10 epochs to refine the model parameters.
[0140] 2. Evaluation Indicators
[0141] ① P (Precision): Precision rate, a measure of accuracy;
[0142] ② R (Recall): Recall rate, a measure of recall capability;
[0143] ③ mAP@0.5: The average precision when the IoU threshold is 0.5;
[0144] ④ mAP@0.5:0.95: Comprehensive index under high-precision positioning requirements;
[0145] ⑤ Params & FLOPs: Measures the model size and computational complexity;
[0146] ⑥ FPS: Frames per second, a measure of inference speed.
[0147] 3. Analysis of Experimental Results
[0148] ①Ablation Study: To verify the independent contribution of each module, ablation studies were conducted as shown in Table 1 and Table 2.
[0149] plan MFM C2f_ScConv C2f_MogaBlock SimAM Detect_LQE loss function Base M1 √ M2 √ M3 √ M4 √ M5 √ C1 √ √ C2 √ √ √ C3 √ √ √ √ C4 √ √ √ √ √ C5 √ √ √ √ √ √ FULL √ √ √ √ √ √
[0150] Table 1: Ablation Experimental Protocol
[0151] plan P R mAP50 mAP50–95 Params(M) FLOPs(G) Remark Base 0.926 0.953 0.972 0.953 3.012 524.701 pure YOLOv8n M1 0.964 0.939 0.977 0.972 2.900 547.867 Replace only with MFM M2 0.932 0.9 0.972 0.965 2.835 506.547 Only ScConv M3 0.893 0.963 0.974 0.967 3.007 519.969 MogaBlock only M4 0.918 0.956 0.978 0.971 3.012 524.701 SimAM only M5 0.961 0.878 0.972 0.964 3.012 524.701 LQE detection head only C1 0.958 0.929 0.982 0.971 2.646 477.581 Replace C2f C2 0.939 0.939 0.982 0.974 2.646 477.581 Add detection head C3 0.96 0.95 0.982 0.965 2.602 501.900 Modify the neck network structure C4 0.967 0.956 0.985 0.975 2.602 501.900 Add attention C5 0.973 0.975 0.993 0.985 2.602 501.900 Modify the loss function FULL 0.973 0.975 0.993 0.985 2.602 501.900 Final Model
[0152] Table 2: Ablation Experiment Results
[0153] Baseline (YOLOv8n): P=92.6%, R=95.3%, mAP@0.5=97.2%.
[0154] As shown in Table 2 above, ① and + MFM: mAP is improved to 97.7%, proving that multi-scale fusion effectively improves feature representation.
[0155] ② + C2f-ScConv: The number of parameters decreased significantly (3.01M -> 2.83M), while the accuracy remained unchanged, verifying its lightweight capability.
[0156] ③ The +C2f-MogaBlock mAP was improved to 97.4%, demonstrating its ability to extract fine-grained features.
[0157] ④ + SimAM: mAP improved by 0.4%, making it extremely cost-effective for parameterless attention.
[0158] ⑤ +Detect_LQE: The significant improvement in R proves that the localization quality estimation reduces false deletions.
[0159] ⑥ + Fusion Loss: Has the greatest effect on improving the recall rate of black beans and broken beans.
[0160] Fully converged (MFASL-LiteV8): All indicators reached their optimal levels, with P=97.3%, R=97.5%, mAP@0.5=99.3%, and mAP@0.5:0.95=98.5%. At the same time, the number of parameters was reduced to 2.602M, and FLOPs were reduced to 501.9G.
[0161] Example 5
[0162] This embodiment compares the model of the multi-module fusion target detection system (MFASL-LiteV8 model) for automatic grading of green coffee beans described in this invention with mainstream models; the details are shown in Table 3 below:
[0163] Model Params(M) FLOPs(G) FPS (average) P R mAP50 mAP50–95 MFASL-LiteV8 2.602 501.900 102.16 0.973 0.975 0.993 0.985 YOLOv8s 11.138 1833.96 122.16 0.947 0.919 0.972 0.968 YOLOv8m 25.859 5061.02 107.20 0.954 0.905 0.974 0.968 YOLOv8l 43.634 10586.9 86.69 0.925 0.929 0.974 0.97 YOLOv8x 68.157 16521.2 88.07 0.933 0.925 0.971 0.925 YOLOv5n 3.109 559.584 122.47 0.953 0.926 0.98 0.972 YOLOv10n 2.907 537.700 83.59 0.886 0.955 0.972 0.967 YOLOv11n 2.591 644.490 116.22 0.934 0.943 0.982 0.976 Deformable DERT 41.503 4701.44 59.37 0.931 0.926 0.945 0.933 SSD 24.281 3923.20 763.48 0.93 0.83 0.945 0.822 Faster R-CNN 41.320 5937.92 78.92 0.937 0.933 0.961 0.914
[0164] Table 3 Performance Comparison of Different Models
[0165] As shown in Table 3:
[0166] YOLOv5n: MFASL-LiteV8 outperformed by 1.3 percentage points in mAP@0.5:0.95, and had fewer parameters.
[0167] YOLOv8s / m: Although v8s / m has good accuracy, its parameter count is 4 times and 10 times that of this model, respectively, and its inference speed is much lower than this model (102 FPS vs 60 FPS), making it unsuitable for embedded deployment.
[0168] Faster R-CNN: A typical two-stage model with high accuracy (96.1% mAP), but extremely slow speed (<20 FPS) and huge model size (41M Params), which cannot meet the needs of production lines.
[0169] RT-DETR: A Transformer architecture model with acceptable accuracy but high computational cost and low FPS. Conclusion: MFASL-LiteV8 achieves the current best trade-off between accuracy and speed.
[0170] Visual verification: In actual testing (e.g.) Figure 11 The model successfully identified closely packed "conjoined beans," accurately distinguished between first-grade and second-grade beans with similar colors, and precisely outlined black beans hidden in shadows. The confidence levels were generally above 0.9, demonstrating the model's high robustness.
[0171] Example 6
[0172] To verify the practical application capability of the multi-module fusion target detection system (MFASL-LiteV8) for automatic grading of green coffee beans described in this invention, the trained system was... The model was exported to ONNX format and deployed for FP16 quantization on an NVIDIA Jetson Orin Nano using TensorRT.
[0173] Conversion process: PyTorch -> ONNX -> TensorRT Engine.
[0174] Performance testing: On the Jetson Orin Nano, the quantized model inference latency is only 8.5ms (approximately 117FPS), with a video memory usage of <1GB.
[0175] System integration: The model is integrated into the coffee bean sorting machine control system, and the air valve nozzle is controlled through the GPIO interface.
[0176] In summary, based on Examples 1-6, the MFASL-LiteV8 system of this invention, by creatively integrating MogaBlock's fine-grained feature extraction capability, ScConv's redundancy suppression capability, MFM's adaptive fusion capability, and SimAM's attention mechanism, successfully constructs a highly efficient detection network specifically for grading Yunnan small-bean coffee beans. Combining Fusion Loss and Detect_LQE, the model achieves state-of-the-art detection accuracy with extremely low computational cost, providing strong technical support for the intelligent upgrading of the coffee industry.
Claims
1. A multi-module fusion target detection system for automatic grading of green coffee beans, characterized in that, Includes the following steps: S1. Construct a Yunnan small-bean green coffee bean grading standard dataset with multi-scale and fine-grained features: Collect images of green coffee beans of different grades and defect categories, including Grade 1 normal beans, Grade 2 normal beans, Grade 3 normal beans, black beans, and damaged beans; Perform multi-stage preprocessing on the collected images, including grayscale processing, bilateral filtering for noise reduction, Canny edge detection, and outer contour extraction, to accurately separate the bean body from the background and quantify the extraction of silver skin region features; Expand the dataset using a hybrid data augmentation strategy, including geometric transformation and noise introduction for single beans, and geometric transformation and multi-image stitching enhancement for multi-bean scenarios; Divide the dataset into training set, validation set, and test set according to a preset ratio; S2. Construct a lightweight multi-module fusion object detection model MFASL-ListV8 based on the improved YOLOv8 architecture: This model is based on the YOLOv8n architecture and introduces customized specific extraction and fusion modules in specific layers of the backbone network and the neck network respectively. S3. In the mid-to-high-level semantic feature extraction stage of the backbone network and neck network, a C2f-MogaBlock module is designed and implanted: The C2f-MogaBlock module retains the parallel branch topology of C2f, replaces the bottleneck unit (Bottleneck) with the multi-level gated aggregation unit (MogaBlock), uses multi-scale dilated convolution and gating mechanism for spatial aggregation, and uses depthwise separable convolution for channel aggregation, so as to enhance the representation ability of fine-grained texture features such as silver skin residue and tiny broken edges on the surface of coffee beans; S4. In the shallow and low-level feature extraction stages of the backbone network and neck network, a C2f-ScConv module is designed and implanted. Three cascaded self-calibrating convolutional units (Bottleneck_ScConv) are integrated in the parallel branch of C2f. Spatial redundancy features are suppressed by the spatial recalibration unit (SRU) and the interaction between channels is optimized by the channel redistribution unit (CRU) to reduce computational complexity and retain key geometric contour information. S5. In the multi-scale feature fusion node of the neck network, design and implant a multi-feature mixer module (MFM) to replace the original concat operation; The MFM module generates dynamic weights through global context modeling and performs adaptive weighted fusion of feature branches from different scales to solve the problem of feature aliasing and missed detection of small targets and occluded targets in scenarios with multiple overlapping and densely distributed features. S6. At the end feature output position of the backbone network, embed the parameterless attention mechanism SimAM; the SimAM module directly calculates the attention weight of each neuron in the feature map based on the energy function, enhances the model's attention to the differences between the bean body and the background, and between the silver skin and the smooth surface, without adding additional model parameters. S7. Construct a Detect_LQE detection head that includes a localization quality estimation branch; Based on the original classification and regression branches, introduce an LQE branch with shared convolutional features to predict the IoU value between the predicted box and the ground truth box, which is used to calibrate the classification confidence during the inference stage and improve the bounding box regression accuracy and localization quality. S8. Define the Fusion Loss function for class imbalanced and hard-to-classify samples; By combining Focal Loss and Cross-Entropy Loss, and adjusting the weight coefficients to balance the learning ratio of positive and negative samples and easy and difficult samples, the model's classification performance for minority class defective beans (black beans, broken beans) and critical grade beans is optimized. S9. The constructed MFASL-LiteV8 model is trained end-to-end using the training set. The model parameters are iteratively updated using a stochastic gradient descent (SGD) optimizer until the loss function converges to obtain the optimal detection model. The model is then deployed on edge computing devices or embedded terminals for real-time hierarchical detection.
2. The multi-module fusion target detection system for automatic grading of green coffee beans according to claim 1, characterized in that, In S1, during the dataset annotation stage, the grading standard for green coffee beans integrates both physical particle size and silverskin coverage. The specific quantitative standards are as follows: Grade 1 normal beans have a particle size greater than 6.30 mm and a silverskin coverage of less than 10%; Grade 2 normal beans have a particle size greater than 5.6 mm and a silverskin coverage of 10%-20%; Grade 3 normal beans have a particle size greater than 4.75 mm and a silverskin coverage of greater than 20%. Defective beans include black beans with moldy, grayish-black surfaces and broken beans with incomplete shapes or obvious cracks. The data preprocessing specifically includes: setting the grayscale contrast to 0.9 for grayscale conversion; using bilateral filtering with a diameter d=4, color space standard deviation sigmaColor=15, and coordinate space standard deviation sigmaSpace=15; setting a low threshold of 50 and a high threshold of 150 for Canny edge detection; and binarization color inversion and outer contour extraction.
3. The multi-module fusion target detection system for automatic grading of green coffee beans according to claim 1, characterized in that, In S3, the specific structural configuration of the C2f-MogaBlock module is as follows: based on the C2f module architecture of YOLOv8, the number of input channels is compressed through a pre-convolution of 1x1, and the feature map is divided into two branches along the channel dimension, one of which passes through... One branch is processed by a series of MogaBlock units, and another branch is connected via a shortcut. Finally, the output is fused with a 1x1 convolution through concatenation. The spatial aggregation stage of the MogaBlock unit includes: extracting features using multi-scale dilated convolutions with kernel sizes of 3x3, 5x5, and 7x7, and performing gated aggregation through channel segmentation and non-linear activation. The C2f-MogaBlock module is specifically deployed in the high-level stage of the MFASL-LiteV8 network architecture to specifically enhance the texture details in the mid-to-high-level semantics.
4. The multi-module fusion target detection system for automatic grading of green coffee beans according to claim 1, characterized in that, In S4, the specific structural configuration of the C2f-ScConv module is as follows: In the architecture of the C2f module, the main branch contains three cascaded Bottleneck_ScConv units; the core of each Bottleneck_ScConv unit is a self-calibrating convolution, which contains parallel SRU and CRU; the SRU first performs group normalization on the input features, uses the Sigmoid function to generate gate weights, separates the features into information features and redundant features, and only reconstructs the information features; CRU utilizes a "segmentation-transformation-fusion" strategy, extracting features through 1x1 convolutions in the upper branch and 3x3 convolutions in the lower branch, and then fusing them using Softmax weighted fusion. The C2f-ScConv module is specifically deployed in the lower layers of the network architecture to compress the redundant computation of shallow networks to the maximum extent while maintaining accuracy.
5. A multi-module fusion target detection system for automatic grading of green coffee beans according to claim 1, characterized in that, In S5, the fusion calculation process of the MFM module specifically includes: S5.1 Input Projection: Let the input feature branch be... Apply a 1x1 convolution to each branch to uniformly adjust its channel count. ; S5.2 Feature Stacking: The adjusted feature maps are stacked along the channel dimension to form a combined feature map. ; S5.3, Weight Generation: For Global average pooling is performed, and normalized attention weight vectors for each branch are generated through two fully connected layers (MLP) and a softmax activation function. ; S5.4 Weighted Fusion: The input branch is summed element-by-element using the weights mentioned above. The calculation formula is as follows: The fused feature map is output; the MFM module is deployed at all nodes in the neck network where multi-scale feature convergence occurs, replacing the original Concat operation.
6. The multi-module fusion target detection system for automatic grading of green coffee beans according to claim 1, characterized in that, In S6, the energy function of the SimAM attention mechanism The formula for calculating its weight is as follows: For the input feature map For each channel in the dataset, calculate the location of each neuron. energy value : in, For the target neuron, For other neurons, and This represents the objective value of the corresponding linear transformation; minimizing this energy function yields the analytical weights for each neuron. In the formula, and These represent the mean and variance of all neurons within the channel, respectively. Here is the regularization coefficient; the final output feature map is... ,in For all The energy matrix formed This indicates element-wise multiplication; the SimAM module is embedded after the SPPF module in the 9th layer of the backbone network, serving as an enhancement step before the features enter the neck network.
7. A multi-module fusion target detection system for automatic grading of green coffee beans according to claim 1, characterized in that, In S7, the workflow of the Detect_LQE detection head is as follows: S7.1 Feature Decoupling: The feature maps output by the neck network are fed into the classification branch (Cls Branch) and the regression branch (Reg Branch) respectively. S7.2, LQE branch embedding: After the convolutional layer of the regression branch, a parallel LQE branch is introduced. This branch consists of a 1x1 convolutional layer with an output dimension of 1. After Sigmoid activation, it represents the IoU estimate between the predicted box and the ground truth box. S7.3 Inference Calibration: During the inference phase, the final confidence score... The calculation formula is: In the formula, The output of the classification branch is the class probability. The positioning quality score output by the LQE branch. This is the balance coefficient; S7.4, Non-maximum suppression (NMS): Using calibrated... When performing NMS operations, prioritize retaining the detection bounding boxes with more accurate positioning.
8. A multi-module fusion target detection system for automatic grading of green coffee beans according to claim 1, characterized in that, In S8, Fusion Loss ( The specific mathematical expression of ) is: In the formula, This represents the model's predicted probability for the target category. To balance the positive and negative samples; This is the focusing parameter for Focal Loss, used to reduce the weight of easily classified samples; One-hot encoding for the true category label, For the first Predicted probability of the category; and These are the weight coefficients of the Focal Loss and Cross-Entropy Loss terms, respectively. Through joint optimization, the model can converge quickly in the early stage of training by utilizing cross-entropy, and in the later stage, Focal Loss can be used to tackle difficult samples such as black beans and broken beans.