Cloth flaw detection method and system based on MAC-YOLO
By constructing a MAC-YOLO network and combining morphological preprocessing, dynamic multi-scale pooling, and attention mechanisms, the problems of detection accuracy and real-time performance for slender and small-scale defects in fabric defect detection were solved, achieving efficient fabric defect detection.
Patent Information
- Application Number
- CN202510849975.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-24
- Publication Date
- 2025-11-18
AI Technical Summary
Existing technologies struggle to effectively detect elongated and small-scale defects on fabric surfaces, and feature extraction and multi-scale fusion in images with extreme aspect ratios present challenges, resulting in low detection accuracy and insufficient real-time performance.
A MAC-YOLO network is constructed, employing a morphological fusion preprocessing block, dynamic multi-scale strip pooling, and a dynamic separable kernel attention mechanism, combined with a multi-scale enhanced CSP module to optimize the feature extraction and fusion process.
It significantly improves the detection accuracy and real-time performance of defects in fabric images with extreme aspect ratios, enhances the ability to express the features of slender and small-scale defects, and meets the real-time detection needs of industrial production lines.
Smart Images

Figure CN120976097A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of fabric defect detection and deep learning technology, specifically to a fabric defect detection method and system based on MAC-YOLO. Background Technology
[0002] In the textile production process, the detection of fabric surface defects plays a crucial role in ensuring product quality. Fabric defects arise from various causes, such as mechanical failures, yarn problems, and improper operation during production. Common defect types include warp breaks, weft breaks, slippage, and stains. Traditional fabric defect detection methods mainly rely on manual inspection. This approach is not only inefficient and costly but also easily influenced by the subjective factors of the inspectors, making it difficult to meet the high-speed, high-precision production demands of modern textile industry.
[0003] With the continuous development of deep learning technology, object detection methods based on convolutional neural networks have been widely used in the field of fabric defect detection. However, fabric images captured by industrial cameras often have extreme aspect ratios, which poses many challenges to deep learning-based detection methods. On the one hand, traditional fixed-size convolutional kernels are difficult to effectively capture defect features of different scales and shapes, resulting in low detection accuracy for slender defects. On the other hand, the complex texture structure of fabrics can easily interfere with the extraction of defect features, making it easy to miss or misjudge small target defects. In addition, existing methods often struggle to achieve a good balance between detection accuracy and real-time performance, failing to meet the requirements of real-time detection on industrial production lines.
[0004] Specifically, existing technologies face the following challenges: For fabric defects with specific morphological characteristics, such as lateral loose seams and longitudinal broken warp threads, conventional convolutional neural networks struggle to simultaneously extract both global structural features and local detail features; for small-scale anomalies such as creases and stains, existing methods lack effective texture separation mechanisms; and in terms of multi-scale feature fusion, traditional methods struggle to achieve dynamic adaptive fusion of lateral and longitudinal features. These problems severely limit the accuracy and practicality of fabric defect detection.
[0005] To address the aforementioned issues, existing technologies urgently need improvement. Summary of the Invention
[0006] In view of the shortcomings of the existing technology, the purpose of this invention is to provide a fabric defect detection method based on MAC-YOLO.
[0007] To achieve the above objectives, the present invention provides the following technical solution: a fabric defect detection method based on MAC-YOLO, comprising the following steps:
[0008] (1) Constructing a MAC-YOLO network, which is an improvement on the YOLOv8 network, specifically including:
[0009] a. The Morphological Fusion Preprocessing Block (MFPB) is used as the first module of the network input layer;
[0010] b. The Dynamic Multi-Scale Strip Pooling (DMS-SP) module is used to replace some of the convolutional layers of the original YOLOv8 network;
[0011] c. Employ a Dynamically Separable Kernel Attention (DSKA) mechanism integrated into the multi-scale feature fusion path;
[0012] d. Replace the original YOLOv8 SPPF module with a multi-scale enhancement CSP module (MSECSP) integrating DMS-SP and DSKA;
[0013] (2) Collect fabric surface image datasets, label defect images with defect types (including broken warp, double warp, broken weft, weft band, tight weft, loose weft, crease and background, a total of 8 categories), and randomly divide the dataset into training set and test set in an 8:2 ratio;
[0014] (3) The MAC-YOLO network is trained using the training set. The AdamW optimizer is used, and the learning rate is adjusted in stages. The loss function includes the binary cross-entropy loss (BCE Loss) of the classification branch and the distribution focus loss (DFL) and complete intersection-union loss (CIoU Loss) of the regression branch.
[0015] (4) Use the trained MAC-YOLO network to detect the input fabric surface image and output the category and location prediction map of the defects.
[0016] In some embodiments, the morphological fusion preprocessing block (MFPB) includes the following sub-modules:
[0017] ① Horizontal / Vertical TopHat-BlackHat Operations:
[0018] Horizontal direction: Perform Top-Hat transformation on the input image using a long horizontal kernel (size 1×15). ) and Black-Hat transform ( ),in As a horizontal structuring element, it is used to enhance the contrast between lateral bright and dark defects. For the input image, For opening operation, This is a closing operation;
[0019] Vertical direction: Perform similar horizontal operations on the input image using a narrow vertical kernel (size 5×1) to enhance local grayscale changes of vertical defects;
[0020] ② Multi-scale opening operation differential operation: By calculating the morphological opening operation residuals of small-scale (3×3) and large-scale (5×5) structuring elements, small-scale anomalies are separated from normal textures, defined as... ,in, and These are small-scale and large-scale structural elements, respectively.
[0021] ③ Channel-spatial collaborative attention (CSA) mechanism:
[0022] Channel attention weight Generated through Global Average Pooling (GAP) and a fully connected layer, the formula is as follows: ;
[0023] Spatial attention weights Generated through 3×3 convolution, the formula is: ;
[0024] The morphological characteristics after fusion are (⊙ represents the Hadamarda complex).
[0025] in, For global average pooling, , and It is a fully connected layer. The morphological features of fusion.
[0026] In some embodiments, the Dynamic Multi-Scale Strip Pooling (DMS-SP) module includes:
[0027] ① Multi-branch pooling structure:
[0028] Global horizontal strip pooling (1×W): captures full-width lateral defects, and the output is restored to its original size by 1×1 convolution and bilinear interpolation;
[0029] Local horizontal strip pooling (1×3): detects segmented small defects while preserving lateral details;
[0030] Global vertical strip pooling (H×1): Extracts the global structure of longitudinal defects (such as broken meridians);
[0031] ② Attention-guided dynamic fusion: Weights are generated through channel attention. (Generated by 1×1 convolution), the features of each branch are weighted and fused, and the formula is: ,in, For different pooling branch characteristics, For the corresponding weights.
[0032] In some embodiments, the Dynamically Separable Kernel Attention (DSKA) mechanism includes:
[0033] Horizontal branch: A depthwise separable convolution with a wide kernel (k≫1) is used to extract long-range lateral dependencies, as shown in the formula. , ;
[0034] Vertical branch: Depth-separable convolutions with narrow kernels (k≪W) preserve vertical details, as shown in the formula. ;
[0035] Dynamic gated fusion: Weights are generated through global average pooling (GAP) and two 1×1 convolutional layers. and The fusion formula is ( and (where are learnable parameters), .
[0036] In some embodiments, the multi-scale enhanced CSP module (MSECSP) includes:
[0037] ① Parallel convolution and pooling branches: The initial 3×3 convolutional layer captures local texture patterns, and then the DMS-SP module is concatenated to aggregate multi-scale contextual information;
[0038] ② Feature fusion: The multi-scale features (global horizontal, local horizontal, global vertical) output by DMS-SP are concatenated with the adaptive features (horizontal and vertical) output by DSKA, and then dimensionality reduction is achieved through 1×1 convolution to achieve collaborative optimization of multi-scale and multi-axis features.
[0039] In some embodiments, the neck structure of the MAC-YOLO network employs a modified PAN-FPN structure, specifically including:
[0040] ① Deep features (1 / 32 resolution) are downsampled to 1 / 16 and 1 / 8 resolution (through convolution with stride 2).
[0041] ② Shallow features (1 / 8, 1 / 16 resolution) are upsampled to 1 / 8 resolution (through bilinear interpolation).
[0042] ③ The bidirectional fusion of features (1 / 8 resolution) is input into the detection head, enhancing the feature transfer efficiency of small targets and slender defects.
[0043] In some embodiments, the detection head employs a decoupled design, including:
[0044] ① Classification branch: 2 layers of 3×3 convolutional layers (each layer followed by ReLU activation), outputting the probability distribution of 7 types of defects (size is [batch_size, 7, H, W]);
[0045] ②Regression branch:
[0046] First layer: 3×3 convolutional layer (outputs the center coordinate offset of 4k anchor frames);
[0047] The second layer: The distributed focus loss (DFL) is used to optimize the bounding box parameter distribution, as shown in the formula below. ;
[0048] The localization accuracy is optimized by incorporating the Cross-Union Loss (CIoU Loss) formula: .
[0049] In some embodiments, the dataset in step (2), whose dataset construction includes:
[0050] Image acquisition parameters: A CCD camera with a resolution of 3072×96 pixels and a frame rate of 50fps is used. The camera is set at the fabric outlet of the fabric production line with a light intensity of 500-800 lux to ensure that the image includes the entire width of the fabric.
[0051] Defect labeling guidelines: Use LabelImg software to label defect images, with the label box covering the defect area (overlap rate ≥ 90%), and background areas labeled as defect-free areas;
[0052] Data augmentation: Randomly flip (horizontal / vertical), adjust brightness (±20%), and add noise to the training set images to improve the model's generalization ability.
[0053] To achieve the above objectives, the present invention also provides the following technical solution: a fabric defect detection system based on MAC-YOLO, comprising:
[0054] Image acquisition module: used to acquire images of the fabric surface in real time and output RGB image data of 3072×96 pixels;
[0055] Preprocessing module: Normalizes the input image (scales pixel values to [0,1]), resizes it (maintains aspect ratio), and filters noise (Gaussian blur kernel 3×3).
[0056] MAC-YOLO detection module: integrates the aforementioned MFPB, DMS-SP, DSKA, and MSECSP modules, used for feature extraction and defect detection of preprocessed images;
[0057] Post-processing module: Performs non-maximum suppression (NMS, confidence threshold 0.5, crossover ratio threshold 0.45) on the detection results, and outputs the final defect category and location (bounding box coordinates) information;
[0058] Visualization module: Overlays the detection results onto the original image to generate an labeled detection map.
[0059] In some embodiments, a training module is also included, which is used to perform the following operations:
[0060] Data loading: Read images and labeled data from the training set and load them in batches (Batch Size=8);
[0061] Forward propagation: Input the image into the MAC-YOLO network and calculate the classification loss. and regression loss ;
[0062] Loss Calculation: Total Loss ,in , ;
[0063] Backpropagation: The network parameters are updated using the AdamW optimizer, and the learning rate is adjusted using an exponential decay strategy;
[0064] Model saving: The model weights are saved every 10 epochs, and the weight with the highest mAP@50 on the test set is selected as the final model.
[0065] Compared with the prior art, the beneficial effects of the present invention are: by constructing an improved MAC-YOLO network, combined with morphological fusion preprocessing, dynamic multi-scale pooling and attention mechanism, the feature representation ability of slender and small-scale defects is effectively enhanced, which has the advantages of improving the accuracy and real-time performance of defect detection in fabric images with extreme aspect ratios.
[0066] 1. The present invention uses Morphological Fusion Preprocessing Block (MFPB) which can effectively enhance defect features, reduce texture interference, improve the grayscale contrast between defects and background, and improve the limitations of traditional preprocessing methods in complex fabrics.
[0067] 2. This invention proposes Dynamic Multi-Scale Strip Pooling (DMS-SP), which can effectively process images with extreme aspect ratios. It expands the receptive field through global-local pooling, captures long-distance dependencies, and reduces computational complexity.
[0068] 3. This invention utilizes the Dynamic Separable Kernel Attention (DSKA) mechanism. Through axis-specific attention, it leverages the importance of horizontal and vertical features in separable convolution to reduce interference from cross-directional features and improve detection accuracy.
[0069] 4. This invention employs a multi-scale enhanced CSP module (MSECSP), which effectively integrates the DMS-SP and DSKA mechanisms. It captures global features through dynamic multi-scale strip pooling and focuses on local details using dynamic separable kernel attention, thereby improving the detection capability of defects in images with extreme aspect ratios.
[0070] Details of one or more embodiments of this application are set forth in the following drawings and description to make other features, objects and advantages of this application more readily apparent. The embodiments of this application will provide a detailed description and understanding of the application. Attached Figure Description
[0071] Figure 1 This is a schematic diagram of the MAC-YOLO network structure of the present invention;
[0072] Figure 2 This is a schematic diagram of the morphological fusion preprocessing block (MFPB) of the present invention;
[0073] Figure 3 This is a schematic diagram of the structure of the multi-scale enhanced CSP module (MSECSP) of the present invention;
[0074] Figure 4 This is a schematic diagram of the strip pooling module.
[0075] Figure 5 This is a schematic diagram of the structure of the Dynamic Multi-Scale Strip Pooling (DMS-SP) module of the present invention;
[0076] Figure 6 This is a schematic diagram of the feature fusion network in the PAN-FPN structure;
[0077] Figure 7 A schematic diagram of the detection network (Head) structure;
[0078] Figure 8 Schematic diagrams of different types of fabric surface defects;
[0079] Figure 9 A comparison chart of the detection results of the MAC-YOLO model and the YOLOv8n model;
[0080] Figure 10 A thermal comparison diagram of the MFPB and baseline modules;
[0081] Figure 11 A thermal comparison diagram of the MSECSP and baseline modules. Detailed Implementation
[0082] 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.
[0083] In traditional fabric defect detection systems, deep learning-based detection methods face inherent limitations in feature extraction and multi-scale fusion when processing industrial images with extreme aspect ratios. Fixed-size convolutional kernels cannot effectively capture the synergistic relationship between long-range lateral dependencies and vertical detail features, resulting in limited geometric feature representation capabilities for elongated defects. Standard pooling operations disrupt the continuous structure of elongated defects when compressing feature maps, causing irreversible loss of key spatial information. The low signal-to-noise ratio feature differences between complex textured backgrounds and small-scale anomalies make it difficult for traditional feature fusion mechanisms to achieve effective interference suppression. The lack of a dynamic weight allocation mechanism during multi-scale feature interaction leads to low fusion efficiency of features along different axes.
[0084] For example, fabric images captured by area-array CCD industrial cameras deployed on textile production lines have an extreme aspect ratio of 3072×96 pixels, covering a width of 1.5 meters laterally while containing only a limited texture period longitudinally. When detecting longitudinal defects such as warp breaks and weft breaks, the fixed receptive field of traditional convolutional kernels cannot simultaneously adapt to the needs of lateral global structure perception and longitudinal local detail capture, resulting in endpoint positioning errors of more than 3 millimeters for slender defects. When processing transverse alternating light and dark defects such as loose stripes, standard max pooling operations eliminate the gray-level gradient features between adjacent stripes, causing the defect boundaries to become blurred. When the gray-level difference between small-scale anomalies such as creases and normal textures is less than 15%, the cross-scale information transmission of existing feature pyramid networks introduces background noise, causing the defect confidence to drop below 0.5.
[0085] If the above problems are not solved, the false detection rate of the detection system will rise to more than 8%, resulting in more than 5 misjudgments and shutdowns per kilometer of fabric; the failure to detect slender defects will cause defective fabric to flow into downstream processes, resulting in at least 2% waste of raw materials per batch; the inefficiency of multi-scale feature fusion will increase the model inference latency to 50 milliseconds, which cannot meet the frame rate requirements of real-time detection on the production line; the lack of a dynamic feature weighting mechanism will reduce the model's generalization ability on complex textured fabrics, causing the cross-category detection accuracy to fluctuate by more than 12 percentage points.
[0086] To address the aforementioned challenges, this application first tackles the difficulty of fixed-size convolutional kernels in simultaneously capturing both lateral global and vertical local features, exploring ways to enhance multi-axial feature extraction capabilities by improving the network infrastructure. Considering the fixed receptive field limitations of traditional convolutional kernels, a dynamic multi-scale pooling mechanism was introduced; however, it was found that standard pooling operations disrupt the continuity of elongated defects. Therefore, this application shifts its focus to a method combining strip pooling with morphological operations, preserving the geometric features of defects through differentiated processing in the horizontal and vertical directions. Further analysis reveals that simply adding pooling branches increases computational complexity, necessitating the design of an attention mechanism to achieve dynamic feature fusion. To resolve the interference from complex textured backgrounds, a preprocessing module based on morphological operations is investigated, separating abnormal regions through multi-scale opening and closing operations. Finally, a collaborative network architecture incorporating morphological preprocessing, dynamic pooling, and attention fusion is determined to effectively extract multi-scale defect features.
[0087] In this regard, such as Figures 1 to 7 As shown, this application proposes a MAC-YOLO-based fabric defect detection method, including the following steps: constructing a MAC-YOLO network, which is an improvement on the YOLOv8 network, specifically including: using a morphological fusion preprocessing block as the first module of the network input layer; replacing some convolutional layers of the original YOLOv8 network with a dynamic multi-scale strip pooling module; integrating a dynamic separable kernel attention mechanism into the multi-scale feature fusion path; replacing the original YOLOv8 SPPF module with a multi-scale enhancement CSP module integrating dynamic multi-scale strip pooling and dynamic separable kernel attention; collecting a fabric surface image dataset, labeling defect images with defect types, and randomly dividing the dataset into training and test sets according to proportions; training the MAC-YOLO network using the training set, employing an optimizer, adjusting the learning rate strategy in stages, and using loss functions including the binary cross-entropy loss of the classification branch and the distribution focus loss and complete intersection-union loss of the regression branch; using the trained MAC-YOLO network to detect the input fabric surface image and outputting a predicted map of the defect category and location.
[0088] The Morphological Fusion Preprocessing Block (MFPB) enhances the contrast of defects in specific directions and separates abnormal textures through morphological operations. Specifically, it can be implemented using horizontal / vertical TopHat-BlackHat operations, multi-scale opening differential operations, and channel-space collaborative attention mechanisms to address the problem of defect recognition amidst complex textured backgrounds. The Dynamic Multi-Scale Strip Pooling (DMS-SP) module captures defect features of different scales and directions through a multi-branch pooling structure and performs dynamic weighted fusion. Specifically, it can be implemented using global horizontal strip pooling, local horizontal strip pooling, and global vertical strip pooling combined with attention mechanisms to address the problem of traditional pooling operations disrupting the continuity of slender defects. The Dynamic Separable Kernel Attention (DSKA) mechanism extracts features in different directions by separating convolutional kernels and dynamically fusing them. Specifically, it can be implemented using depthwise separable convolutions with wide horizontal kernels and narrow vertical kernels combined with gated weight generation to address the problem that fixed-size convolutional kernels cannot simultaneously handle long-distance lateral dependencies and vertical details. The Multi-Scale Enhancement CSP module (MSECSP) optimizes multi-scale feature representation capabilities through parallel convolutional pooling branches and multi-axial feature fusion. Specifically, it can be implemented by combining feature concatenation with the DMS-SP module and the DSKA mechanism for dimensionality reduction, addressing the lack of adaptability in multi-scale feature fusion. The Distributed Focal Point Loss (DFL) and Complete Intersection over Union (CIoU) Loss improve regression accuracy by optimizing bounding box parameter distribution and localization precision. Specifically, it can be implemented by combining weighted probability distributions of adjacent locations with center point distance and aspect ratio consistency measures, addressing the problem of inaccurate localization of slender defects.
[0089] The core innovation of this application lies in enhancing defect contrast through morphological preprocessing, preserving slender defect features through dynamic multi-scale pooling, optimizing multi-axial feature extraction through a separable kernel attention mechanism, and synergistic fusion of multiple modules. This improves the accuracy of horizontal and vertical defect detection in fabric images with extreme aspect ratios while maintaining real-time detection efficiency.
[0090] The working process and principle of this application are as follows: The MAC-YOLO network is an improvement on the YOLOv8 network, mainly including the introduction of four key modules. First, a morphological fusion preprocessing block is used as the first module of the network input layer to enhance the defect features in the image through morphological operations. Second, a dynamic multi-scale strip pooling module replaces some convolutional layers of the original YOLOv8 network to effectively capture defects of different scales and shapes. Third, a dynamic separable kernel attention mechanism is integrated into the multi-scale feature fusion path to improve the adaptability of feature extraction. Finally, a multi-scale enhancement CSP module replaces the original YOLOv8 SPPF module to further optimize the feature extraction and fusion process.
[0091] During network training, a dataset of fabric surface images was first collected and defect types were labeled. The dataset was then divided into training and testing sets. The MAC-YOLO network was then trained using the training set, employing an optimizer with phased adjustments to the learning rate. The loss function included binary cross-entropy loss for the classification branch and distribution focus loss and perfect intersection-over-union (CIU) loss for the regression branch. This loss function design helps improve the model's ability to identify and locate different types of defects.
[0092] During the detection process, the fabric surface image is input into a trained MAC-YOLO network. The network performs a series of feature extraction and fusion operations, ultimately outputting a predicted map of the defect category and location. Morphological preprocessing enhances defect features, dynamic multi-scale strip pooling improves the detection capability for elongated defects, a dynamic separable kernel attention mechanism optimizes the feature fusion process, and a multi-scale enhanced CSP module further improves feature representation capabilities. These improvements work together to enable the MAC-YOLO network to more accurately detect various defects on the fabric surface.
[0093] As a preferred embodiment, the solution of this application is specifically implemented as follows:
[0094] In the process of building a MAC-YOLO network, the basic YOLOv8 network is built first.
[0095] The YOLOv8 model employs an encoder-decoder structure, with the backbone network using CSPDarknet53. In the encoder section, multi-scale feature extraction and fusion are used to increase the model's receptive field. In the decoder section, deep and shallow features output from the encoding stage are fused to help the model extract richer and more comprehensive feature information, ultimately predicting the category and location of defects.
[0096] The morphological fusion preprocessing block employs horizontal and vertical morphological operations, including Top-Hat and Black-Hat transforms, to enhance defect features in different directions. The dynamic multi-scale strip pooling module has three branches: global horizontal strip pooling (1×W), local horizontal strip pooling (1×3), and global vertical strip pooling (H×1), used to capture full-width lateral defects, segmented small defects, and vertical defects, respectively. The dynamic separable kernel attention mechanism includes horizontal branches (7×1 convolutional kernels) and vertical branches (1×3 convolutional kernels), achieving adaptive feature extraction through dynamic gating fusion. The multi-scale enhancement CSP module integrates the above components to achieve collaborative optimization of multi-scale and multi-axial features.
[0097] During dataset construction, an area-array CCD camera (3072×96 pixels resolution, 50fps) was used to capture images at the fabric exit of the production line, with illumination intensity controlled between 500-800 lux. Defect labels included eight categories: broken warp, double warp, broken weft, weft band, tight weft, loose weft, kinks, and background. Data augmentation employed random flipping, brightness adjustment, and noise addition.
[0098] The network was trained using the AdamW optimizer with an initial learning rate of 0.000833 and a weight decay of 0.0005. An exponential decay strategy (γ=0.95) was used to adjust the learning rate. In the loss function, the classification branch used binary cross-entropy loss, while the regression branch combined distribution focus loss and perfect intersection-over-union (MIU) loss. The model weights were saved every 10 epochs, and the weight with the highest mAP@50 on the test set was selected as the final model.
[0099] During the detection process, the input image first undergoes preprocessing, including normalization (pixel values scaled to [0,1]), resizing (maintaining aspect ratio), and noise filtering (Gaussian blur kernel 3×3). After the MAC-YOLO network outputs the original detection results, post-processing is performed using non-maximum suppression (NMS, confidence threshold 0.5, intersection-over-union threshold 0.45) to obtain the final defect category and location information.
[0100] Through the above-described scheme, this application effectively solves the feature extraction and multi-scale fusion problems faced by traditional fabric defect detection systems when processing industrial images with extreme aspect ratios. The morphological fusion preprocessing block enhances the contrast of defect features and improves the detection capability of small-scale anomalies. The dynamic multi-scale strip pooling module overcomes the limitation of fixed-size convolutional kernels in simultaneously handling long-distance lateral dependencies and vertical detail features, improving the detection accuracy for slender defects. The dynamic separable kernel attention mechanism enables adaptive feature fusion, enhancing the model's robustness to complex textured backgrounds. The multi-scale enhancement CSP module optimizes the multi-scale feature interaction process, improving feature representation capabilities. These improvements work together to significantly enhance the accuracy and efficiency of fabric defect detection, meeting the requirements of real-time detection on industrial production lines.
[0101] In some of the schemes described above in this application, the morphological fusion preprocessing block, as the first module of the network input layer, is insufficient in enhancing the contrast of defects in different directions, separating small-scale anomalies, and optimizing feature fusion. This makes it difficult for the subsequent network to effectively extract the features of transverse bright defects, longitudinal dark defects, and small-scale anomalies, thus affecting the detection accuracy.
[0102] This application further proposes a morphological fusion preprocessing block including the following sub-modules: horizontal / vertical TopHat-BlackHat operation, multi-scale opening operation differential operation, and channel-space collaborative attention mechanism.
[0103] Among them, the horizontal / vertical TopHat-BlackHat operation uses a long horizontal kernel and a narrow vertical kernel to perform the Top-Hat transformation and Black-Hat transformation respectively. The horizontal kernel size is 1×15 and the vertical kernel size is 15×1. The multi-scale opening operation differential operation calculates the opening operation residual through 3×3 and 5×5 structuring elements. The channel-space collaborative attention mechanism generates channel attention weights through global average pooling, generates spatial attention weights through 3×3 convolution, and uses Hadamard product to fuse morphological features.
[0104] Specifically, in the horizontal direction, a 1×15 kernel is used to perform Top-Hat and Black-Hat transformations to enhance the contrast of bright and dark defects, such as loose sections and broken warp, respectively. In the vertical direction, a 15×1 kernel performs the same operation to enhance the local grayscale changes of vertical defects, such as broken warp and double warp defects. Multi-scale opening operation difference separates small-scale anomalies through the opening operation residuals of small-scale and large-scale structuring elements; for example, a 3×3 kernel captures curvature defects, and a 5×5 kernel suppresses normal textures. A channel-space collaborative attention mechanism compresses global information in the channel dimension and extracts local patterns in the spatial dimension from the morphologically processed features. Feature weighting is achieved through Hadamard product; for example, global average pooling generates channel weights to focus on important feature channels, and 3×3 convolution generates spatial weights to enhance the response of defect regions. The morphologically processed features are multiplied element-wise with the attention weights to suppress background texture interference and improve the signal-to-noise ratio of defect features.
[0105] As a preferred embodiment, the solution of this application is specifically implemented as follows:
[0106] The morphological fusion preprocessing block includes horizontal / vertical TopHat-BlackHat operations, multi-scale opening differential operations, and channel-space collaborative attention mechanisms.
[0107] In the horizontal / vertical TopHat-BlackHat operation, a long horizontal kernel of size 1×15 is used to perform Top-Hat and Black-Hat transformations on the input image in the horizontal direction; a similar operation is performed in the vertical direction using a narrow vertical kernel of size 15×1. These operations enhance the contrast of lateral and vertical defects.
[0108] Horizontal operations utilize long horizontal kernels to capture long horizontal defects, enhance the continuity of bright areas through dilation operations, and preserve and expand dark areas through erosion operations. The calculation formula is as follows: ;
[0109] in, This is a lateral expansion operation. For transverse corrosion operations, highlight transverse bright defects such as loose sections and weft threads.
[0110] Vertical operations use a narrow vertical kernel to emphasize local grayscale changes in vertical defects. The calculation formula is as follows:
[0111] in, and For longitudinal expansion / corrosion operations, enhance longitudinal dark defects such as broken warp and double warp.
[0112] Multi-scale opening differential operations separate small-scale anomalies from normal textures by calculating the morphological opening residuals of 3×3 and 5×5 structuring elements.
[0113] The calculation formula is as follows:
[0114] in, For small-scale opening operations. It enables large-scale opening operations, effectively separating small defects such as curves and stains from background textures.
[0115] Channel-spatial collaborative attention (CSA) fusion , , Morphological characteristics Channel attention weights are generated through global average pooling (GAP) and two convolutional layers. (1×1 convolution for dimensionality reduction and dimensionality increase) and spatial attention weights (3×3 convolution generates spatial weight map), and the defect region is enhanced by fusion using Hadamard product: .
[0116] Through the above technical solution, this application achieves effective preprocessing of fabric surface images. The morphological fusion preprocessing block can enhance the local features of different types of defects, improve the detection sensitivity of small-scale anomalies, and adaptively adjust feature representation through an attention mechanism. This preprocessing method helps subsequent networks to more accurately identify and locate various types of fabric defects, especially showing significant improvement in defect detection against subtle defects and complex texture backgrounds.
[0117] In some of the solutions described above in this application, when processing fabric images with extreme aspect ratios, traditional pooling operations make it difficult for fixed-size convolutional kernels to simultaneously capture long-distance lateral dependencies and vertical detail features. Standard pooling operations also disrupt the continuity features of elongated defects, resulting in limited detection accuracy.
[0118] This application further proposes a dynamic multi-scale strip pooling module, including a multi-branch pooling structure and attention-guided dynamic fusion. The multi-branch pooling structure includes global horizontal strip pooling, local horizontal strip pooling, and global vertical strip pooling. Global horizontal strip pooling captures full-width lateral defects using a 1×W-sized pooling kernel, and the output is restored to its original size through 1×1 convolution and bilinear interpolation. Local horizontal strip pooling uses a 1×3-sized pooling kernel to detect segmented small defects, preserving lateral details. Global vertical strip pooling extracts the global structure of vertical defects using an H×1-sized pooling kernel. Attention-guided dynamic fusion generates 3D weights through channel attention. The features of each branch are weighted and fused, and the formula is as follows: .in, , , These are global level, local level, and global vertical pooling features, respectively.
[0119] Specifically, global horizontal strip pooling enhances the global perception of lateral defects such as loose weft threads through large-scale horizontal pooling, while local horizontal strip pooling focuses on local areas such as weft breaks using small-sized kernels, avoiding the loss of details. Global vertical strip pooling extracts continuous structural features of vertical defects such as warp breaks using vertical pooling kernels. The channel attention mechanism generates dynamic weights through 1×1 convolutions, adaptively adjusting the contribution of each branch based on input features. For example, it assigns higher weights to global horizontal pooling when detecting wide lateral defects, and increases the weight ratio of vertical pooling branches when detecting long and narrow vertical defects. After weighted fusion, the multi-scale pooling features can preserve the continuity of defects in different directions while suppressing interference from fabric texture background, improving the robustness to detecting defects with extreme aspect ratios.
[0120] As a preferred embodiment, the solution of this application is specifically implemented as follows:
[0121] The Dynamic Multi-Scale Strip Pooling (DMS-SP) module consists of two parts: a multi-branch pooling structure and attention-guided dynamic fusion.
[0122] The multi-branch pooling structure consists of three branches: Global Horizontal Strip Pooling (1×W): Performs global horizontal pooling on the input feature map to capture full-width lateral defect features. The pooled features are then adjusted for channel count using 1×1 convolutions and bilinear interpolation is used to restore the original spatial dimensions. Local Horizontal Strip Pooling (1×3): Uses a 1×3 sliding window for local horizontal pooling, preserving lateral detail information and aiding in the detection of segmented small defects. Global Vertical Strip Pooling (H×1): Performs global vertical pooling on the input feature map to extract global structural features of vertical defects.
[0123] The attention-guided dynamic fusion component generates 3D weights through a channel attention mechanism. This is used to perform weighted fusion of features from each branch. The specific steps are as follows:
[0124] 1. Perform global average pooling on the pooling features of the three branches respectively to obtain the feature vectors of the channel dimension.
[0125] 2. Use a 1×1 convolutional layer to transform the feature vector and generate the corresponding attention weights. .
[0126] 3. Multiply the attention weights by the features of each branch to obtain the weighted features.
[0127] 4. Add the weighted features together to obtain the final fused features. .
[0128] The fusion formula is: .in, , , These are global level, local level, and global vertical pooling features, respectively.
[0129] Through the above technical solutions, this application achieves adaptive capture and fusion of defect features at different scales and directions. Global horizontal strip pooling effectively extracts long-distance lateral dependencies, suitable for detecting full-width lateral defects such as loose seams. Local horizontal strip pooling preserves lateral detail information, which is beneficial for detecting local small defects such as broken weft threads. Global vertical strip pooling enhances the detection capability of longitudinal defects such as broken warp threads. The attention-guided dynamic fusion mechanism further improves the flexibility and adaptability of feature fusion, enabling the model to automatically adjust the importance of different branch features according to the characteristics of the input image. As a result, this module significantly improves the detection accuracy of various fabric defects while maintaining low computational complexity, meeting the needs of real-time detection.
[0130] In some of the solutions described above in this application, when processing fabric images with extreme aspect ratios, the traditional YOLO series algorithms have difficulty simultaneously taking into account both long-distance lateral dependencies and vertical detail features using convolutional kernels of fixed size, resulting in limited detection accuracy for slender defects.
[0131] This application further proposes a dynamic separable kernel attention mechanism, including horizontal branching, vertical branching, and dynamic gating fusion. The horizontal branch uses a depthwise separable convolution with a wide kernel to extract long-range lateral dependencies, while the vertical branch uses a depthwise separable convolution with a narrow kernel to preserve vertical details. The dynamic gating fusion achieves adaptive feature fusion by generating weight parameters through global average pooling and convolution.
[0132] In this design, the horizontal branch uses a 7×1 wide convolutional kernel to reduce computational cost through depthwise separable convolutions, while simultaneously expanding the receptive field along the horizontal direction to capture global correlation features of lateral extension defects such as broken latitudes and loose spurs. The vertical branch uses a 1×3 narrow convolutional kernel to limit the vertical kernel size, avoiding excessive smoothing of vertical details and effectively extracting local gradient changes of vertical defects such as broken longitudes and double longitudes. Dynamic gated fusion compresses the feature dimension through global average pooling and combines two layers of 1×1 convolutions to generate the horizontal branch weights. and vertical branch weights The weight parameters are automatically optimized through backpropagation, dynamically adjusting the contribution ratio of horizontal and vertical features based on the input features.
[0133] Specifically, the input feature map is processed by horizontal branching to generate lateral features. Vertical branching generates vertical features. Global average pooling compresses the spatial dimension of the input features, generating channel description vectors, which are then mapped to weight parameters through two 1×1 convolutional layers. and The integration phase will and Multiply, and Multiply them, then add them together to get the final output feature. This process enables the network to adaptively enhance its response to defect features in the dominant direction of the current input image, such as the horizontal branch weights when detecting latitude break defects. Automatically increases and strengthens the expression of lateral features; when detecting menstrual fracture defects, the vertical branch weight is increased. Automatically enlarges to enhance the saliency of vertical features. By separating the convolution kernel direction and dynamically assigning weights, it effectively solves the problem of insufficient feature extraction in images with extreme aspect ratios using traditional fixed convolution kernels.
[0134] As a preferred embodiment, the solution of this application is specifically implemented as follows:
[0135] The Dynamically Separable Kernel Attention (DSKA) mechanism consists of three parts: horizontal branching, vertical branching, and dynamic gating fusion.
[0136] The horizontal branch uses a 7×1 depthwise separable convolution to extract long-range lateral dependencies. Specifically, the input feature map x is first subjected to a 7×1 depthwise convolution, followed by GELU activation and a 1×1 convolution to restore channel correlation. The calculation formula is as follows: , to obtain lateral features .
[0137] The vertical branch employs a 1×3 depthwise separable convolution to preserve vertical details. Specifically, the input feature map x is first subjected to a 1×3 depthwise convolution, followed by a 1×1 pointwise convolution, calculated using the following formula: To obtain longitudinal features .
[0138] Dynamic gating fusion generates weights through global average pooling and two 1×1 convolutional layers. and Specifically, first, a global average pooling operation is performed on the input feature map x to obtain a C-dimensional vector (C being the number of channels in the feature map). Then, a 2C-dimensional vector is generated through two 1×1 convolutions and a sigmoid activation function, corresponding to... and Finally, the output features are obtained through weighted fusion. .
[0139] Through the above technical solution, this application can adaptively capture lateral and longitudinal feature information, effectively extracting features of slender defects. The dynamic gating mechanism can automatically adjust the weights of lateral and longitudinal features according to the content of the input features, enhancing the flexibility and adaptability of feature extraction. This design helps improve the detection accuracy of slender defects such as broken warp and weft threads, while maintaining computational efficiency.
[0140] In some of the schemes mentioned above in this application, the multi-scale feature fusion mechanism lacks adaptability, resulting in limited feature representation ability and an inability to effectively coordinate and optimize feature information of different scales and multiple axes, thus affecting detection accuracy.
[0141] This application further proposes a multi-scale enhanced CSP module, including: parallel convolution and pooling branches: an initial 3×3 convolutional layer captures local texture patterns, followed by a cascaded dynamic multi-scale strip pooling module to aggregate multi-scale contextual information; feature fusion: the multi-scale features output by the dynamic multi-scale strip pooling are concatenated with the adaptive features output by the dynamic separable kernel attention, and then dimensionality is reduced by 1×1 convolution to achieve collaborative optimization of multi-scale and multi-axial features.
[0142] In the parallel convolution and pooling branches, the initial 3×3 convolutional layer is used to extract local texture features from the fabric image, such as subtle texture changes like broken weft or undulations. The dynamic multi-scale strip pooling module captures lateral and longitudinal defect features at different scales through global horizontal, local horizontal, and global vertical pooling branches. During the feature fusion stage, the multi-scale features output by dynamic multi-scale strip pooling contain global lateral defect information and local longitudinal details, while the adaptive features output by dynamic separable kernel attention contain lateral long-distance dependencies and longitudinal detail enhancement information. The stitching operation merges the lateral and longitudinal features along the channel dimension, and the 1×1 convolutional layer compresses the number of channels to the original size, reducing computational redundancy.
[0143] Specifically, the initial 3×3 convolutional layer extracts low-level features of fabric texture through local receptive fields, such as short line segments of weft breakage defects or curved structures of undulations. The global horizontal pooling branch of the dynamic multi-scale strip pooling module uses a 1×W-sized pooling kernel to extract global features of long-distance lateral defects such as loose weft threads. The local horizontal pooling branch uses a 1×3 pooling kernel to preserve local details of weft breakage, while the global vertical pooling branch uses an H×1 pooling kernel to capture the longitudinal continuity features of warp breakage. The horizontally wide kernel features and vertically narrow kernel features output by the dynamic separable kernel attention module enhance the saliency of long-distance lateral defects and longitudinal details, respectively. The stitched multi-scale features undergo channel dimensionality reduction through a 1×1 convolutional layer, for example, reducing the number of channels from 256 to 128 while retaining key information of multi-axial features. Thus, local texture features, multi-scale pooling features, and adaptive attention features achieve synergistic optimization during dimensionality reduction, improving the detection accuracy of different morphological defects such as warp breakage and loose weft threads.
[0144] As a preferred embodiment, the solution of this application is specifically implemented as follows:
[0145] The multi-scale enhancement CSP module consists of two parts: parallel convolution and pooling branches, and feature fusion.
[0146] The parallel convolution and pooling branches first employ a 3×3 convolutional layer to capture local texture patterns. This convolutional layer uses 32 kernels with a stride of 1 and padding of 1 to maintain the feature map size. The convolutional operation is followed by a BatchNorm layer and a ReLU activation function. Subsequently, a dynamic multi-scale strip pooling module is cascaded, which includes three branches: global horizontal strip pooling (1×W), local horizontal strip pooling (1×3), and global vertical strip pooling (H×1).
[0147] The feature fusion section first concatenates the multi-scale features (global horizontal, local horizontal, and global vertical) output from the dynamic multi-scale strip pooling module with the adaptive features (horizontal and vertical) output from the dynamic separable kernel attention mechanism. The concatenation operation is performed along the channel dimension, resulting in a feature map with an increased number of channels. Dimensionality reduction is then achieved through 1×1 convolutions, with the number of kernels set to half the original input channel number to achieve information compression and feature selection. Finally, the fused features are obtained after passing through a BatchNorm layer and a ReLU activation function.
[0148] This design achieves collaborative optimization of multi-scale and multi-axial features through parallel branching and feature fusion, enhancing the model's ability to detect defects of different scales and shapes.
[0149] Through the above technical solution, this application can effectively capture multi-scale features in fabric images, improving the detection accuracy of slender defects and small target defects. Parallel convolution and pooling branches can simultaneously extract local texture and global contextual information, while the feature fusion mechanism effectively integrates multi-scale and multi-directional features. This design significantly enhances the model's adaptability to defects of different types and scales, improving detection accuracy and robustness. Simultaneously, dimensionality reduction through 1×1 convolution maintains computational efficiency, facilitating the model's deployment and application in real-world production environments.
[0150] In some of the solutions described above in this application, the resolution of deep features is low, which leads to the loss of features of small targets and slender defects during transmission, affecting the detection accuracy.
[0151] This application further proposes using an improved PAN-FPN structure as the neck structure of the MAC-YOLO network, specifically including: deep features downsampled to 1 / 16 and 1 / 8 resolution, shallow features upsampled to 1 / 8 resolution, and a bidirectional fused feature input detection head.
[0152] In this process, deep features are downsampled using convolution operations with a stride of 2, progressively expanding the 1 / 32 resolution feature map to 1 / 16 and 1 / 8 resolutions, preserving the global structural information of slender defects. Shallow features are upsampled using bilinear interpolation to restore the 1 / 8 resolution, maintaining the local detail features of small targets. The bidirectional fusion process concatenates feature maps of different resolutions through channel-wise connections, enabling multi-scale feature interaction. When the fused feature map is input into the detection head, a 3×3 convolution kernel is used for feature integration, balancing computational efficiency and feature representation capability.
[0153] Specifically, deep features are processed through two convolutional layers with a stride of 2, generating feature maps at 1 / 16 and 1 / 8 resolutions respectively. This process reduces computation by decreasing the number of channels. Shallow features are then enlarged from the 1 / 16 resolution feature map to 1 / 8 resolution using bilinear interpolation and superimposed on the original 1 / 8 resolution features to supplement high-frequency texture information. During bidirectional fusion, the semantic information carried by the deep features and the spatial details of the shallow features are concatenated along the channel dimension to form a comprehensive representation containing multi-scale features. The final output 1 / 8 resolution feature map is used by the detection head to generate prediction results, preserving the continuity of elongated defects while improving the sensitivity of small target detection. This structure optimizes the transmission path of defect features in extreme aspect ratio fabric images through resolution matching and feature complementarity mechanisms.
[0154] As a preferred embodiment, the solution of this application is specifically implemented as follows:
[0155] The neck structure of the MAC-YOLO network employs a modified PAN-FPN structure. First, deep features are downsampled using convolutional layers with a stride of 2, downsampling the 1 / 32 resolution feature maps to 1 / 16 and 1 / 8 resolutions respectively. Then, shallow features (1 / 8 and 1 / 16 resolutions) are upsampled to 1 / 8 resolution using bilinear interpolation. Finally, the bidirectionally fused features (1 / 8 resolution) are input into the detection head.
[0156] Specifically, in the deep feature downsampling process, a 3x3 convolution kernel with a stride of 2 and padding of 1 is used. For example, for a 1 / 32 resolution feature map F_32 (size H / 32 x W / 32 x C), a 1 / 16 resolution feature map F_16 (size H / 16 x W / 16 x C') is first obtained through a convolution operation, and then the same convolution operation is performed again to obtain a 1 / 8 resolution feature map F_8 (size H / 8 x W / 8 x C'').
[0157] For upsampling of shallow features, a bilinear interpolation method is used. For example, the feature map F_16 at 1 / 16 resolution is upsampled to 1 / 8 resolution to obtain F_16_up (size H / 8 x W / 8 x C'). Similarly, the feature map F_8 at 1 / 8 resolution remains unchanged.
[0158] Furthermore, the bidirectional fusion process employs element-wise addition. The upsampled feature map F_16_up is added element-wise to F_8 to obtain the fused feature map F_fused (size H / 8 x W / 8 x C''). Finally, F_fused is passed as input to the detection head for subsequent target detection tasks.
[0159] Through the above technical solutions, this application achieves effective fusion of multi-scale features, enhancing the feature transfer efficiency for small targets and slender defects. The improved PAN-FPN structure achieves the alignment and fusion of features at different resolutions through downsampling of deep features and upsampling of shallow features, effectively improving the detection model's ability to recognize targets at different scales. Simultaneously, using 1 / 8 resolution as the final output maintains both high spatial resolution and computational efficiency. This design helps improve the model's detection accuracy for small and slender defects while maintaining low computational complexity, making it suitable for real-time fabric defect detection scenarios.
[0160] In some of the schemes described above in this application, the bounding box prediction of the regression branch uses a single loss function, which leads to insufficient positioning accuracy for defects with extreme aspect ratios, especially in terms of the consistency measurement of aspect ratios for slender defects.
[0161] This application further proposes that the detection head adopts a decoupled design. The classification branch includes two 3×3 convolutional layers, each followed by ReLU activation, which outputs the probability distribution of 7 types of defects. The regression branch includes the first 3×3 convolutional layer that outputs the center coordinate offset of 4k anchor boxes. The second layer uses distributed focus loss to optimize the distribution of bounding box parameters and combines complete intersection-union loss to optimize positioning accuracy.
[0162] Specifically, the 3×3 convolutional layer in the classification branch captures the texture features of defects through local receptive fields. The second convolutional layer further aggregates contextual information, and ReLU activation enhances the non-linear expressive power of the features. The output layer uses the sigmoid function to generate probability distribution maps for seven types of defects. The 3×3 convolutional layer in the regression branch outputs the center coordinate offset. Each anchor box corresponds to four parameters. The distributed focus loss transforms continuous coordinate prediction into discrete probability distribution optimization, balancing the probability differences between adjacent positions by adjusting the factor τ. The perfect intersection-union (MIU) loss introduces a center point distance penalty term and an aspect ratio consistency measure when calculating the MTU. The diagonal length c of the minimum bounding box is calculated using the extreme values of the ground truth and predicted box coordinates. During backpropagation, the distributed focus loss optimizes the probability distribution of the anchor box parameters, while the MTU loss simultaneously adjusts the center point offset and aspect ratio error. The weighted sum of these two losses forms the total loss of the regression branch.
[0163] As a preferred embodiment, the solution of this application is implemented as follows: The detection head adopts a decoupled design, including a classification branch and a regression branch. The classification branch consists of two 3×3 convolutional layers, each followed by a ReLU activation function, and finally outputs the probability distribution of 7 types of defects, with an output size of [batch_size, 7, H, W].
[0164] The classification branch uses the binary cross-entropy loss (BCE Loss), calculated as follows: .
[0165] The regression branch consists of two layers. The first layer is a 3×3 convolutional layer used to output the center coordinate offsets of 4k anchor boxes. The second layer uses distributed focus loss (DFL) to optimize the distribution of bounding box parameters. The DFL loss function is defined as follows: Simultaneously, it combines the Complete Intersection over Union (CIoU) Loss to optimize positioning accuracy. The CIoU loss function is defined as follows: , .in, The intersection-union ratio (IUR) of the bounding boxes. This represents the distance between the center points of the predicted bounding box and the ground truth bounding box. This represents the length of the diagonal of the actual bounding box. Measuring the difference in aspect ratio, This is a local minimum value used to prevent division by zero. During training, the classification loss and regression loss are added together to obtain the final loss expression. .
[0166] Through the above technical solution, this application achieves a decoupled design of the detection head, separating the classification and regression tasks, and improving the model's flexibility and interpretability. The classification branch extracts defect features through multi-layer convolution and activation functions, improving classification accuracy. The regression branch uses a combination of distributed focal loss and perfect intersection-over-union (MIU) loss to optimize the bounding box parameter distribution and positioning accuracy, effectively improving the detection performance for slender defects and small target defects. This design not only improves detection accuracy but also maintains low computational complexity, making it suitable for real-time detection on industrial production lines.
[0167] In some of the solutions described above in this application, existing fabric defect detection methods suffer from several problems during dataset construction, including insufficient image acquisition resolution leading to the loss of elongated defect features, inaccurate bounding boxes covering defect areas affecting model learning performance, and insufficient training data diversity limiting model generalization ability.
[0168] This application further proposes its dataset construction, including,
[0169] Image acquisition parameters: A CCD camera with a resolution of 3072×96 pixels and a frame rate of 50fps is used. The camera is set at the fabric outlet of the fabric production line with a light intensity of 500-800 lux to ensure that the image includes the entire width of the fabric, which is approximately 1.5 meters.
[0170] Defect labeling specifications: Use LabelImg software to label defective images. The label box should cover the defective area and the overlap rate should be ≥90%. Background areas should be labeled as defect-free areas. Data augmentation includes randomly flipping the training set images horizontally or vertically, adjusting the brightness by ±20%, and adding Gaussian noise σ=10.
[0171] The area-array CCD camera captures images at a resolution of 3072×96 pixels. This aspect ratio design matches the physical characteristics of the fabric unfolding horizontally, ensuring that each frame covers a width of 1.5 meters of fabric. The annotation specifications require that the overlap between the annotation box and the defect area be no less than 90%, and annotation accuracy is ensured through manual verification. In the data augmentation operation, the standard deviation of Gaussian noise is set to 10 to simulate noise interference from industrial cameras while preserving texture details.
[0172] Specifically, the high-resolution setup of the area-array CCD camera can fully capture the continuous surface of the fabric as it unfolds laterally. The 3072-pixel horizontal resolution can identify warp breaks less than 0.5 mm wide, while the 96-pixel vertical resolution, combined with a 50fps frame rate, ensures clear imaging of moving fabric. During annotation, the requirement that the annotation box covers more than 90% of the defect area is achieved through the coordinate verification function of the LabelImg software, avoiding feature mislabeling caused by annotation box offset. In the data augmentation stage, horizontal flipping simulates a two-way movement of the fabric, while vertical flipping enhances the robustness of longitudinal defect recognition. The brightness adjustment range of ±20% covers lighting fluctuations on the production line, and the Gaussian noise parameter σ=10 has been experimentally verified to maintain effective features when PSNR ≥ 30dB. These measures synergistically improve the representational capabilities of the dataset, enabling the model to accurately distinguish between normal textures and minor defects.
[0173] As a preferred embodiment, the solution of this application is implemented as follows: Image acquisition is performed using a CCD area array camera, which is installed at the fabric outlet of the fabric production line. The camera's resolution is set to 3072×96 pixels, and the frame rate is configured to 50 frames per second. During shooting, the illumination intensity is controlled within the range of 500-800 lux to ensure that the image completely covers the 1.5-meter width of the fabric. Defect labeling is performed using LabelImg software. The label box is set to cover the defect area, and the overlap rate between the label box and the actual defect area is not less than 90%. Background labels are defined as defect-free areas. Data augmentation operations include random horizontal or vertical flipping, brightness adjustment within ±20% of the original brightness, and Gaussian noise is added to the training set images, with a noise standard deviation set to 10.
[0174] Through the above technical solutions, this application solves the problem of feature extraction difficulties caused by extreme aspect ratios in fabric images in industrial scenarios. It ensures complete capture of defect details through high-resolution cameras and specific lighting conditions, and improves the accuracy of defect localization by combining precise annotation standards. Data augmentation strategies effectively suppress interference from complex textured backgrounds and enhance the model's robustness to brightness changes and noise contamination, thereby reducing the false negative rate of small-scale defects.
[0175] This application further proposes a fabric defect detection system based on MAC-YOLO, characterized in that it includes:
[0176] Image acquisition module: used to acquire images of the fabric surface in real time and output RGB image data of 3072×96 pixels;
[0177] Preprocessing module: Normalizes the input image (scales pixel values to [0,1]), resizes it (maintains aspect ratio), and filters noise (Gaussian blur kernel 3×3).
[0178] MAC-YOLO detection module: integrates the MFPB, DMS-SP, DSKA, and MSECSP modules described in claims 2-5, and is used for feature extraction and defect detection of preprocessed images;
[0179] Post-processing module: Performs non-maximum suppression (NMS, confidence threshold 0.5, crossover ratio threshold 0.45) on the detection results, and outputs the final defect category and location (bounding box coordinates) information;
[0180] Visualization module: Overlays the detection results onto the original image to generate an labeled detection map.
[0181] The image acquisition module uses a CCD area array camera for real-time acquisition, outputting RGB image data with a resolution of 3072×96 pixels. The camera is mounted directly above the fabric outlet of the fabric production line, with the lens axis at a vertical distance of 80 cm from the fabric surface. The preprocessing module performs normalization on the input image, linearly mapping pixel values to the 0-1 range, and adjusts the image size to 640×640 pixels using bilinear interpolation. A Gaussian filter with a standard deviation of 1.5 is used for noise smoothing. The MAC-YOLO detection module loads the trained model weight file. The morphological fusion preprocessing block performs morphological transformations on the input image using a 1×15 kernel in the horizontal direction and opening / closing operations using a 5×1 kernel in the vertical direction, and enhances features using a channel-space collaborative attention mechanism. The post-processing module uses a non-maximum suppression algorithm, setting the detection box confidence threshold to 0.5 and the intersection-overlap ratio (IoU) overlap threshold to 0.45, filtering out redundant detection boxes. The visualization module overlays the detection box coordinates with the original image pixel by pixel, marks the defect area with a red rectangle, and displays the defect category label in the upper left corner of the detection box.
[0182] Through the above technical solutions, this application achieves real-time and efficient detection of fabric images with abnormal aspect ratios, overcoming the limitations of traditional convolutional neural networks in extracting features of elongated defects. Normalization and noise filtering preprocessing effectively suppress illumination fluctuations and sensor noise interference in the production line environment; the multi-module collaborative feature extraction mechanism enhances the contrast between lateral and longitudinal defects, reducing the interference of complex textured backgrounds on the detection results; the non-maximum suppression post-processing algorithm ensures detection accuracy while avoiding misjudgments caused by repeated bounding boxes; and the visual output provides operators with intuitive defect location information, facilitating rapid quality assessment and production adjustments.
[0183] In some of the solutions mentioned above in this application, the training module has problems such as a single learning rate adjustment strategy, a fixed weight decay method, and an imperfect model saving mechanism when optimizing network parameters. This results in slow model convergence speed, easy getting stuck in local optima, and inability to effectively select the weights with the best generalization performance.
[0184] This application further proposes a training module, including data loading, forward propagation, loss calculation, backpropagation, and model saving operations.
[0185] In this process, data loading reads images and labeled data from the training set, with a batch size of 8 to balance memory usage and gradient stability. Forward propagation inputs images into the network; the classification branch calculates the predicted probability distribution, while the regression branch outputs bounding box parameters. Loss calculation combines binary cross-entropy loss, distribution focus loss, and perfect intersection-union (MIU) loss, summing them by weights to form the total loss. Backpropagation uses the AdamW optimizer with an initial learning rate of 0.000833, a weight decay coefficient of 0.0005, and an exponential decay strategy with a decay factor γ of 0.95. Model saving is performed every 10 training epochs, selecting the optimal weights based on the mAP@50 metric on the test set.
[0186] The MAC-YOLO network was trained using the AdamW optimizer, with an initial learning rate of 0.000833, momentum of 0.9, and weight decay set to [value missing]. The Epoch was set to 200, BatchSize to 8, and num_workers to 16. An ExponentialLR learning rate decay strategy was used to smooth the loss function decline and accelerate convergence. Weights with the lowest loss and best performance during training were selected for testing on the test set. Test set images were input into the network to obtain the final test set prediction map. This map was compared with the label map, and a confusion matrix was constructed based on the pixel-level classification results. Evaluation metrics for assessing detection accuracy were obtained, including Precision, Recall, Mean Average Precision (mAP), and Frames Per Second (FPS).
[0187] Specifically, during the data loading phase, a fixed batch size is used to reduce memory fluctuations and ensure the stability of gradient updates. In the forward propagation phase, the classification loss is calculated using pixel-by-pixel binary cross-entropy, and the regression loss optimizes the probability distribution of bounding box parameters using distributed focus loss, combined with perfect intersection-over-union (MIU) loss to constrain localization accuracy. In the backpropagation phase, the AdamW optimizer avoids excessive parameter regularization by decoupling weight decay and learning rate updates. An exponential decay strategy gradually reduces the learning rate, accelerating convergence initially and fine-tuning parameters later. A model saving mechanism periodically stores intermediate weights, and the model with the best generalization ability is selected through test set performance evaluation to avoid overfitting. This scheme improves model convergence efficiency and detection accuracy through dynamic learning rate adjustment and decoupled optimization strategies, while the periodic weight saving mechanism ensures the robustness of the deployed model.
[0188] As a preferred embodiment, the specific implementation of this application's solution is as follows: During the training module's operation, the data loading stage reads images and annotation information from the training set, loading them in batches of 8 images; during the forward propagation stage, the images are input into the MAC-YOLO network, and the binary cross-entropy loss is calculated through the classification branch, while the distribution focus loss and perfect intersection-union ratio loss are calculated through the regression branch; during the loss calculation stage, the classification loss and regression loss are weighted and summed in a 1:1 ratio, where the regression loss is a linear superposition of the distribution focus loss and the perfect intersection-union ratio loss; during the backpropagation stage, the AdamW optimizer is used to update the network parameters, with the initial learning rate set to 0.000833, the weight decay coefficient set to 0.0005, and the learning rate decreasing by 5% per training cycle according to the exponential decay strategy; during the model saving stage, the model weights are saved after every 10 complete dataset training iterations, and the average accuracy index is calculated on the test set, selecting the weight with the highest mAP@50 value as the final deployment model.
[0189] Through the above technical solutions, this application achieves dynamic optimization of the model training process, effectively balances the gradient update direction of classification and regression tasks, avoids local optima through a phased learning rate adjustment strategy, and suppresses overfitting by combining a weight decay mechanism, thereby improving the robustness of the model in defect detection on fabric images with extreme aspect ratios, while meeting the requirements of industrial production lines for real-time detection efficiency.
[0190] Based on the MAC-YOLO network constructed in this application, and compared with existing mainstream detection models, the experiments are as follows:
[0191] 1. The dataset used is the dataset constructed by training the model in step 2 above;
[0192] 2. Define evaluation indicators:
[0193] The evaluation metric system covers parameter count, floating-point operations (FLOPs), precision, recall, mean average precision (mAP), frames per second (FPS), and giga-point operations per second (GPS). The formulas for calculating precision and recall are as follows: , Where TP (True Positives) represents the number of correctly detected positive samples; FP (False Positives) represents the number of negative samples that were incorrectly predicted as positive samples; and FN (False Negatives) represents the number of undetected positive samples. For each category... Mean precision (AP) is calculated by integrating the results and considering the precision-recall tradeoff at different confidence thresholds. The formula is as follows: The mean precision (mAP) is a measure of the accuracy of all... The average AP values across all categories are taken. .
[0194] Computational efficiency is evaluated using the following metrics: real-time performance is measured in frames per second (FPS), model size is represented by total parameters, and floating-point operations per second (GFLOPs) are used to evaluate the performance. These metrics provide a comprehensive balance between robustness and deployment feasibility.
[0195] Ultimately, the evaluation metrics for the experiment included multiple aspects such as the model's accuracy, robustness, and computational efficiency, ensuring the model's effectiveness and feasibility in practical applications.
[0196] 3. Comparative experiments of different models on the same dataset:
[0197] Based on the same dataset, a comparative experiment was conducted between the MAC-YOLO model proposed in this invention and current mainstream detection models (YOLOv5n, YOLOv6n, YOLOv7, YOLOv8n, YOLOv9t, YOLOv10n, YOLOv11n, YOLOv12n). The experiment focused on seven common types of defects in fabric defect detection (broken warp, double warp, broken weft, weft stripe, fabric skew, tight weft, and loose weft), and used mAP@50, Precision, Recall, parameter size, and GFLOPS as evaluation indicators. Table 1 presents the quantitative results of each model in terms of detection accuracy, parameter size, and computational efficiency.
[0198] Table 1. Quantitative comparison results of different models (bold text indicates optimal data)
[0199]
[0200] Analysis of the data in Table 1 shows that the MAC-YOLO model proposed in this invention significantly outperforms the comparative models in terms of mAP@50, Precision, Recall, and detection accuracy for each defect category. Based on YOLOv8n, this invention improves mAP@50 by 10.4%, and improves the accuracy for difficult-to-detect defects such as broken weft and weft banding by 41.92% and 84.93%, respectively, effectively solving the detection challenges of extreme aspect ratio defects and low-contrast defects. Although the GFLOPs of this invention's model are slightly higher than some lightweight models, its lightweight design through the MFPB morphological preprocessing module and the MSECSP dynamic multi-scale fusion module achieves an optimized balance between parameter quantity and computational efficiency while maintaining a real-time inference speed of 55.72 FPS, meeting the deployment requirements of industrial-grade real-time detection.
[0201] 4. Ablation test
[0202] To accurately evaluate the independent contributions and synergistic effects of MFPB (morphological fusion preprocessing module) and MSECSP (multi-scale enhancement CSP module), four sets of experiments were designed: baseline model (YOLOv8n), baseline + MFPB, baseline + MSECSP, and baseline + MFPB + MSECSP. The analysis was carried out from three aspects: overall performance, typical defect response, and feature visualization.
[0203] Table 2. Ablation experiments under different module configurations (optimal data shown in bold)
[0204]
[0205] As shown in Table 2, MFPB improved single-module precision by 4.0% (from 60.2% to 64.2%), but reduced recall by 7.1% (from 64.5% to 57.4%). This trade-off indicates that MFPB effectively suppresses complex texture interference and reduces false positives (FP) through its complementary top-hat and black-hat operators (horizontal and vertical), but increases false negatives (FN). MSECSP improved single-module mAP@50 by 2.4% (61.9% → 64.3%), while increasing GFLOPS by only 1.5, indicating that its Dynamic Multi-Scale Strip Pooling (DMS-SP) mechanism enhances the overall perception of extreme aspect ratio defects by coordinating global-local horizontal and vertical pooling.
[0206] By combining the two technologies, this invention resulted in a 10.4% increase in mAP@50 (from 61.9% to 72.3%), and a recovery in recall to 66.6%, exceeding the baseline level. This is because MFPB provides denoised features to MSECSP, while MSECSP compensates for the edge details that MFPB may lose through a self-attention mechanism, achieving a closed-loop optimization of "texture suppression-feature enhancement".
[0207] To verify the enhancement mechanism of the morphology fusion preprocessing module (MFPB) in this invention for defects with different spatial characteristics, we performed quantitative analysis on horizontal, vertical and speckled defects, and the results are shown in Table 3.
[0208] Table 3. Improvement in the detection of typical defects by the core module (optimal data is shown in bold).
[0209]
[0210] As shown in Table 3, the MFPB module proposed in this invention significantly improves the detection performance for all defect types. For horizontal bright defects, such as broken weft and loose stumps, the improvement in mAP@50 is significant (84.93% and 49.22%, respectively), which proves the effectiveness of the H-TopHat operator. The H-TopHat operator enhances narrow bright areas by subtracting the result of the opening operation from the original image, making the latitudinal stripe features more prominent. (Heatmap comparison...) Figure 9 The diagram shows that (a) is the original image, (b) is the module input, (c) is the original module output of the baseline model, and (d) is the MFPB module output of MAC-YOLO. The activation region of the baseline model (c) is scattered due to the interference of the periodic latitude and longitude pattern, while the heatmap of MFPB (d) converges more accurately to the defect location, thereby improving the grayscale contrast between the defect and the background.
[0211] For horizontal dark defects, such as weft breaks and tight gaps, the horizontal black hat (H-BlackHat) operator enhances the contrast of dark regions and improves edge gradients by utilizing closed-open residuals. This improves the mAP@50 of weft breaks from 45.8% to 65.0% (an improvement of 36.03%). Heatmap comparison ( Figure 9 The results show that the active region of the baseline model is fragmented, while the heatmap of MFPB(d) focuses on the defect region, enhancing edge contrast and suppressing background noise from the weft yarn, thereby improving detection accuracy.
[0212] In vertical defect detection, the V-TopHat operator improved the mAP@50 of double warp detection from 82.1% to 88.8% by separating bright warp stripes from the background texture. The V-BlackHat operator slightly improved the mAP@50 of warp break defects to 99.5% (an improvement of 0.1%) by expanding dark boundaries and filling gaps. Heatmap comparison ( Figure 9 The results show that the heatmap of MFPB(d) reveals clearer and more concentrated defect activation regions, demonstrating the effectiveness of MFPB in optimizing feature detection and reducing noise.
[0213] For spot defects, such as fabric skew, the multi-scale opening differential operator distinguishes between real anomalies and fiber noise (using 5×5 and 3×3 kernels), thereby improving mAP@50 by 96.62%. (Heatmap comparison) Figure 9 The baseline model (c) shows that the activation regions are scattered. The heatmap of MFPB (d) shows that the location of the red activation regions highly matches the defects in the original image, making the localization of detected defects more precise.
[0214] To evaluate the performance improvement of the multi-scale enhanced CSP module (MSECSP) in fabric defect detection, an ablation experiment (Table 4) and thermographic visualization analysis were designed. Figure 10 The study verified the synergistic effect of its core components, Dynamic Multi-Scale Strip Pooling (DMS-SP) and Decoupled Spatial Attention (DSKA).
[0215] Table 4. Comparison of Ablation Experiment Data
[0216]
[0217] As shown in Table 4, when the baseline model is combined with SPPF, its mAP@50 remains at 61.9%, indicating limited performance improvement. This suggests that a single fixed-scale pooling method is insufficient to effectively model the complex features of defects with extreme aspect ratios, revealing its inadequacy in adapting to multi-morphological defects. When the SPPFCSPC module is introduced, mAP@50 increases to 64.0%, demonstrating the necessity of multi-scale feature fusion for improving detection performance. However, this configuration still relies on a preset fixed-scale division, exhibiting weak adaptability to the dynamic changes in defect morphology during actual detection, and failing to fully address the detection challenges posed by scale variability.
[0218] Further integration of the DSKA (Decoupled Spatial Attention) component significantly improved the precision of the SPPFCSPC+DSKA configuration to 70.1%, thanks to the targeted enhancement of local detail features by the horizontal / vertical separable convolutional kernels. However, due to the over-focus on fine modeling of local textures, the recall of this configuration dropped to 54.6%, reflecting the missed detection problem caused by the loss of global defect contextual information, indicating that simply enhancing local features may destroy the integrity of feature representation.
[0219] In contrast, the SPPFCSPC+DMS-SP configuration employs a dynamic multi-scale strip pooling mechanism. It captures the overall contour of wide defects through global horizontal pooling and preserves detailed features through local vertical pooling, resulting in a recall rate of 57.5% and an mAP@50 of 61.3%. This result demonstrates that the collaborative design of global-local pooling effectively enhances the feature capture capability for wide defects, maintaining a certain level of detail awareness while avoiding the loss of global features.
[0220] The complete MSECSP module (integrating DSKA and DMS-SP) proposed in this experiment achieves a performance breakthrough, with precision, recall, and mAP@50 reaching 77.1%, 61.9%, and 68.8%, respectively, representing a 6.9% improvement over the baseline. This configuration leverages the complementary strengths of DSKA and DMS-SP, avoiding missed detections caused by excessive localization and overcoming the adaptive limitations of fixed-scale pooling. This verifies the technical advantages of dual-component collaboration in multi-scale feature fusion and spatial orientation perception.
[0221] Figure 10 A heatmap comparison between the baseline model and MSECSP is shown, where (a) is the original image, (c) is the SPPF module of the baseline model, and (d) is the MSECSP module of MAC-YOLO. The activation regions generated by the baseline model for weft breaks are scattered, and its localization effect is worse for tight and loose wefts. In contrast, the activation regions generated by MSECSP are more concentrated and continuous, especially for defects with extreme aspect ratios such as tight and loose wefts. The global horizontal pooling of the DMS-SP module effectively captures full-width defects, while the horizontal and vertical separable kernels of the DSKA module accurately locate smaller defects such as fabric skew. These results verify the coordination between DMS-SP and DSKA, which together improve the defect detection accuracy at different scales and orientations.
[0222] The above embodiments merely illustrate several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.
[0223] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A fabric defect detection method based on MAC-YOLO, characterized in that: Includes the following steps: (1) Constructing a MAC-YOLO network, which is an improvement on the YOLOv8 network, specifically including: a. The Morphological Fusion Preprocessing Block (MFPB) is used as the first module of the network input layer; b. The Dynamic Multi-Scale Strip Pooling (DMS-SP) module is used to replace some of the convolutional layers of the original YOLOv8 network; c. Employ a Dynamically Separable Kernel Attention (DSKA) mechanism integrated into the multi-scale feature fusion path; d. Replace the original YOLOv8 SPPF module with a multi-scale enhancement CSP module (MSECSP) integrating DMS-SP and DSKA; (2) Collect fabric surface image datasets, label defect images with defect types (including broken warp, double warp, broken weft, weft band, tight weft, loose weft, crease and background, a total of 8 categories), and randomly divide the dataset into training set and test set in an 8:2 ratio; (3) The MAC-YOLO network is trained using the training set. The AdamW optimizer is used, and the learning rate is adjusted in stages. The loss function includes the binary cross-entropy loss (BCE Loss) of the classification branch and the distribution focus loss (DFL) and complete intersection-union loss (CIoU Loss) of the regression branch. (4) Use the trained MAC-YOLO network to detect the input fabric surface image and output the category and location prediction map of the defects.
2. The fabric defect detection method based on MAC-YOLO according to claim 1, characterized in that: The Morphological Fusion Preprocessing Block (MFPB) includes the following sub-modules: ① Horizontal / Vertical TopHat-BlackHat Operations: Horizontal direction: Perform Top-Hat transformation on the input image using a long horizontal kernel (size 1×15). ) and Black-Hat transform ( ),in As a horizontal structuring element, it is used to enhance the contrast between lateral bright and dark defects. For the input image, For opening operation, This is a closing operation; Vertical direction: Perform similar horizontal operations on the input image using a narrow vertical kernel (size 5×1) to enhance local grayscale changes of vertical defects; ② Multi-scale opening operation differential operation: By calculating the morphological opening operation residuals of small-scale (3×3) and large-scale (5×5) structuring elements, small-scale anomalies are separated from normal textures, defined as... ,in, and These are small-scale and large-scale structural elements, respectively. ③ Channel-spatial collaborative attention (CSA) mechanism: Channel attention weight Generated through Global Average Pooling (GAP) and a fully connected layer, the formula is as follows: ; Spatial attention weights Generated through 3×3 convolution, the formula is: ; The morphological characteristics after fusion are (⊙ represents the Hadamarda complex). in, For global average pooling, , and It is a fully connected layer. The morphological features of fusion.
3. The fabric defect detection method based on MAC-YOLO according to claim 1, characterized in that: The Dynamic Multi-Scale Strip Pooling (DMS-SP) module includes: ① Multi-branch pooling structure: Global horizontal strip pooling (1×W): captures full-width lateral defects, and the output is restored to its original size by 1×1 convolution and bilinear interpolation; Local horizontal strip pooling (1×3): detects segmented small defects while preserving lateral details; Global vertical strip pooling (H×1): Extracts the global structure of longitudinal defects (such as broken meridians); ② Attention-guided dynamic fusion: Weights are generated through channel attention. (Generated by 1×1 convolution), the features of each branch are weighted and fused, and the formula is: ,in, For different pooling branch characteristics, For the corresponding weights.
4. The fabric defect detection method based on MAC-YOLO according to claim 1, characterized in that: The Dynamically Separable Kernel Attention (DSKA) mechanism includes: Horizontal branch: A depthwise separable convolution with a wide kernel (k≫1) is used to extract long-range lateral dependencies, as shown in the formula. , ; Vertical branch: Depth-separable convolutions with narrow kernels (k≪W) preserve vertical details, as shown in the formula. ; Dynamic gated fusion: Weights are generated through global average pooling (GAP) and two 1×1 convolutional layers. and The fusion formula is ( and (where are learnable parameters), .
5. The fabric defect detection method based on MAC-YOLO according to claim 1, characterized in that: The multi-scale enhanced CSP module (MSECSP) includes: ① Parallel convolution and pooling branches: The initial 3×3 convolutional layer captures local texture patterns, and then the DMS-SP module is concatenated to aggregate multi-scale contextual information; ② Feature fusion: The multi-scale features (global horizontal, local horizontal, global vertical) output by DMS-SP are concatenated with the adaptive features (horizontal and vertical) output by DSKA, and then dimensionality reduction is achieved through 1×1 convolution to achieve collaborative optimization of multi-scale and multi-axis features.
6. The fabric defect detection method based on MAC-YOLO according to claim 1, characterized in that: The neck structure of the MAC-YOLO network adopts an improved PAN-FPN structure, specifically including: ① Deep features (1 / 32 resolution) are downsampled to 1 / 16 and 1 / 8 resolution (through convolution with stride 2). ② Shallow features (1 / 8, 1 / 16 resolution) are upsampled to 1 / 8 resolution (through bilinear interpolation). ③ The bidirectional fusion of features (1 / 8 resolution) is input into the detection head, enhancing the feature transfer efficiency of small targets and slender defects.
7. The fabric defect detection method based on MAC-YOLO according to claim 6, characterized in that: The detection head adopts a decoupled design, including: ① Classification branch: Two 3×3 convolutional layers (each followed by ReLU activation), outputting the probability distribution of 7 defect types (size [batch_size, 7, H, W]), using binary cross-entropy loss (BCE Loss), the formula is as follows: ; ②Regression branch: First layer: 3×3 convolutional layer (outputs the center coordinate offset of 4k anchor frames); The second layer: The distributed focus loss (DFL) is used to optimize the bounding box parameter distribution, as shown in the formula below. ; The localization accuracy is optimized by incorporating the Cross-Union Loss (CIoU Loss) formula: .
8. The fabric defect detection method based on MAC-YOLO according to claim 1, characterized in that: The dataset in step (2) is constructed as follows: Image acquisition parameters: A CCD camera with a resolution of 3072×96 pixels and a frame rate of 50fps is used. The camera is set at the fabric outlet of the fabric production line with a light intensity of 500-800 lux to ensure that the image includes the entire width of the fabric. Defect labeling guidelines: Use LabelImg software to label defect images, with the label box covering the defect area (overlap rate ≥ 90%), and background areas labeled as defect-free areas; Data augmentation: Randomly flip (horizontal / vertical), adjust brightness (±20%), and add noise to the training set images to improve the model's generalization ability.
9. A fabric defect detection system based on MAC-YOLO, characterized in that: include: Image acquisition module: used to acquire images of the fabric surface in real time and output RGB image data of 3072×96 pixels; Preprocessing module: Normalizes the input image (scales pixel values to [0,1]), resizes it (preserves aspect ratio), and filters noise (Gaussian blur kernel 3×3). MAC-YOLO detection module: integrates the MFPB, DMS-SP, DSKA, and MSECSP modules described in claims 2-5, and is used for feature extraction and defect detection of preprocessed images; Post-processing module: Performs non-maximum suppression (NMS, confidence threshold 0.5, intersection-over-union threshold 0.45) on the detection results, and outputs the final defect category and location (bounding box coordinates) information; Visualization module: Overlays the detection results onto the original image to generate an labeled detection map.
10. The fabric defect detection method based on MAC-YOLO according to claim 9, characterized in that: It also includes a training module, which is used to perform the following operations: Data loading: Read images and labeled data from the training set and load them in batches (Batch Size=8). Forward propagation: Input the image into the MAC-YOLO network and calculate the classification loss. and regression loss ; Loss Calculation: Total Loss ,in , ; Backpropagation: The network parameters are updated using the AdamW optimizer, and the learning rate is adjusted using an exponential decay strategy; Model saving: The model weights are saved every 10 epochs, and the weight with the highest mAP@50 on the test set is selected as the final model.
Citation Information
Cited By
Electrical secondary drawing component detection method and device based on structure sensing mechanism and medium
CN121458716A
An electrical secondary drawing component detection method and device based on a structure perception mechanism and a medium
CN121458716B
Prefabricated part surface defect lightweight detection method and system based on structure guiding network
CN121746384A
A prefabricated part surface defect lightweight detection method and system based on a structure guided network
CN121746384B
A lung nodule detection method and system based on adaptive multi-scale deformable attention
CN122436200A