YOLOv11-based cotton and linen fiber detection method, electronic equipment and storage medium

By combining adaptive threshold segmentation and morphological opening and closing operations with a combination of distribution functions and natural physical constraints to generate training sets, the YOLOv11 network is improved for cotton and linen fiber detection. This solves the problems of high manual annotation costs, insufficient data augmentation, and unbalanced training data in existing technologies, and achieves efficient and accurate cotton and linen fiber detection.

CN121921597APending Publication Date: 2026-04-24ZHEJIANG INSTITUTE OF QUALITY SCIENCES +1
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
ZHEJIANG INSTITUTE OF QUALITY SCIENCES
Filing Date
2026-01-12
Publication Date
2026-04-24

AI Technical Summary

Technical Problem

Existing cotton and linen fiber detection technologies suffer from problems such as high costs of manual labeling, insufficient diversity of traditional data augmentation methods, low utilization of unlabeled data, and easy imbalance in the distribution of training data, resulting in insufficient detection accuracy and efficiency.

Method used

Adaptive threshold segmentation and morphological opening and closing operations are used for boundary segmentation. A training set is generated by combining the combined distribution function and natural physical constraints. The improved YOLOv11 network is used for initial training, and outlier samples are screened through confidence screening and cluster analysis for iterative training. Finally, the model is fine-tuned by manual review.

Benefits of technology

It enables low-cost construction of training datasets, improves detection accuracy and efficiency, solves the problem of efficient extraction and accurate identification of fiber micro-features, reduces manual annotation costs, and expands the scale of training data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121921597A_ABST
    Figure CN121921597A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of machine vision, and provides a YOLOv11-based cotton and linen fiber detection method, electronic equipment and a storage medium, and the method comprises the following steps: identifying a detection model; the model construction process comprises image acquisition, image library construction, training set generation, primary training, network detection, image library expansion, secondary training, abnormal sample screening, error prediction image library construction and fine tuning training; according to the invention, through the set sample generation strategy, the training data set is constructed at low cost, the manpower input for labeling is greatly reduced, and the authenticity and diversity of the training sample are improved; through an unlabeled data iterative utilization strategy, the training data scale can be continuously expanded on the premise of not additionally increasing the manual labeling cost; through clustering verification and an abnormal sample manual review fine tuning strategy, the accuracy and stability of a model detection effect are improved; by improving the YOLOv11 network, efficient extraction and accurate identification of fiber microscopic features are realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of machine vision technology, and in particular to a method, electronic device and storage medium for detecting cotton and linen fibers based on YOLOv11. Background Technology

[0002] Cotton, flax, and ramie fibers, as typical natural fibers, occupy an important position in the textile industry due to their excellent breathability and moisture absorption. The accurate detection of their purity and type directly affects the quality and grading of textiles. Currently, the technological development in the field of cotton and flax fiber testing is transitioning from traditional manual testing to automated testing. Traditional testing methods mainly rely on manual observation combined with microscope assistance, requiring inspectors to judge and classify the morphology, texture, and cross-sectional characteristics of each fiber under a high-powered microscope. With the rise of machine vision and deep learning technologies, automated testing solutions are gradually replacing traditional manual methods. Deep learning models with convolutional neural networks at their core have become mainstream. For example, classification models such as VGG16 and ResNet are used for preliminary fiber category identification, while target detection models such as the YOLO series, due to their real-time advantages, are being tested in multi-fiber interweaving scenarios.

[0003] However, due to the inherent characteristics of cotton and linen fiber microscopic images—namely, small inter-class differences, diverse intra-class morphologies, and complex background noise—existing automated detection technologies still face numerous bottlenecks and struggle to meet the demands of high-precision, high-efficiency industrial-grade detection. Specifically, these limitations include: 1) High cost and low efficiency of manual annotation, relying heavily on specialized personnel and exhibiting unstable annotation accuracy: Annotating cotton and linen fiber microscopic images requires professionals with extensive knowledge of fiber morphology. Boundary boxes must be drawn and categories labeled for each individual fiber in the image, with annotation time potentially reaching several minutes per image. Large-scale dataset construction requires significant manpower. Furthermore, manual annotation is susceptible to subjective judgment; differences in fiber boundary and category judgments among annotators can lead to fluctuations in annotation accuracy, thus affecting model training performance. 2) Insufficient diversity of traditional data augmentation methods: Generated samples differ significantly from the natural distribution and crossover states of fibers in real fabrics, limiting model generalization ability. Commonly used methods such as rotation, flipping, and shrinking... Data augmentation techniques, such as scattering, can only simply change the posture and size of fibers, and cannot simulate the complex states of random interweaving, density distribution differences, and natural crossing angles of fibers in real fabrics; the difference between training samples and real detection scenarios makes the model prone to missed detections and false detections when facing real fabric samples; 3) the utilization rate of unlabeled data is low, and potential effective samples are not fully explored, resulting in difficulty in expanding the scale of the dataset and high construction costs: there are a large number of unlabeled microscopic images of cotton and linen fibers in real industrial scenarios. These images contain rich fiber morphological features, but existing technologies mostly use fully supervised training. The training mode does not make effective use of unlabeled data; if the dataset size is to be expanded, a lot of manpower needs to be continuously invested in labeling, which further increases the application cost; 4) The distribution of training data is prone to imbalance, which leads to biased learning of the model and limited generalization ability: In the process of building the existing dataset, there is a problem of uneven distribution of the number of different types of fiber samples and uneven distribution of different morphological fiber samples; when the model is trained on imbalanced data, it will be biased towards the category or morphology with a large number of samples, and the recognition accuracy of minority class samples and special morphological samples will be significantly reduced, which cannot adapt to the randomness of fiber distribution in actual industrial scenarios. Summary of the Invention

[0004] To overcome the shortcomings of existing technologies, the purpose of this invention is to provide a cotton and linen fiber detection method, electronic device, and storage medium based on YOLOv11, which solves the problems of high cost of manual annotation, insufficient diversity of traditional data augmentation methods, low utilization rate of unlabeled data, and easy imbalance in the distribution of training data in existing technologies.

[0005] To achieve the above objectives, the present invention provides the following solution: A method for detecting cotton and linen fibers based on YOLOv11, comprising: The microscopic image of the fabric sample to be tested is input into a pre-constructed cotton and linen fiber detection model for identification, thereby obtaining the cotton and linen fiber detection results; the cotton and linen fiber detection model construction process includes: A fiber slide for pre-collecting fabric samples was prepared, and images of the fiber slide were acquired using a microscope to obtain raw microscopic images; the pre-collected fabric samples consisted of cotton fibers, flax fibers, and ramie fibers; The original microscopic image is segmented using adaptive thresholding and morphological opening and closing operations to obtain fiber region maps. Each fiber region map is then annotated with a category to obtain a basic region map library. The basic region map library includes: a cotton fiber region map set, a flax fiber region map set, and a ramie fiber region map set. Define a combination distribution function and natural physical constraints, and use the combination distribution function and natural physical constraints to randomly combine the regional maps in the basic regional map library to obtain an initial training set; The improved YOLOv11 network was initially trained using the initial training set to obtain the initial trained network. The pre-collected unlabeled microscopic images were detected using the initial training network to obtain detection results; The fiber region map corresponding to the detection result whose confidence exceeds a set confidence threshold is updated to the basic region map library to obtain an expanded map library; The initial training network is trained a second time using the extended image library, and then the process is iteratively trained by returning to the step "using the initial training network to detect the pre-collected unlabeled microscopic images and obtain the detection results" to obtain the extended training network. Cluster analysis is performed on the prediction results output by the extended training network to obtain cluster data. Samples that do not meet the set clustering threshold in the cluster data are filtered out to obtain abnormal samples. The labels of the abnormal samples are manually reviewed, error predictions are filtered, and labels are annotated to obtain an error prediction library; The extended training network was fine-tuned using the error prediction library to obtain a cotton and linen fiber detection model.

[0006] Preferably, a fiber slide for pre-collecting fabric samples is prepared, and images of the fiber slide are acquired using a microscope to obtain raw microscopic images, including: Yarns were removed from the pre-collected fabric sample, and 30 segments of the yarn with a length of 10 cm were randomly selected to prepare fiber bundles. A fiber segment is cut from the middle of the fiber bundle using a fiber slicer; the length of the fiber segment ranges from 0.2 mm to 0.4 mm. The fiber fragments were placed on a first glass slide and liquid paraffin was added. The fiber fragments were stirred with tweezers to obtain a mixed sample. The mixed sample is evenly placed on the second glass slide and covered with a cover glass to obtain the fiber glass slide; The fiber slide is fixed on an electric stage, and the image of the fiber slide is acquired using a microscope at a magnification of 200x to obtain the original microscopic image.

[0007] Preferably, the original microscopic image is segmented using adaptive thresholding and morphological opening / closing operations to obtain fiber region maps, and each fiber region map is categorized to obtain a basic region map library, including: Adaptive threshold segmentation is performed on the original microscopic image based on a dynamically adjusted segmentation threshold to obtain an initial segmentation mask; the expression for the dynamically adjusted segmentation threshold is: ;in, For pixels The segmentation threshold at the point; The average gray level within the pixel's neighborhood; This is the adjustment coefficient; The standard deviation of the gray level in the neighborhood; The initial segmentation mask is subjected to dilation and erosion operations in sequence to obtain the fiber region map; The fiber region map is annotated with categories using the labelme software, and the fiber region map is classified according to the annotation results to obtain the basic region map library; the types of fiber region maps include any one of cotton fiber, flax fiber, and ramie fiber.

[0008] Preferably, the combined distribution function includes: , ;in, Fiber density distribution; The standard deviation of density; The number of combinations of fiber region maps in a single image; The average fiber density of the actual fabric sample; Fiber angular distribution; The angle is the rotation angle.

[0009] Preferably, the natural physical constraints include: , ;in, For the intersection angle; , , respectively, are the rotation angles of the i-th and j-th fibers; The distance between the center points of the fibers; Let x and y be the x and y coordinates of the i-th fiber; This represents the average diameter of the corresponding fiber.

[0010] Preferably, the improved YOLOv11 network is initially trained using the initial training set to obtain an initial trained network, including: Construct the original YOLOv11 network; A RepVGG-C3K2 module is constructed; the RepVGG-C3K2 module includes: a first convolutional layer, a second convolutional layer, a RepVGG layer, a feature concatenation layer, and a third convolutional layer; the first convolutional layer, the RepVGG layer, the feature concatenation layer, and the third convolutional layer are connected sequentially; the second convolutional layer is connected to the first convolutional layer and the feature concatenation layer respectively; the RepVGG layer includes: a plurality of cascaded RepVGGBlocks; Construct an LTDW-BiFPN module; the LTDW-BiFPN module includes: parallel top-down paths and bottom-up paths; wherein, the expression of the top-down path includes: ;in, The features of the fifth layer after fusion in the top-down path; For depthwise separable convolution; , These are the first learnable fusion weight and the second learnable fusion weight, respectively. For scale alignment operations; These are the original input features for the fifth layer; The input features for the sixth layer; The preset positive integer; The expression for the bottom-up path includes: ;in, This refers to the fused output features from the bottom-up path in the fifth layer; , , These are the first-path feature learnable fusion weights, the second-path feature learnable fusion weights, and the third-path feature learnable fusion weights, respectively. This represents the output features of the fourth layer in the bottom-up path. The improved YOLOv11 network is obtained by replacing the C3K2 module of the original YOLOv11 network with the RepVGG-C3K2 module, replacing the PAPPN module of the original YOLOv11 network with the LTDW-BiFPN module, and embedding the CBAM attention mechanism in front of the detection head of the original YOLOv11 network. The improved YOLOv11 network is iteratively trained using the SIOU loss function based on the initial training set to obtain the initial training network.

[0011] Preferably, the expression for the confidence threshold is: ;in, The conservative confidence threshold; The average confidence score of the validation set during the initial training phase; For safety factor; The standard deviation is the confidence level.

[0012] Preferably, cluster analysis is performed on the prediction results output by the extended training network to obtain clustered data. Samples in the clustered data that do not meet a set clustering threshold are then filtered out to obtain abnormal samples, including: All samples from the extended image library are input into the trained extended training network to obtain the data to be clustered; Collect the feature vectors output by the extended training network during the identification process of the data to be clustered; The K-Means algorithm is used to cluster the feature vectors with the same label to obtain cluster centers; Extract the distance between each feature vector and the cluster center corresponding to that feature vector to obtain a deviation value; the expression for the deviation value is: ;in, The deviation value; Let t be the t-th component of the i-th eigenvector; The t-th dimension component of the q-th cluster center; For the overall dimension; The abnormal samples are obtained by filtering out samples whose deviation values ​​exceed a set distance threshold.

[0013] Preferably, an electronic device includes: at least one processor and a memory communicatively connected to the processor; wherein the memory stores instructions executable by the processor, the instructions being executed by the processor to enable the processor to perform the aforementioned YOLOv11-based cotton and linen fiber detection method.

[0014] Preferably, a non-transitory computer-readable storage medium stores computer instructions for causing a computer to execute the aforementioned YOLOv11-based cotton and linen fiber detection method.

[0015] The present invention discloses the following technical effects: This invention provides a cotton and linen fiber detection method, electronic device, and storage medium based on YOLOv11. By establishing a sample generation strategy, it solves the problems of high cost, low efficiency, unstable accuracy, and insufficient diversity in traditional data augmentation methods, achieving low-cost construction of training datasets. Through an iterative utilization strategy of unlabeled data, it addresses the low utilization rate of unlabeled data in existing technologies, enabling continuous expansion of training data scale without increasing manual annotation costs. Through clustering verification and manual review and fine-tuning of outlier samples, it solves the problems of hidden erroneous prediction samples and insufficient detection reliability in existing models after training, achieving accurate error correction and optimization of model prediction results. By improving the YOLOv11 network, it addresses the problems of insufficient ability to extract subtle features of cotton and linen fibers and limited detection accuracy in scenarios with small inter-class differences and complex background noise, achieving efficient extraction and accurate identification of fiber micro-features. Attached Figure Description

[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in 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.

[0017] Figure 1 This is a schematic diagram of the cotton and linen fiber detection process based on YOLOv11 provided in an embodiment of the present invention; Figure 2 This is a schematic diagram illustrating the basic region map library construction process provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the abnormal sample screening process provided in an embodiment of the present invention; Figure 4 An improved YOLOv11 network structure diagram provided in an embodiment of the present invention; Figure 5 The diagram shows the structure of the CBAM attention mechanism provided in this embodiment of the invention. Detailed Implementation

[0018] 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.

[0019] The purpose of this invention is to provide a cotton and linen fiber detection method, electronic device and storage medium based on YOLOv11, which solves the problems of high cost of manual annotation, insufficient diversity of traditional data augmentation methods, low utilization of unlabeled data and easy imbalance of training data distribution in the prior art.

[0020] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0021] Figure 1 This is a schematic diagram of the cotton and linen fiber detection process based on YOLOv11 provided in an embodiment of the present invention, as shown below. Figure 1 As shown, this invention provides a method for detecting cotton and linen fibers based on YOLOv11, comprising: Step 100: Input the microscopic image of the fabric sample to be tested into the pre-constructed cotton and linen fiber detection model for identification to obtain the cotton and linen fiber detection results; the cotton and linen fiber detection model construction process includes: Step 101: Prepare a fiber slide for pre-collecting the fabric sample, and acquire an image of the fiber slide using a microscope to obtain the original microscopic image; the pre-collected fabric sample is composed of cotton fiber, flax fiber, and ramie fiber; Step 102: Perform boundary segmentation on the original microscopic image using adaptive threshold segmentation and morphological opening and closing operations to obtain fiber region maps, and annotate each fiber region map with a category to obtain a basic region map library; the basic region map library includes: cotton fiber region map set, flax fiber region map set, and ramie fiber region map set; Step 103: Set the combined distribution function and natural physical constraints, and use the combined distribution function and natural physical constraints to randomly combine the regional maps in the basic regional map library to obtain the initial training set; Step 104: Use the initial training set to perform initial training on the improved YOLOv11 network to obtain the initial training network; Step 105: Use the pre-trained network to detect the pre-collected unlabeled microscopic images and obtain the detection results; Step 106: Update the fiber region map corresponding to the detection results whose confidence exceeds the set confidence threshold to the basic region map library to obtain the extended map library; Step 107: Use the extended image library to perform secondary training on the initial training network, and return to step "Use the initial training network to detect the pre-collected unlabeled microscopic images and obtain the detection results" for iterative training to obtain the extended training network; Step 108: Perform cluster analysis on the prediction results output by the extended training network to obtain cluster data, and filter out samples in the cluster data that do not meet the set clustering threshold to obtain abnormal samples; Step 109: Manually review the labels of the abnormal samples, filter out incorrect predictions, and annotate the labels to obtain an incorrect prediction library; Step 110: Fine-tune the extended training network using the error prediction library to obtain the cotton and linen fiber detection model.

[0022] Further, fiber slides for pre-collecting fabric samples are prepared, and images of the fiber slides are acquired using a microscope to obtain raw microscopic images, including: Yarns were removed from the pre-collected fabric sample, and 30 segments of the yarn with a length of 10 cm were randomly selected to prepare fiber bundles. A fiber segment is cut from the middle of the fiber bundle using a fiber slicer; the length of the fiber segment ranges from 0.2 mm to 0.4 mm. The fiber fragments were placed on a first glass slide and liquid paraffin was added. The fiber fragments were stirred with tweezers to obtain a mixed sample. The mixed sample is evenly placed on the second glass slide and covered with a cover glass to obtain the fiber glass slide; The fiber slide is fixed on an electric stage, and the image of the fiber slide is acquired using a microscope at a magnification of 200x to obtain the original microscopic image.

[0023] refer to Figure 2 The original microscopic image is segmented using adaptive thresholding and morphological opening / closing operations to obtain fiber region maps. Each fiber region map is then annotated with a category to create a basic region map library, including: Step 10201: Perform adaptive threshold segmentation on the original microscopic image according to the dynamically adjusted segmentation threshold to obtain an initial segmentation mask; the expression for the dynamically adjusted segmentation threshold is: ;in, For pixels The segmentation threshold at the point; The average gray level within the pixel's neighborhood; This is the adjustment coefficient; The standard deviation of the gray level in the neighborhood; Step 10202: Perform dilation and erosion operations sequentially on the initial segmentation mask to obtain the fiber region map; Step 10203: Use labelme software to annotate the fiber region map by category, and classify the fiber region map according to the annotation results to obtain the basic region map library; the types of the fiber region map include any one of cotton fiber, flax fiber, and ramie fiber.

[0024] Furthermore, the combined distribution function includes: , ;in, Fiber density distribution; The standard deviation of density; The number of combinations of fiber region maps in a single image; The average fiber density of the actual fabric sample; Fiber angular distribution; The angle is the rotation angle.

[0025] Specifically, the natural physical constraints include: , ;in, For the intersection angle; , , respectively, are the rotation angles of the i-th and j-th fibers; The distance between the center points of the fibers; Let x and y be the x and y coordinates of the i-th fiber; This represents the average diameter of the corresponding fiber.

[0026] Furthermore, the improved YOLOv11 network is initially trained using the initial training set to obtain the initial trained network, including: Construct the original YOLOv11 network; A RepVGG-C3K2 module is constructed; the RepVGG-C3K2 module includes: a first convolutional layer, a second convolutional layer, a RepVGG layer, a feature concatenation layer, and a third convolutional layer; the first convolutional layer, the RepVGG layer, the feature concatenation layer, and the third convolutional layer are connected sequentially; the second convolutional layer is connected to the first convolutional layer and the feature concatenation layer respectively; the RepVGG layer includes: a plurality of cascaded RepVGGBlocks; Construct an LTDW-BiFPN module; the LTDW-BiFPN module includes: parallel top-down paths and bottom-up paths; wherein, the expression of the top-down path includes: ;in, The features of the fifth layer after fusion in the top-down path; For depthwise separable convolution; , These are the first learnable fusion weight and the second learnable fusion weight, respectively. For scale alignment operations; These are the original input features for the fifth layer; The input features for the sixth layer; The preset positive integer; The expression for the bottom-up path includes: ;in, This refers to the fused output features from the bottom-up path in the fifth layer; , , These are the first-path feature learnable fusion weights, the second-path feature learnable fusion weights, and the third-path feature learnable fusion weights, respectively. This represents the output features of the fourth layer in the bottom-up path. The improved YOLOv11 network is obtained by replacing the C3K2 module of the original YOLOv11 network with the RepVGG-C3K2 module, replacing the PAPPN module of the original YOLOv11 network with the LTDW-BiFPN module, and embedding the CBAM attention mechanism in front of the detection head of the original YOLOv11 network. The improved YOLOv11 network is iteratively trained using the SIOU loss function based on the initial training set to obtain the initial training network.

[0027] Specifically, the expression for the confidence threshold is: ;in, The conservative confidence threshold; The average confidence score of the validation set during the initial training phase; For safety factor; The standard deviation is the confidence level.

[0028] refer to Figure 3 Cluster analysis is performed on the prediction results output by the extended training network to obtain cluster data. Samples in the cluster data that do not meet the set clustering threshold are then filtered out to obtain abnormal samples, including: Step 10801: Input all samples from the extended image library into the trained extended training network to obtain the data to be clustered; Step 10802: Collect the feature vector output by the extended training network during the identification process of the data to be clustered; Step 10803: Use the K-Means algorithm to cluster the feature vectors with the same label to obtain cluster centers; Step 10804: Extract the distance between each feature vector and the cluster center corresponding to the feature vector to obtain the deviation value; the expression for the deviation value is: ;in, The deviation value; Let t be the t-th component of the i-th eigenvector; The t-th dimension component of the q-th cluster center; For the overall dimension; Step 10805: Filter samples whose deviation values ​​exceed the set distance threshold to obtain the abnormal samples.

[0029] Specifically, the dataset construction is divided into four stages: basic region map construction, constraint-based combined dataset generation, semi-supervised region map expansion, and cluster-guided manual review. Basic fiber region map construction: First, yarns are extracted from a 10cm×10cm fabric sample containing cotton, flax, and ramie fibers. Thirty 10cm yarn segments are randomly selected and combined to form a fiber bundle. Next, fiber fragments of 0.2mm to 0.4mm in length are cut from the middle of the fiber bundle using a fiber slicer. These fragments are placed on a glass slide, and a suitable amount of liquid paraffin is added as a dispersion medium. The slide is gently stirred with tweezers to promote uniform fiber distribution. Then, a suitable amount of this mixed sample is placed on a glass slide, spread evenly, and covered with a coverslip to complete the fiber slide preparation. Finally, the slide is fixed on the motorized stage of an optical microscope, and the magnification is set to 200x. The control system drives the motor platform to move automatically, and an industrial camera works synchronously with the computer system to record and save the fiber images within the field of view.

[0030] Furthermore, individual fiber regions are extracted through boundary segmentation to construct a well-defined basic region map library. Specific steps include: performing boundary segmentation on the acquired multi-fiber microscopic images using adaptive thresholding and morphological opening / closing operations. The segmentation threshold is dynamically adjusted based on the local gray-level mean of the image, as shown in the following formula: .

[0031] By filling the pores in the fiber regions with expansion and then removing minute noise through erosion, a complete mask for each individual fiber region is obtained. The segmented individual fiber region images are then labeled with their categories (cotton fiber / linen fiber / ramie fiber) using LabelMe software, establishing a basic region image library for these three fiber categories. ,in, This is a collection of cotton fiber region maps. A collection of flax fiber region maps. This is a collection of ramie fiber region maps.

[0032] Preferably, based on a basic regional map library By randomly combining training samples that conform to natural physical properties, the problem of fiber distribution diversity in real-world scenarios can be solved. 1) Define the combined distribution function: To ensure that the combined sample is consistent with the actual fabric fiber distribution, two types of core distribution functions are designed: Fiber density distribution: The number of fibers in a single image is described using a normal distribution, as shown in the following formula: .

[0033] Fiber angular distribution: A uniform distribution is used to describe fiber orientation, as shown in the following formula: in, The rotation angle of the fiber region map is used to simulate the random orientation characteristics of natural fibers.

[0034] 2) Imposing natural physical constraints: The physical properties of the fibers must be satisfied during the assembly process to avoid distribution states that do not conform to reality. Crossing angle constraint: The formula for the crossing angle of any two fibers is as follows: in, , The rotation angle between the two fibers is used to avoid the fibers being too parallel or perpendicular, which would not conform to the natural interweaving characteristics of fibers.

[0035] Spacing constraint: The fiber center spacing satisfies: .

[0036] Length ratio constraint: Limits the ratio range of the displayed length of a single fiber after combination to the length of the original area map to ensure that the fiber morphology is not excessively distorted.

[0037] 3) Generate combined samples: Write a combination function and input the base region map library. The distribution function parameters and physical constraints are defined. A fiber region map is randomly selected, and its location is assigned (image size 640×640, random coordinates must be set so that the fiber is completely within the image). After angle rotation and scaling adjustments, the data are superimposed to generate combined samples. The combined dataset generated in each training round must satisfy the requirement of distribution function diversity, i.e., changing the distribution function parameters. , The value of is chosen to avoid a single distribution of training data.

[0038] refer to Figure 4 and Figure 5An improved YOLOv11 object detection model was constructed by introducing the RepVGG-C3K2 module into the backbone network and the LTDW-BiFPN module into the neck network, and adding a CBAM attention mechanism to the detection head. To address the issue of existing methods failing to balance accuracy and speed, the RepVGG-C3K2 module was introduced into the YOLOv11 backbone network, replacing the C3K2 module in the backbone network. This RepVGG-C3K2 module, by incorporating the ideas of RepVGG and utilizing structural reparameterization, improves the model's ability to recognize micro-texture details while significantly reducing inference complexity.

[0039] Furthermore, the structure of the RepVGG-C3K2 module is as follows: 1) Input processing: The input feature map is first processed through a 1×1 convolutional layer to perform preliminary feature transformation and channel number adjustment.

[0040] 2) Feature Splitting: The feature map processed by the 1×1 convolutional layer is split into two paths. One path inputs the processed feature map into the RepVGGBlock module for deep processing. The RepVGGBlock module uses three parallel branches during training: a 3×3 convolutional path for extracting local spatial features, a 1×1 convolutional path for channel information fusion, and an identity mapping path for information preservation and gradient stabilization. Each branch is followed by a batch normalization (BN) layer. After training, leveraging the linear additivity of convolutions and the equivalent transformation of BN layers during inference, the multi-branch structure can be reparameterized into a single 3×3 convolutional layer, simplifying the model structure, significantly improving inference efficiency, and forming a lightweight network with VGG style characteristics.

[0041] 3) Feature concatenation: The feature maps output from the two paths are concatenated along the channel dimension to combine the features obtained from the two different processing methods, thereby enriching the diversity of features.

[0042] 4) Feature integration and output: The concatenated feature map is further integrated and optimized through another 1×1 convolutional layer, such as adjusting the number of channels and enhancing feature expression, to obtain the final output feature map.

[0043] Preferably, to address the challenge of recognizing the fine, long, and intricate textures of cotton and linen fibers, the LTDW-BiFPN module is introduced into the YOLOv11 neck network to replace the original PAFPN module. This module effectively fuses the feature maps output by the backbone network, highlighting the texture and contour information of cotton and linen fibers, while effectively suppressing background noise and significantly reducing computational costs while maintaining detection accuracy. The structure of LTDW-BiFPN is as follows: 1) Input feature map: Discard the P7 feature map, which has the lowest resolution and the most channels and is usually used to detect targets with extremely large scales. All input features are first adjusted to the same number of channels and appropriate spatial size by 1×1 convolution and up / downsampling operations.

[0044] 2) Top-down path: fusing features from high-level features downwards. Taking the feature map of layer P5 as an example, its expression is: 3) Bottom-up path: This involves fusing features from lower levels upwards, and its expression is: in , , , , These are learnable weight parameters used to determine the importance of each input feature map; The divisor is a small positive integer, and it is guaranteed that the divisor is not zero.

[0045] 4) Output feature map: The output is still a multi-scale feature map. Each output layer has the same number of channels, and the features after bidirectional fusion are enhanced in both semantics and details. They can be directly fed into the detection head for classification and localization.

[0046] Optionally, to address redundant features in complex backgrounds, a CBAM attention mechanism is added before the output of the YOLOv11 detection head. Through the channel-spatial attention mechanism, the final output features are significantly enhanced in discriminative ability, thereby improving the accuracy and robustness of the detection results. The CBAM attention mechanism structure is as follows: 1) Input Features: The feature map extracted by the detection head convolutional layer is denoted as the input feature map of the CBAM module. ,in, Represents the number of channels, height, and width, respectively. 2) Channel Attention Module: Global feature extraction: extracting features from the input feature map along the spatial dimension. Performing global max pooling and global average pooling yields two different channel descriptors. and All shapes Shared Multilayer Perceptron (MLP): The two types of channel descriptors mentioned above are input into a multilayer perceptron with shared parameters. This MLP consists of two fully connected layers. The first layer compresses the channel dimension to reduce computational overhead, and the second layer restores the original channel dimension, outputting channel attention feature maps. and Feature fusion and weight generation: The two feature maps are added element-wise, and channel attention weights are generated using the Sigmoid activation function. Used to adaptively adjust the importance of each channel.

[0047] Channel weighting: weighting With input feature map Channel-by-channel multiplication yields the enhanced feature map. .

[0048] 3) Spatial Attention Module: Feature projection: Enhancing the feature map of a channel along the channel dimension. Max pooling and average pooling are performed separately to obtain two two-dimensional feature maps. and All shapes .

[0049] Feature fusion and convolution: Two feature maps are concatenated along their channel dimensions and then input into a single convolutional layer. Convolutional layers capture global and local spatial context information and output spatial attention feature maps. .

[0050] Spatial weighting: Incorporating spatial attention maps With channel enhancement feature map Pixel-by-pixel multiplication yields the final weighted feature map. .

[0051] Output features: Feature maps output by the CBAM module Convolutional mapping to Dimension, in which Indicates the number of categories. This indicates the number of anchor frames, ultimately yielding the prediction result from the detection head.

[0052] Optionally, the hyperparameters and optimizer settings are as follows: input images are uniformly scaled to 640×640; batch size is set to 16; SGD is selected as the optimizer, with an initial learning rate of 0.001 and cosine annealing used for learning rate scheduling; the number of training epochs is 300, and an early stopping strategy is adopted to terminate training early when the performance index no longer improves within 20 epochs; the weight decay coefficient is 0.0005; and the momentum is 0.937. Forward propagation calculation: batch images from the training set are input into the improved YOLOv11 network. Features are extracted through the backbone network, fused through the neck network, and then the detection head outputs the class probability, target confidence, and bounding box coordinates for each predicted box. Loss function design and calculation: the SIOU loss function is used to calculate the difference between the predicted box and the ground truth box, and the total loss value is obtained by combining the confidence loss and class loss. Backpropagation and parameter optimization: the gradient of the network parameters is calculated using the backpropagation algorithm, and the parameters are iteratively updated using the set optimizer to minimize the loss function, gradually improving the detection accuracy of the model, and obtaining a converged detection model.

[0053] Preferably, the semi-supervised region image library is expanded by introducing an unlabeled set of microscopic images. High-confidence samples are selected from the initially trained model to expand the basic regional map library. Specific steps: 1) Unlabeled image preprocessing: Preprocessing unlabeled image sets Perform size adjustment (640×640) and normalization; 2) High-confidence sample selection: The preprocessed unlabeled images are input into the initially trained improved YOLOv11 model, and the detection results (including predicted bounding boxes, categories, and confidence scores) are output. Set a conservative confidence threshold. Filter to meet Test results: .

[0054] 3) Region map extraction and update: For the selected high-confidence detection results, perform boundary segmentation based on the predicted bounding box, extract individual fiber region maps, match them with the predicted categories, and add them to the basic region map library. In this process, an expanded regional map library is formed. ,in Add a set of high-confidence region maps.

[0055] Furthermore, cluster analysis is performed on the prediction results of the combined dataset, outlier samples are screened and manually reviewed, and high-quality labeled data is added: all samples generated by the combination are input into the trained model, and the output is a local region map with prediction boxes and prediction labels. ( (The number of local region maps); directly use the feature vectors output by the previously trained model. ( (As the feature dimension, output by the improved YOLOv11 backbone network), the K-Means algorithm is used to cluster feature vectors with the same label to obtain cluster centers. ( For the number of categories, here ); Calculate the Euclidean distance between each feature vector and its corresponding cluster center: Set distance threshold Filter out An abnormal local area diagram.

[0056] The abnormal area maps are manually reviewed to correct erroneous prediction labels. The corrected area maps are then compiled into an error prediction map library. The trained model is then fine-tuned using the error prediction map library. The output model is then used as the final detection model in the subsequent cotton and linen fiber detection process.

[0057] As an optional implementation, this embodiment also provides an electronic device, including: at least one processor, and a memory communicatively connected to the processor; wherein the memory stores instructions executable by the processor, the instructions being executed by the processor to enable the processor to perform the aforementioned YOLOv11-based cotton and linen fiber detection method.

[0058] As an optional implementation, this embodiment also provides a non-transitory computer-readable storage medium storing computer instructions for causing a computer to execute the aforementioned YOLOv11-based cotton and linen fiber detection method.

[0059] The beneficial effects of this invention are as follows: This invention achieves low-cost construction of training datasets through a set sample generation strategy, significantly reducing the manpower required for annotation and improving the authenticity and diversity of training samples; through an unlabeled data iterative utilization strategy, the scale of training data can be continuously expanded without increasing the cost of manual annotation; through clustering verification and manual review and fine-tuning of abnormal samples, the accuracy and stability of model detection are improved; and through improvements to the YOLOv11 network, efficient extraction and accurate identification of fiber micro-features are achieved.

[0060] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.

[0061] This document uses specific examples to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. Furthermore, those skilled in the art will recognize that, based on the ideas of the present invention, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A method for detecting cotton and linen fibers based on YOLOv11, characterized in that, include: The microscopic image of the fabric sample to be tested is input into the pre-constructed cotton and linen fiber detection model for identification, and the cotton and linen fiber detection results are obtained. The process for constructing the cotton and linen fiber detection model includes: A fiber slide for pre-collecting fabric samples was prepared, and images of the fiber slide were acquired using a microscope to obtain raw microscopic images; the pre-collected fabric samples consisted of cotton fibers, flax fibers, and ramie fibers; The original microscopic image is segmented using adaptive thresholding and morphological opening and closing operations to obtain fiber region maps. Each fiber region map is then annotated with a category to obtain a basic region map library. The basic region map library includes: a cotton fiber region map set, a flax fiber region map set, and a ramie fiber region map set. Define a combination distribution function and natural physical constraints, and use the combination distribution function and natural physical constraints to randomly combine the regional maps in the basic regional map library to obtain an initial training set; The improved YOLOv11 network was initially trained using the initial training set to obtain the initial trained network. The pre-collected unlabeled microscopic images were detected using the initial training network to obtain detection results; The fiber region map corresponding to the detection result whose confidence exceeds a set confidence threshold is updated to the basic region map library to obtain an expanded map library; The initial training network is trained a second time using the extended image library, and then the process is iteratively trained by returning to the step "using the initial training network to detect the pre-collected unlabeled microscopic images and obtain the detection results" to obtain the extended training network. Cluster analysis is performed on the prediction results output by the extended training network to obtain cluster data. Samples that do not meet the set clustering threshold in the cluster data are filtered out to obtain abnormal samples. The labels of the abnormal samples are manually reviewed, error predictions are filtered, and labels are annotated to obtain an error prediction library; The extended training network was fine-tuned using the error prediction library to obtain a cotton and linen fiber detection model.

2. The method for detecting cotton and linen fibers based on YOLOv11 according to claim 1, characterized in that, Prepare fiber slides for collecting fabric samples, and acquire images of the fiber slides using a microscope to obtain raw microscopic images, including: Yarns were removed from the pre-collected fabric sample, and 30 segments of the yarn with a length of 10 cm were randomly selected to prepare fiber bundles. A fiber segment is cut from the middle of the fiber bundle using a fiber slicer; the length of the fiber segment ranges from 0.2 mm to 0.4 mm. The fiber fragments were placed on a first glass slide and liquid paraffin was added. The fiber fragments were stirred with tweezers to obtain a mixed sample. The mixed sample is evenly placed on the second glass slide and covered with a cover glass to obtain the fiber glass slide; The fiber slide is fixed on an electric stage, and the image of the fiber slide is acquired using a microscope at a magnification of 200x to obtain the original microscopic image.

3. The method for detecting cotton and linen fibers based on YOLOv11 according to claim 1, characterized in that, The original microscopic image is segmented using adaptive thresholding and morphological opening / closing operations to obtain fiber region maps. Each fiber region map is then annotated with a category to create a basic region map library, including: Adaptive threshold segmentation is performed on the original microscopic image based on a dynamically adjusted segmentation threshold to obtain an initial segmentation mask; the expression for the dynamically adjusted segmentation threshold is: ;in, For pixels The segmentation threshold at the point; The average gray level within the pixel's neighborhood; This is the adjustment coefficient; The standard deviation of the gray level in the neighborhood; The initial segmentation mask is subjected to dilation and erosion operations in sequence to obtain the fiber region map; The fiber region map is annotated with categories using the labelme software, and the fiber region map is classified according to the annotation results to obtain the basic region map library; the types of fiber region maps include any one of cotton fiber, flax fiber, and ramie fiber.

4. The method for detecting cotton and linen fibers based on YOLOv11 according to claim 1, characterized in that, The combined distribution function includes: , ;in, Fiber density distribution; The standard deviation of density; The number of combinations of fiber region maps in a single image; The average fiber density of the actual fabric sample; Fiber angular distribution; The angle is the rotation angle.

5. The method for detecting cotton and linen fibers based on YOLOv11 according to claim 1, characterized in that, The natural physical constraints include: , ;in, For the intersection angle; , , respectively, are the rotation angles of the i-th and j-th fibers; The distance between the center points of the fibers; Let x and y be the x and y coordinates of the i-th fiber; This represents the average diameter of the corresponding fiber.

6. The method for detecting cotton and linen fibers based on YOLOv11 according to claim 1, characterized in that, The improved YOLOv11 network is initially trained using the initial training set to obtain the initial trained network, which includes: Construct the original YOLOv11 network; A RepVGG-C3K2 module is constructed; the RepVGG-C3K2 module includes: a first convolutional layer, a second convolutional layer, a RepVGG layer, a feature concatenation layer, and a third convolutional layer; the first convolutional layer, the RepVGG layer, the feature concatenation layer, and the third convolutional layer are connected sequentially; the second convolutional layer is connected to the first convolutional layer and the feature concatenation layer respectively; the RepVGG layer includes: a plurality of cascaded RepVGGBlocks; Construct an LTDW-BiFPN module; the LTDW-BiFPN module includes: parallel top-down paths and bottom-up paths; wherein, the expression of the top-down path includes: ;in, The features of the fifth layer after fusion in the top-down path; For depthwise separable convolution; , These are the first learnable fusion weight and the second learnable fusion weight, respectively. For scale alignment operations; These are the original input features for the fifth layer; The input features for the sixth layer; The preset positive integer; The expression for the bottom-up path includes: ;in, This refers to the fused output features from the bottom-up path in the fifth layer; , , These are the first-path feature learnable fusion weights, the second-path feature learnable fusion weights, and the third-path feature learnable fusion weights, respectively. This represents the output features of the fourth layer in the bottom-up path. The improved YOLOv11 network is obtained by replacing the C3K2 module of the original YOLOv11 network with the RepVGG-C3K2 module, replacing the PAPPN module of the original YOLOv11 network with the LTDW-BiFPN module, and embedding the CBAM attention mechanism in front of the detection head of the original YOLOv11 network. The improved YOLOv11 network is iteratively trained using the SIOU loss function based on the initial training set to obtain the initial training network.

7. The method for detecting cotton and linen fibers based on YOLOv11 according to claim 1, characterized in that, The expression for the confidence threshold is: ;in, The conservative confidence threshold; The average confidence score of the validation set during the initial training phase; For safety factor; The standard deviation is the confidence level.

8. The method for detecting cotton and linen fibers based on YOLOv11 according to claim 1, characterized in that, Cluster analysis is performed on the prediction results output by the extended training network to obtain clustered data. Samples in the clustered data that do not meet the set clustering threshold are then filtered out to obtain outlier samples, including: All samples from the extended image library are input into the trained extended training network to obtain the data to be clustered; Collect the feature vectors output by the extended training network during the identification process of the data to be clustered; The K-Means algorithm is used to cluster the feature vectors with the same label to obtain cluster centers; Extract the distance between each feature vector and the cluster center corresponding to that feature vector to obtain a deviation value; the expression for the deviation value is: ;in, The deviation value; Let t be the t-th component of the i-th eigenvector; The t-th dimension component of the q-th cluster center; For the overall dimension; The abnormal samples are obtained by filtering out samples whose deviation values ​​exceed a set distance threshold.

9. An electronic device, characterized in that, include: At least one processor, and a memory communicatively connected to the processor; wherein the memory stores instructions executable by the processor, the instructions being executed by the processor to enable the processor to perform a cotton and linen fiber detection method based on YOLOv11 according to any one of claims 1 to 8.

10. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to execute the cotton and linen fiber detection method based on YOLOv11 according to any one of claims 1 to 8.