Cotton rolling quality detection method and system
Through the improved Yolov8 network model, combined with the efficient channel attention mechanism and Focal Loss function, the problems of low efficiency and poor accuracy in cotton gluter quality detection are solved, and efficient detection of cotton texture and defect distribution is achieved, meeting the detection requirements of national standards.
Patent Information
- Application Number
- CN202510558363.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-29
- Publication Date
- 2025-08-08
AI Technical Summary
The prior art has problems of low manual detection efficiency and poor accuracy in cotton rolling quality detection, and deep learning research mainly focuses on cotton pests and diseases and foreign fiber detection, and insufficient research on the texture and roughness of rolling quality.
The improved Yolov8 network model is adopted to train the cotton image dataset by introducing the efficient channel attention mechanism (ECA), Focal Loss function and step-by-step classification strategy, and improve the model's fine-grained feature extraction ability of cotton texture and defect distribution, and optimize the bounding box regression accuracy through the EIoU loss function.
It significantly improves the accuracy and robustness of cotton gluten quality inspection, reduces the complexity of the model, improves the classification accuracy of P1, P2 and P3 levels, and meets the national inspection standard GB 1103.1-2023.
Smart Images

Figure CN120451108A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of cotton quality classification, and in particular to a cotton ginning quality detection method and system. Background Art
[0002] Cotton is one of the world's most important agricultural cash crops, directly impacting the raw material supply of the textile industry. It not only provides employment opportunities for farmers but also drives economic development in many countries. Cotton quality assurance is crucial, and cotton quality inspection is essential. Grinding quality testing is a key indicator within this process, significantly impacting subsequent cotton processing and the textile industry. The latest revised national standard provides a clear definition: After seed cotton processing, ginning quality is categorized into three grades: good, medium, and poor, based on the roughness of the lint's appearance, as well as the type and number of defects it contains. These grades are designated P1, P2, and P3, respectively.
[0003] Early cotton ginning quality testing relied primarily on manual sensory inspection. This led to problems such as eye fatigue and a lack of concentration after long hours of work. Furthermore, different individuals possessed varying levels of professional skills, which directly impacted cotton grading and made it difficult to ensure efficient and accurate inspections. With the widespread adoption of smart agriculture, deep learning technology has achieved breakthroughs in crop classification, crop detection, yield prediction, and other areas of agriculture.
[0004] In the field of cotton detection, many studies have been conducted on cotton pests and diseases, cotton internal impurities, etc. Reference [1] uses YOLOv5 and MaskR-CNN to detect two algorithms in two stages to establish a cotton trichome detection and counting system based on deep learning technology and compares it with the YOLOv3 and YOLOv4 models; Reference [2] proposes a new and efficient method for rapid detection of foreign fibers in seed cotton by improving the YOlOv7 network model with Swin-Transforme and ConvNext modules, which provides a solid technical foundation for the creation of an automated detection device for foreign fibers in seed cotton; Reference [3] proposes a cotton pest classification in field images based on a deep residual network to identify various pests on cotton leaves; Reference [4] improves the YOLOX model by introducing ECA, hard-Swish and Focal Loss modules, and proposes a precise detection system for cotton pests and diseases under complex backgrounds.
[0005] In addition to cotton testing, researchers have also tested the quality of many plants. Reference [5] proposed a ResNet deep model and transfer learning technology for rice variety classification and quality detection; Reference [6] proposed a cotton seed quality detection method based on the improved ResNet50 model by embedding the CBAM module and improving the fully connected layer; Reference [7] used computer vision and MLP, SVM, kNN, DT classification models to classify seven different registered dry bean varieties; Reference [8] proposed a lightweight Lit-FasterNet model by optimizing volumes and channels, adding full convolution layers, and modifying the fully connected layers, and mapped it to FPGA using DDR3 SDRAM to achieve dual transmission of image data and weights to efficiently detect lettuce quality.
[0006] However, due to differences in cotton ginning quality inspection standards, there has been little research on cotton grade detection. Most of the researchers' deep learning research has focused on foreign fibers, defects, pests, and other plants with universal rating standards. These studies have mostly focused on details, and no further research has been conducted on the overall texture and roughness of cotton ginning quality. Summary of the Invention
[0007] In view of the above problems, the present invention proposes a cotton ginning quality detection method and system.
[0008] According to one aspect of the present invention, a cotton ginning quality detection method is provided, the method comprising:
[0009] Get the cotton image dataset;
[0010] A classification model based on the improved Yolov8 network was trained based on the cotton image dataset;
[0011] The cotton image to be tested is input into the trained classification model for classification to obtain the cotton quality grade.
[0012] Furthermore, the labels of cotton images in the cotton image dataset include first-grade cotton, second-grade cotton, and third-grade cotton according to ginning quality; the cotton images of the three ginning qualities are preprocessed as follows: the second-grade cotton images are deleted, and the first-grade cotton images and the third-grade cotton images are expanded.
[0013] Furthermore, the preprocessing of the cotton image dataset also includes: classifying and organizing the cotton image dataset in steps, that is, in the first step, the first-level cotton image and the second-level cotton image are placed in the same folder, and the category name corresponding to the folder is defined as P0, and the category P0 and the third-level cotton image P3 are classified; in the second step, the first-level cotton image P1 and the second-level cotton image P2 under the category P0 are classified.
[0014] Furthermore, the improvements of the improved Yolov8 network include: adding an ECA attention mechanism to the original Yolov8 network; replacing the regression loss IoU function with an EIoU function; and modifying the classification loss function to a Focal Loss function.
[0015] Furthermore, an ECA attention mechanism is added to the end of the backbone network of the original Yolov8 network. The operation mechanism of the ECA attention mechanism includes: first, compressing the spatial dimension feature information through a global average pooling layer; then using a one-dimensional convolution layer with an adaptive convolution kernel k to achieve local cross-channel interaction; finally, normalizing the feature response to the channel attention weight through a Sigmoid function; where the adaptive convolution kernel k is expressed as:
[0016]
[0017] Where C represents the number of channels of input features; δ and b are hyperparameters; | | odd It means taking the absolute value and rounding down to the nearest odd number.
[0018] Furthermore, the formula of the EIoU function is expressed as:
[0019]
[0020] Where w c and h c Represents the width and height of the minimum bounding rectangle of the predicted bounding box and the true bounding box respectively; ρ 2 (d,d gt ) represents the square of the Euclidean distance between the center point of the predicted bounding box and the true bounding box; ρ 2 (w,w gt ) represents the Euclidean width difference between the center point of the predicted bounding box and the true bounding box; ρ 2 (h,h gt ) represents the Euclidean height difference between the center point of the predicted bounding box and the true bounding box.
[0021] Furthermore, the formula of the Focal Loss function is expressed as:
[0022] FL(p t )=-α t (1-p t ) γ log(p t )
[0023] Where, P t Represents the model's predicted probability of the target class; α tis a balancing factor used to adjust the influence between positive and negative samples; γ is a focus factor used to adjust the weight of difficult and easy samples.
[0024] According to another aspect of the present invention, a cotton ginning quality detection system is provided, the system comprising:
[0025] an image acquisition module configured to acquire a cotton image dataset;
[0026] a model training module configured to train a classification model based on an improved Yolov8 network based on a cotton image dataset;
[0027] The quality classification module is configured to input the cotton image to be tested into the trained classification model for classification to obtain the cotton quality grade.
[0028] Furthermore, the improvements of the improved Yolov8 network in the model training module include: adding an ECA attention mechanism to the original Yolov8 network; replacing the regression loss IoU function with an EIoU function; and modifying the classification loss function to a Focal Loss function.
[0029] Furthermore, the operation mechanism of the ECA attention mechanism in the model training module includes: first compressing the spatial dimension feature information through a global average pooling layer; then using a one-dimensional convolution layer with an adaptive convolution kernel k to achieve local cross-channel interaction; finally, normalizing the feature response to the channel attention weight through a Sigmoid function; where the adaptive convolution kernel k is expressed as:
[0030]
[0031] Where C represents the number of channels of input features; δ and b are hyperparameters; | | odd It means taking the absolute value and rounding down to the nearest odd number;
[0032] The formula of the EIoU function is expressed as:
[0033]
[0034] Where w c and h c Represents the width and height of the minimum bounding rectangle of the predicted bounding box and the true bounding box respectively; ρ 2 (d,d gt ) represents the square of the Euclidean distance between the center point of the predicted bounding box and the true bounding box; ρ 2 (w,w gt ) represents the Euclidean width difference between the center point of the predicted bounding box and the true bounding box; ρ 2 (h,h gt) represents the Euclidean height difference between the center point of the predicted bounding box and the true bounding box;
[0035] The formula of the Focal Loss function is expressed as:
[0036] FL(p t )=-α t (1-p t ) γ log(p t )
[0037] Where, P t Represents the model's predicted probability of the target class; α t is a balancing factor used to adjust the influence between positive and negative samples; γ is a focus factor used to adjust the weight of difficult and easy samples.
[0038] The beneficial technical effects of the present invention are:
[0039] This paper proposes a cotton ginning quality detection method and system. The dataset selects cotton of three ginning quality grades. Based on the new national cotton quality inspection standard GB 1103.1-2023, the model is trained based on the roughness of the lint appearance and the types of defects it contains. The Yolov8-cls model is used as the baseline model, and an efficient channel attention mechanism, a Focal Loss function, and a step-by-step classification strategy are introduced. Specifically, an efficient channel attention module (ECA) is embedded at the end of the backbone network, significantly improving the model's ability to extract fine-grained features such as cotton texture and defect distribution. To address sample imbalance, a Focal Loss function is used to adjust the weights of easy and difficult samples, reducing the impact of high-quality anchor box gradients on training. Furthermore, the IoU loss is improved to EIoU (Enhanced IoU), which improves the bounding box regression accuracy by minimizing the center distance and width-height difference between the predicted box and the true box. Experimental results show that after training using the improved model of the present invention, the classification accuracy is significantly improved, and the overall performance of the improved model is significantly better than the original model. However, the results showed that the classification of P1 and P2 grades resulted in a high incidence of misclassification. To address this issue, a two-stage classification process was proposed: in the first stage, P1 and P2 were combined into the P0 class and coarsely classified with P3; in the second stage, P1 and P2 within the P0 class were finely classified. This strategy reduced model complexity and improved classification accuracy by decomposing tasks. This invention provides strong data support for cotton ginning quality classification. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The above and other objects, features and advantages of the exemplary embodiments of the present invention will become readily apparent by reading the following detailed description with reference to the accompanying drawings, in which several embodiments of the present invention are shown by way of example and not limitation, in which:
[0041] Figure 1 is a flow chart of a cotton ginning quality detection method according to an embodiment of the present invention;
[0042] Figure 2 2 is a schematic structural diagram of a cotton image acquisition device according to an embodiment of the present invention;
[0043] Figure 3 The following are photos of cotton of three grades of ginning quality according to an embodiment of the present invention; (a) corresponds to grade P1; (b) corresponds to grade P2; and (c) corresponds to grade P3.
[0044] Figure 4 Schematic diagram of the structure of the C2f module in an embodiment of the present invention;
[0045] Figure 5 Schematic diagram of the structure of the Conv module in an embodiment of the present invention;
[0046] Figure 6 1 is a diagram showing the overall structure of the improved YOLOv8 classification model in an embodiment of the present invention;
[0047] Figure 7 Schematic diagram of the principle of the ECA module in an embodiment of the present invention;
[0048] Figure 8 1 is a flow chart of a cascade neural network algorithm based on an improved YOLOv8 classification model in an embodiment of the present invention;
[0049] Figure 9 : This is a comparison chart of the precision, recall rate, F1 score, and confusion matrix of the YOLOv8 classification model before and after improvement in an embodiment of the present invention;
[0050] Figure 10 This is a comparison chart of the top 1 accuracy of the YOLOv8 classification model before and after improvement in an embodiment of the present invention;
[0051] Figure 11 This is a comparison chart of the losses before and after the improvement of the YOLOv8 classification model in an embodiment of the present invention. DETAILED DESCRIPTION
[0052] The principles and spirit of the present invention will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided solely to enable those skilled in the art to better understand and implement the present invention, and are not intended to limit the scope of the present invention in any way. Rather, these embodiments are provided to make this disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.
[0053] It is known to those skilled in the art that the embodiments of the present invention may be implemented as a system, apparatus, device, method, or computer program product. Therefore, the present disclosure may be specifically implemented in the following forms, namely: complete hardware, complete software (including firmware, resident software, microcode, etc.), or a combination of hardware and software. It should be understood that any number of elements in the accompanying drawings is for illustration and not limitation, and any nomenclature is for distinction only and does not have any limiting meaning.
[0054] The embodiment of the present invention provides a cotton ginning quality detection method, such as Figure 1 As shown, the method includes:
[0055] S1. Obtain cotton image dataset;
[0056] S2, training a classification model based on the improved Yolov8 network based on the cotton image dataset;
[0057] S3. Input the cotton image to be tested into the trained classification model for classification to obtain the cotton quality grade.
[0058] The method starts from S1. In S1, a cotton image dataset is obtained.
[0059] According to an embodiment of the present invention, a cotton image acquisition device is used to collect a cotton image dataset. The entire device consists of the following parts: 1) Loading platform: composed of a transparent glass plate and a loading platform, used to fix the cotton sample; 2) Illumination system: using two strip LED light sources distributed on both sides of the camera to ensure uniform illumination of the sample surface; 3) Sample fixing module: through the combination of foam board and slide bar, the cotton sample can be non-destructively fixed and flatly unfolded; 4) Shooting module: composed of a color camera with a resolution of 1920×1080; 5) Control terminal: composed of a display screen, a host, and two start and stop buttons. The schematic diagram of the device is shown in the figure below. Figure 2 shown.
[0060] The working process of the device is as follows: spread the cotton sample flat on the center of the glass slide, press the start button after the device is powered on, the foam plate is pressed down by the slide bar to fix the cotton sample, the image taken by the camera is displayed on the display screen, the picture is screenshot and saved, press the stop button, the foam plate rises, and the operation is repeated.
[0061] By collecting multiple pictures through the above-mentioned acquisition device, we constructed a cotton image dataset with three different ginning qualities: first-grade cotton (good), second-grade cotton (medium), and third-grade cotton (poor), which are represented by P1, P2, and P3 respectively. Figure 3The collected cotton image dataset contains a total of 6206 images. However, due to the excessive number of P2 images in the dataset, P2 images were deleted and P1 and P3 images were expanded. The resulting dataset contains 5308 images, including 1660 P1 images, 3000 P2 images, and 648 P3 images. The dataset is also divided into two parts: training and validation sets. The data distribution between these sets is shown in Table 1. The training set of P1 consists of 1332 images, and the validation set consists of 328 images; the training set of P2 consists of 2400 images, and the validation set consists of 600 images; and the training set of P3 consists of 520 images, and the validation set consists of 128 images.
[0062] Table 1
[0063]
[0064] Then S2 is executed, in which a classification model based on the improved Yolov8 network is trained based on the cotton image dataset.
[0065] According to an embodiment of the present invention, the ginning quality defined in the cotton quality inspection standard is: the roughness of the appearance of the lint cotton and the degree of the types of defects contained after the seed cotton is processed. The appearance includes the clarity and roughness of the cotton layer. The clarity is mainly related to the short fiber rate of the lint cotton. If there are many vertically arranged fibers, the surface will give a fuzzy feeling and the clarity will be reduced. The roughness of the shape is determined based on the shape and number of fiber entanglements and silk threads on the fiber surface and the smoothness, fluffiness and uniformity of the cotton layer. The defects include 7 types: ropes, soft seed skin, stiff pieces, broken seeds, infertile seeds, fiber-bearing seed chips and cotton knots.
[0066] During ginning quality inspection, inspectors process cotton samples to bring their surface density close to the ginning quality standard. They then perform a categorized inspection of the cotton sample as a whole, comparing the overall cotton layer's defects, color, and smoothness with the textual descriptions of the ginning quality grading criteria to determine the grade, as shown in Table 2. Subsequently, defects within the cotton sample are targeted for inspection and compared with the grading criteria reference indicators to determine the grade, as shown in Table 3.
[0067] Table 2
[0068]
[0069] Table 3
[0070]
[0071]
[0072] Yolov8 is the latest YOLO model for object detection, instance segmentation, and image classification. It provides new features based on previous Yolo versions to improve performance and flexibility. According to the ratio of network depth and width, Yolov8 can be divided into five types: N, S, M, L, and X. In view of the size and complexity of the model and the main focus on classification tasks, the present invention selects Yolov8n-cls as the basic network model. The Yolov8n-cls model is a model dedicated to image classification in Yolov8. It is divided into two parts: the backbone network-Backbone and the head network-Head. Its model complexity is smaller and can complete classification tasks faster. Figure 4 、 Figure 5 As shown, the Backbone is responsible for feature extraction and employs a series of convolutional and deconvolutional layers. It also uses residual connections and bottleneck structures to reduce network size and improve performance. This part uses the Conv module and the C2f module as basic building blocks. The Conv module consists of convolution, normalization, and activation functions. Convolution uses a 2D convolution operation to extract local features. Finally, the concatenated feature maps are compressed through a single convolution to output feature maps with the target number of channels. Normalization uses Batch Norm to accelerate training and improve stability. Activation uses the nonlinear activation function SiLU to introduce nonlinear capabilities. The C2f module first performs a convolution on the input feature map, doubling the number of channels. This is followed by multiple Bottleneck modules to gradually extract features. The Head consists of a fully connected layer and average pooling, outputting only a single vector.
[0073] Due to the uneven characteristics of the dataset samples, the present invention improves the original Yolov8n-cls as follows: adding the ECA attention mechanism and Focal Loss function to the original model, and improving the IoU function to the EIoU function. The improved Yolov8 classification model is named Yolov8ECA model. The overall structure of the improved YOLOv8 classification model is shown in the figure below. Figure 6 shown.
[0074] Specifically, the ECA (Efficient Channel Attention) module is added to the end of the Backbone module. The ECA module is a lightweight channel attention mechanism. The core idea is to efficiently model the inter-channel dependency relationship while avoiding dimensionality reduction through a local cross-channel interaction strategy. The principle is as follows: Figure 7As shown. The ECA attention mechanism has made innovative improvements in the channel information aggregation method. Different from the traditional channel attention method that relies on the fully connected layer for channel interaction, the ECA module uses lightweight one-dimensional convolution to achieve dynamic weight generation. Its technical process includes three key steps: first, the spatial dimension feature information is compressed through the global average pooling layer, and then a one-dimensional convolution layer with an adaptive convolution kernel k is used to achieve local cross-channel interaction. Finally, the feature response is normalized to the channel attention weight through the Sigmoid function. This method innovatively introduces a cross-channel interaction strategy that does not require parameter dimensionality reduction. By dynamically calculating the optimal convolution kernel size k, while effectively maintaining the nonlinear relationship between channels, the model parameters are reduced to a negligible O(k) level, successfully solving the problem of feature information loss caused by dimensionality compression in traditional methods. The convolution kernel size k can be adaptively determined as:
[0075]
[0076] Where C is the number of channels of the input feature, δ and b are hyperparameters; | | odd It means taking the absolute value and rounding down to the nearest odd number to ensure that the kernel size is an odd number.
[0077] The regression loss uses the EIoU Loss function, which consists of three parts: IoU loss, distance loss (dis), and height-width loss (asp). The height-width loss directly minimizes the difference in height and width between the predicted target bounding box and the true bounding box, resulting in faster convergence and better positioning results. It also solves the gradient vanishing problem for non-overlapping boxes and jointly optimizes the center point and size deviation to enhance scale invariance. The formula for EIoU Loss is as follows:
[0078]
[0079] Among them, w c and h c is the width and height of the minimum bounding rectangle of the predicted bounding box and the true bounding box; ρ 2 (d,d gt ) is the square of the Euclidean distance between the predicted box and the center point of the real box, ρ 2 (w,w gt ) is the Euclidean width difference between the predicted box and the center point of the real box, ρ 2 (h,h gt ) is the Euclidean height difference between the center point of the predicted box and the true box.
[0080] Taking into account the problem of imbalanced training samples in the process of predicting target bounding box regression, that is, in an image, the number of high-quality anchor frames with small regression errors is far less than the number of low-quality anchor frames with large errors. Anchor frames of poor quality will produce excessively large gradients, affecting the training process. Directly using EIoU is not very effective. Therefore, the embodiment of the present invention adds a classification loss function - Focal Loss, which separates high-quality anchor frames from low-quality anchor frames from the perspective of gradient. FocalLoss introduces a focus factor and adjusts the sample weights so that the model pays more attention to samples that are difficult to classify, thereby improving the classification performance. The formula of Focal Loss is as follows:
[0081] FL(p t )=-α t (1-p t ) γ log(p t )
[0082] Among them, P t is the model’s predicted probability of the target class; α t is a balancing factor used to adjust the influence between positive and negative samples; γ is a focus factor used to adjust the weight of difficult and easy samples.
[0083] In Yolov8-cls model training, the dataset does not need to be labeled, but must be organized in a specific split directory structure. Each directory should contain a subdirectory for each category in the dataset. The subdirectory is named after the corresponding category and contains all images of that category. Make sure that each image file has a unique name, and after training, the category name of the result is the same as the directory name. When classifying, since P3 is quite different from P1 and P2, it is easiest to distinguish them, while the difference between P1 and P2 is not obvious. A step-by-step classification method is proposed. The first step is to put the data of P1 and P2 in the same folder P0 and classify them with P3. The second step is to distinguish P1 and P2. The principle process is as follows Figure 8 shown.
[0084] Then, S3 is executed. In S3, the cotton image to be tested is input into the trained classification model for classification to obtain the cotton quality grade.
[0085] The technical effects of the present invention are further verified through experiments.
[0086] Table 4 lists the computer parameters used for training and validation, as well as the resource configuration of the improved Yolov8 classification model environment. During training, the image size is set to 640×640, the number of training rounds is 100, and the batch size is fixed to 16 given the computational efficiency and model convergence rate.
[0087] Table 4
[0088]
[0089] In order to verify the superiority of the method proposed in this paper on the cotton data dataset, indicators such as accuracy, precision, recall and F1 score were used, and the step-by-step operation (yo-yolov8ECA) performed by the improved yolov8 classification model was compared with the original yolov8 model (yolov8), the original model distribution operation (yo-yolov8) and the improved model (yolov8ECA).
[0090] like Figure 9 As shown in the figure, for the P1 level, the precision rate increased to 91.56%, the recall rate increased to 89.23%, and the F1 value increased to 0.90. For the P2 level, the precision rate increased to 94.24%, the recall rate increased to 95.00%, and the F1 value increased to 0.94. For the P3 level, the precision rate increased to 96.10%, the recall rate increased to 89.47%, and the F1 value increased to 0.88. Among them, the improvement of the P3 level is the most obvious. This is the result of modifying the attention mechanism and loss function. The confusion matrix shows that the original model has a misclassification rate of 28.73% for P1 and P2, while the improved model reduces it to 5.68%. Figure 10 The comparison of accuracy_top1 of six classification tasks, Yo-Yolov8ECA, Yo-Yolov8ECA(P1,P2), Yo-Yolov8ECA(P0,P3), Yo-Yolov8, Yo-Yolov8(P1,P2), and Yo-Yolov8(P0,P3), is listed. Figure 11 The comparison of the loss rate of the training and validation processes for six classification tasks is shown. Among them, Yolov8ECA represents the improved model for the classification tasks of P1, P2, and P3; Yo-Yolov8ECA(P1,P2) represents the classification tasks of P1 and P2 using the improved Yolov8 classification model in a step-by-step manner; Yo-Yolov8ECA(P0,P3) represents the classification task of P3 using the improved Yolov8 classification model in a step-by-step manner, and the same applies to the original model.
[0091] Experimental results show that compared with other models, the improved Yo-YOLOv8ECA model of the present invention has higher accuracy for the classification tasks of P1, P2 and P3, and the loss curve converges faster and the final loss value is lower.
[0092] Table 5 shows the overall performance metrics for the six training tasks. The original YOLOv8 model achieved an overall accuracy of 81.82%, but its recall (66.27%) and F1 score (0.65) were low, indicating sample imbalance and insufficient fine-grained classification capabilities. Using a step-by-step classification strategy, the original model achieved an accuracy of 89.29% and a recall of 74.22% in the task of classifying P3. The accuracy was 92.03% and the F1 score was 0.91 in classifying P1 and P2, validating the effectiveness of the step-by-step strategy for task decomposition. The improved Yolov8 classification model achieved an accuracy of 84.85% and an F1 score of 0.72, demonstrating that the channel attention mechanism enhances the ability to extract texture features. The improved model (Yo-YOLOv8ECA), which further incorporates the step-by-step strategy, achieved an accuracy of 95.62% in the P3 classification task, with precision and recall increased to 96.60% and 90.03%, respectively. In the P1 and P2 classification tasks, the accuracy reached 94.32% and the F1 score reached 0.93, representing a 13.8% improvement in overall accuracy and a 43.1% improvement in F1 score over the original model. In terms of detection speed, the improved model experienced a slight increase due to its increased complexity, but overall, it was still superior.
[0093] Table 5
[0094]
[0095] The overall experimental results show that the ECA module significantly optimizes the model's adaptability to imbalanced data sets and classification accuracy by strengthening fine-grained feature expression and combining the Focal Loss sample balancing strategy. The application of the step-by-step strategy further optimizes the accuracy of rolling quality classification, providing an efficient solution for intelligent detection of rolling quality.
[0096] In summary, in the cotton processing link, ginning quality (i.e. the appearance and defect content of lint) is the core indicator for evaluating cotton grades, which directly affects its market value and the production efficiency of downstream industries. Traditional artificial sensory detection methods have problems such as strong subjectivity, low efficiency, and easy fatigue, while existing research mostly focuses on the detection of cotton pests or impurities, and research on ginning quality grading is relatively scarce. The present invention proposes an intelligent detection method based on an improved YOLOv8 classification model, which significantly improves the detection accuracy and robustness by introducing an efficient channel attention mechanism (ECA), a Focal Loss function, and a step-by-step classification strategy. The dataset selected three ginning quality grades of cotton, and took the new national cotton quality inspection standard GB 1103.1-2023 as the standard, and trained the model according to the degree of rough appearance and defect types of the lint cotton. The Yolov8-cls model was used as a baseline for the improved model. After using the original model for classification testing on a dataset, the accuracy of the results was found to be unsatisfactory. Therefore, the original model was improved by embedding an efficient channel attention (ECA) module at the backbone end, significantly enhancing the model's ability to extract fine-grained features such as cotton texture and defect distribution. To address sample imbalance, a focal loss function was used to adjust the weights of easy and difficult samples, reducing the impact of high-quality anchor box gradients on training. Furthermore, the Intersection over Union (IoU) loss was modified to Enhanced IoU (EIoU), which improves bounding box regression accuracy by minimizing the center distance, width, and height difference between the predicted and true boxes. Retraining with the improved model revealed significant improvements in accuracy. The improved model significantly outperformed the original model overall. However, the results showed a high incidence of misclassifications at the P1 and P2 levels. To address this issue, a novel classification approach was proposed: a two-stage classification process. In the first stage, P1 and P2 are merged into P0 and coarsely classified with P3. In the second stage, P1 and P2 within P0 are finely classified. This strategy reduces model complexity and improves classification accuracy by task decomposition.
[0097] Another embodiment of the present invention provides a cotton ginning quality detection system, the system comprising:
[0098] an image acquisition module configured to acquire a cotton image dataset;
[0099] a model training module configured to train a classification model based on an improved Yolov8 network based on a cotton image dataset;
[0100] The quality classification module is configured to input the cotton image to be tested into the trained classification model for classification to obtain the cotton quality grade.
[0101] In this embodiment, preferably, the improvements of the improved Yolov8 network in the model training module include: adding an ECA attention mechanism to the original Yolov8 network; replacing the regression loss IoU function with an EIoU function; and modifying the classification loss function to a Focal Loss function.
[0102] In this embodiment, preferably, the operation mechanism of the ECA attention mechanism in the model training module includes: first compressing the spatial dimension feature information through a global average pooling layer; then using a one-dimensional convolution layer with an adaptive convolution kernel k to achieve local cross-channel interaction; finally, normalizing the feature response to the channel attention weight through a Sigmoid function; wherein the adaptive convolution kernel k is expressed as:
[0103]
[0104] Where C represents the number of channels of input features; δ and b are hyperparameters; | | odd It means taking the absolute value and rounding down to the nearest odd number;
[0105] The formula of the EIoU function is expressed as:
[0106]
[0107] Where w c and h c Represents the width and height of the minimum bounding rectangle of the predicted bounding box and the true bounding box respectively; ρ 2 (d,d gt ) represents the square of the Euclidean distance between the center point of the predicted bounding box and the true bounding box; ρ 2 (w,w gt ) represents the Euclidean width difference between the center point of the predicted bounding box and the true bounding box; ρ 2 (h,h gt ) represents the Euclidean height difference between the center point of the predicted bounding box and the true bounding box;
[0108] The formula of the Focal Loss function is expressed as:
[0109] FL(p t )=-α t (1-p t ) γ log(p t )
[0110] Where, P t Represents the model's predicted probability of the target class; α t is a balancing factor used to adjust the influence between positive and negative samples; γ is a focus factor used to adjust the weight of difficult and easy samples.
[0111] It should be noted that the functions of the cotton ginning quality detection system described in this embodiment can be described by the aforementioned cotton ginning quality detection method. For the parts not described in detail in the system embodiment, please refer to the above method embodiment.
[0112] It should be noted that although several units, modules, or submodules are mentioned in the detailed description above, such division is merely exemplary and not mandatory. In fact, according to embodiments of the present invention, the features and functions of two or more modules described above may be embodied in one module. Conversely, the features and functions of one module described above may be further divided and embodied by multiple modules.
[0113] Furthermore, although the operations of the method of the present invention are described in a particular order in the accompanying drawings, this does not require or imply that these operations must be performed in this particular order, or that all illustrated operations must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.
[0114] Although the spirit and principles of the present invention have been described with reference to several specific embodiments, it should be understood that the present invention is not limited to the specific embodiments disclosed, and the division into various aspects does not mean that the features of these aspects cannot be combined to benefit. Such division is only for the convenience of expression. The present invention is intended to cover various modifications and equivalent arrangements included within the spirit and scope of the appended claims.
[0115] The documents cited in the present invention are as follows:
[0116] [1] Keyan Luo, Yu Jin, Shuhan Wen, Yicheng Li, Junkang Rong, Mingquan Ding, 2023. Detection and quantification of cotton trichomes by deep learning algorithm. Computers and Electronics in Agriculture. https: / / doi.org / 10.1016 / j.compag.2023.107936.
[0117] [2]Qingxu Li,Wenjing Ma,Hao Li,Xuedong Zhang,Ruoyu Zhang,WanhuaiZhou,2024.Cotton-YOLO:Improved YOLOV7 for rapid detection of foreign fibersin seed cotton.Computers and Electronics in Agriculture..https: / / doi.org / 10.1016 / j.compag.2024.108752.
[0118] [3] Nunes Alves,Witenberg S.R.Souza, Leandro Borges,2020.Cotton pests classification in field-based images using deep residualnetworks.Computers and Electronics in Agriculture..https: / / doi.org / 10.1016 / j.compag.2020.105488
[0119] [4]Yuanjia Zhang,Benxue Ma,Yating Hu,Cong Li,Yujie Li,2022.Accuratecotton diseases and pests detection in complex background based on animproved YOLOX model.Computers and Electronics in Agriculture.https: / / doi.org / 10.1016 / j.compag.2022.107484.
[0120] [5]Mohammad Razavi,Samira Mavaddati,Hamidreza Koohi,2024.ResNet deepmodels and transfer learning technique for classification and qualitydetection of rice cultivars.Expert Systems with Applications.https: / / doi.org / 10.1016 / j.eswa.2024.123276.
[0121] [6]Xinwu Du,Laiqiang Si,Pengfei Li,Zhihao Yun,2023.Amethod fordetecting the quality ofcotton seeds basedon an improved ResNet50 model.PLOSONE..https: / / doi.org / 10.1371 / journal.pone.0273057,
[0122] [7]Murat Koklu,Ilker Ali Ozkan,2020.Multiclass classification of drybeans using computer vision and machine learning techniques.Computers andElectronics in Agriculture.https: / / doi.org / 10.1016 / j.compag.2020.105507.
[0123] [8]Zhenzhong Wang,Tongge Li,Rong Du,Ning Yang,Jianfeng Ping,2025.Ahigh-efficiency lettuce quality detection system based on FPGA.Computers andElectronics in Agriculture.https: / / doi.org / 10.1016 / j.compag.2025.109978.
Claims
1. A cotton ginning quality detection method, characterized in that: include: Get the cotton image dataset; A classification model based on the improved Yolov8 network was trained based on the cotton image dataset; The cotton image to be tested is input into the trained classification model for classification to obtain the cotton quality grade.
2. A cotton ginning quality detection method according to claim 1, characterized in that: The labels of cotton images in the cotton image dataset include first-grade cotton, second-grade cotton, and third-grade cotton according to ginning quality; the cotton images of the three ginning qualities are preprocessed as follows: the second-grade cotton images are deleted, and the first-grade cotton images and the third-grade cotton images are expanded.
3. A cotton ginning quality detection method according to claim 2, characterized in that: The preprocessing of the cotton image dataset also includes: classifying and organizing the cotton image dataset in steps, that is, in the first step, the first-level cotton images and the second-level cotton images are placed in the same folder, and the category name corresponding to the folder is defined as P0, and the category P0 and the third-level cotton image P3 are classified; in the second step, the first-level cotton image P1 and the second-level cotton image P2 under the category P0 are classified.
4. A cotton ginning quality detection method according to claim 1, characterized in that: The improvements of the improved Yolov8 network include: adding the ECA attention mechanism to the original Yolov8 network; replacing the regression loss IoU function with the EIoU function; and changing the classification loss function to the Focal Loss function.
5. A cotton ginning quality detection method according to claim 4, characterized in that: The ECA attention mechanism is added to the end of the backbone network of the original Yolov8 network. The operation mechanism of the ECA attention mechanism includes: first, compressing the spatial dimension feature information through a global average pooling layer; then using a one-dimensional convolution layer with an adaptive convolution kernel k to achieve local cross-channel interaction; finally, normalizing the feature response to the channel attention weight through the Sigmoid function; where the adaptive convolution kernel k is expressed as: Where C represents the number of channels of input features; δ and b are hyperparameters; | | odd It means taking the absolute value and rounding down to the nearest odd number.
6. A cotton ginning quality detection method according to claim 4, characterized in that: The formula of the EIoU function is expressed as: Where w c and h c Represents the width and height of the minimum bounding rectangle of the predicted bounding box and the true bounding box respectively; ρ 2 (d,d gt ) represents the square of the Euclidean distance between the center point of the predicted bounding box and the true bounding box; ρ 2 (w,w gt ) represents the Euclidean width difference between the center point of the predicted bounding box and the true bounding box; ρ 2 (h,h gt ) represents the Euclidean height difference between the center point of the predicted bounding box and the true bounding box.
7. A cotton ginning quality detection method according to claim 4, characterized in that: The formula of the Focal Loss function is expressed as: FL(p t )=-a t (1-p t ) γ log(p t ) Where, P t Represents the model's predicted probability of the target class; α t is a balancing factor used to adjust the influence between positive and negative samples; γ is a focus factor used to adjust the weight of difficult and easy samples.
8. A cotton ginning quality detection system, characterized in that: include: an image acquisition module configured to acquire a cotton image dataset; a model training module configured to train a classification model based on an improved Yolov8 network based on a cotton image dataset; The quality classification module is configured to input the cotton image to be tested into the trained classification model for classification to obtain the cotton quality grade.
9. A cotton ginning quality detection system according to claim 8, characterized in that: The improvements of the improved Yolov8 network in the model training module include: adding the ECA attention mechanism to the original Yolov8 network; replacing the regression loss IoU function with the EIoU function; and modifying the classification loss function to the FocalLoss function.
10. A cotton ginning quality detection system according to claim 9, characterized in that: The operation mechanism of the ECA attention mechanism in the model training module includes: first compressing the spatial dimension feature information through a global average pooling layer; then using a one-dimensional convolution layer with an adaptive convolution kernel k to achieve local cross-channel interaction; finally, normalizing the feature response to the channel attention weight through a Sigmoid function; where the adaptive convolution kernel k is expressed as: Where C represents the number of channels of input features; δ and b are hyperparameters; | | odd It means taking the absolute value and rounding down to the nearest odd number; The formula of the EIoU function is expressed as: Where w c and h c Represents the width and height of the minimum bounding rectangle of the predicted bounding box and the true bounding box respectively; ρ 2 (d,d gt ) represents the square of the Euclidean distance between the center point of the predicted bounding box and the true bounding box; ρ 2 (w,w gt ) represents the Euclidean width difference between the center point of the predicted bounding box and the true bounding box; ρ 2 (h,h gt ) represents the Euclidean height difference between the center point of the predicted bounding box and the true bounding box; The formula of the Focal Loss function is expressed as: FL(p t )=-a t (1-p t ) γ log(p t ) Where, P t Represents the model's predicted probability of the target class; α t is a balancing factor used to adjust the influence between positive and negative samples; γ is a focus factor used to adjust the weight of difficult and easy samples.