Fabric image defect detection method and system based on improved yolov7-tiny of SPD-SE
By introducing an improved SPD-SE module into the YOLOV7-tiny model, the feature loss problem caused by traditional downsampling is solved, thereby improving the accuracy and efficiency of fabric defect detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG UNIV
- Filing Date
- 2024-12-23
- Publication Date
- 2026-07-21
AI Technical Summary
The existing YOLOV7-tiny model suffers from reduced detection accuracy in fabric defect detection due to feature loss caused by traditional pooling downsampling, especially in the identification of small defect features.
The first two MX modules in the backbone feature extraction network of the YOLOV7-tiny model are replaced with the improved SPD-SE module. The SPD-SE module consists of an improved SPD convolution module and an SE attention mechanism module. Through the transformation between size and channel dimensions and the channel attention mechanism, downsampling without information loss is achieved.
It improves the recognition rate of fabric defect detection, enables more accurate location of defect features, and achieves fast and accurate fabric defect detection.
Smart Images

Figure CN119831957B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of deep learning image processing, and in particular relates to a fabric image defect detection method and system based on SPD-SE and an improved YOLOV7-tiny. Background Technology
[0002] Currently, the downsampling techniques used in major classic models employ pooling operations (max pooling or average pooling). While pooling is computationally inexpensive and convenient, it results in a loss of nearly half of the information, which negatively impacts model performance. To address this, Raja Sunkara et al. introduced a novel CNN module tailored for low-resolution images and small objects, called the SPD convolutional module (SPD-Conv). This module achieves this by transforming the size dimension and channel dimension, reducing the size dimension and increasing the channel dimension. Although pooling is computationally inexpensive and convenient, it still results in a loss of nearly half of the information, which negatively impacts model performance. While Raja Sunkara et al.'s SPD convolutional module (SPD-Conv) cleverly avoids the loss of pixel-level information in the feature map, it disrupts the original pixel distribution of the feature map, reducing the detection accuracy of large and medium-sized targets.
[0003] YOLOv7-tiny is suitable for most fields as an object detection model. However, due to the small and few features of fabric defects, traditional pooling downsampling in YOLOv7-tiny can cause pixel-level feature loss, leading to a decrease in model recognition accuracy. Therefore, it is necessary to improve the YOLOv7-tiny network model to ensure that the downsampling operation is completed while preserving as many of the original small and few defect features as possible, thereby improving model performance and ultimately increasing the detection accuracy of fabric image defects. Summary of the Invention
[0004] To address the problems existing in the background art, the purpose of this invention is to propose an improved YOLOV7-tiny fabric image defect detection method and system based on SPD-SE.
[0005] The technical solution adopted in this invention is as follows, including the following steps:
[0006] Step S1: Establish a fabric defect image dataset, including fabric defect images and their corresponding category labels; divide the fabric defect image dataset into a training set and a validation set according to a preset ratio;
[0007] Step S2: Construct an improved YOLOV7-tiny model; the improved YOLOV7-tiny model is mainly obtained by improving the backbone feature extraction network in the YOLOV7-tiny model using the SPD convolutional module and the SE attention mechanism module;
[0008] Step S3: Input the training set and validation set into the constructed improved YOLOV7-tiny model for training to obtain the trained improved YOLOV7-tiny model;
[0009] Step S4: Finally, input the image of the fabric defect to be detected into the trained improved YOLOV7-tiny model, and output the defect detection result of the fabric defect image.
[0010] In step S2, the improved YOLOV7-tiny model is obtained by replacing the first two MX modules in the backbone feature extraction network of the YOLOV7-tiny model with SPD-SE modules. The SPD-SE module is mainly composed of an improved SPD convolution module and an SE attention mechanism module connected together. The improved SPD convolution module is used to convert the size dimension and channel dimension of the input original feature map, increasing the number of feature map channels while reducing the size dimension, thereby compressing the feature map size. The SE attention mechanism module first obtains the weight values of each channel of the compressed feature map, and then uses the channel weight values to assign weights to the feature map, generating a weighted feature map. The size of the weighted feature map is completely consistent with the size of the compressed feature map.
[0011] The SPD-SE module in step S2 is constructed as follows:
[0012] Step S21: First, for the original feature map X with input dimensions S×S×C, the improved SPD convolutional module downsamples the original feature map using a sampling factor scale, dividing the original feature map X into scale... 2 Sub-feature maps; where S represents the side length of the original feature map and C represents the number of channels;
[0013] Step S22 Then, scale 2 The sub-feature maps are merged along the channel dimension to form a new compressed feature map X0. The spatial dimension of the compressed feature map X0 is 1 / scale of the original feature map X, and the channel dimension is scale of the original feature map X. 2 times;
[0014] Step S23: Next, the dimension is S / scale×S / scale×scale 2The compressed feature map X0 of C is input into the SE attention mechanism module. The SE attention mechanism module first performs a global average pooling operation on the compressed feature map X0, which compresses the compressed feature map X0 in spatial dimension, forming a 1×1×scale image. 2 The feature map X' of C is then passed through two consecutive fully connected layers to obtain a feature map with channel attention;
[0015] Step S24: Finally, multiply the feature map with channel attention and the compressed feature map X0 input from the SE attention mechanism module by weight coefficients channel by channel, and finally output the feature map with channel attention and dimension S / scale×S / scale×scale. 2 C's target feature map.
[0016] In step S21, the improved SPD convolution module divides the original feature map into multiple sub-feature maps using the sampling factor scale as follows: In the spatial dimension, the original feature map X is divided equally along both sides using the sampling factor scale as the division number; no division is performed in the channel dimension, so that the original feature map X is uniformly divided into scale. 2 Individual feature map.
[0017] In step S3, when training the improved YOLOV7-tiny model using the training and validation sets, the parameters of the improved YOLOV7-tiny model are updated through backpropagation. During the backpropagation process, the error between the predicted values outputs and the true labels is calculated using the loss function MPDIoU. The parameters of the improved YOLOV7-tiny model are then optimized using the gradient descent method, thus completing the training of the improved YOLOV7-tiny model.
[0018] In step S3, the number of epochs during training of the improved YOLOV7-tiny model is 300, the batch size is 16, the DataLoader is 16, the initial learning rate is 0.0001, the optimizer is Adam, and the input image pixel is 640×640.
[0019] A fabric image defect detection system for implementing the above method includes:
[0020] The data acquisition module is used to acquire a dataset of fabric defect images containing fabric defect images and their corresponding category labels, and to divide the fabric defect image dataset into a training set and a validation set according to a preset ratio;
[0021] The model acquisition module is used to replace the first two MX modules in the backbone feature extraction network of the YOLOV7-tiny model with the SPD-SE module to obtain an improved YOLOV7-tiny model. The SPD-SE module includes an improved SPD convolution module and an SE attention mechanism module.
[0022] The model optimization module is used to input the training set and the validation set into the constructed improved YOLOV7-tiny model for training, and obtain the trained improved YOLOV7-tiny model.
[0023] The data acquisition module is used to input the fabric defect image to be detected into the trained improved YOLOV7-tiny model and output the defect detection results of the fabric defect image.
[0024] The present invention provides a computer program product, including a computer program / instruction, which, when executed by a processor, can implement the improved YOLOV7-tiny fabric image defect detection method based on SPD-SE as described in any of the above embodiments.
[0025] The present invention provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the improved YOLOV7-tiny fabric image defect detection method based on SPD-SE as described in any of the above embodiments.
[0026] This invention provides a computer electronic device, which includes a memory and a processor;
[0027] The memory is used to store computer programs;
[0028] The processor is configured to, when executing the computer program, implement the improved YOLOV7-tiny fabric image defect detection method based on SPD-SE as described in any of the above schemes.
[0029] Currently, most advanced image object detection network models rely heavily on cross-scale feature fusion. Downsampling is an essential operation in this process. The purpose of downsampling is to generate thumbnails of the corresponding images for better feature fusion. However, existing techniques (such as max pooling) achieve downsampling by discarding some pixel information. This loss of half the information significantly impacts the model's detection accuracy. To address this issue, this invention proposes a lossless downsampling module—SPD-SE. This module avoids the fine-grained pixel loss during downsampling, achieving downsampling based on existing information, thereby enabling accurate detection of fabric defects.
[0030] This invention proposes a lossless downsampling module, SPD-SE. This SPD-SE module consists of two parts: one involves an improvement on the sampling method of the classic Spatial Pyramid Dilated Convolution (SPD) module, enabling SPD to retain the pixel-level distribution patterns of the original feature map to the greatest extent possible; the other introduces an SE attention mechanism to learn the relationships between the channels after sampling and concatenation.
[0031] S1) Spatial Pyramid Dilated Convolution (SPD) Module: A novel CNN module tailored for low-resolution images and small objects, called the SPD convolution module (SPD-Conv). This module generates corresponding image thumbnails by transforming the size dimension and channel dimension, thereby reducing the size dimension and increasing the channel dimension. However, the classic SPD convolution module uses interval sampling in the downsampling operation of the original feature map X with dimensions S×S×C: for example, when scale=2, it means dividing it pixel by pixel, with each 2 as a cycle. In this case, there will be S / 2 cycles in the x-direction of the feature map, and the same applies to the y-direction. Thus, the original feature layer will be divided into S... 2 / 4 feature maps, at which point each small feature map is further divided into f 0,1 f 1,1 f 0,0 f 1,1 Then, recombine the feature maps with the same number to form 4 feature maps. Connect these feature maps along the channel dimension to form a complete feature map.
[0032] This method cleverly avoids the loss of pixel-level information in the feature map, but it disrupts the pixel distribution of the original feature map, which reduces the detection accuracy of large and medium-sized targets. Therefore, the sampling method needs to be improved.
[0033] S2) SPD module improvement
[0034] The original SPD module sampling step used an equal-interval sampling principle, which disrupted the original feature layout. The improved method directly divides the original feature map X into scales. 2 =4 consecutive sub-feature maps. The same principle of size-to-channel dimension conversion is used to achieve downsampling. However, instead of interval sampling, we use the original feature maps... Figure 4The feature maps are divided into four equal parts to preserve the original pixel distribution as much as possible. Then, following the SPD post-processing operation, the equally divided feature maps are concatenated along the channel dimension. At this point, compared to SPD convolution, we retain four feature maps with complete pixel distributions. However, compared to the original feature map, the relationship information between the four equally divided feature maps is fragmented and lost. Therefore, we introduce the SE channel attention mechanism module (located at graph e in the improved SPD-SE module structure diagram) to learn and supplement the relationship partitioning between channels.
[0035] The beneficial effects of this invention are as follows:
[0036] This invention improves the downsampling capability of the SPD convolution module by modifying it. After downsampling, the multidimensional fabric defect features are combined with the SE channel attention mechanism to classify the importance of defect feature channels, enabling the model to more accurately locate useful defect features after downsampling, thereby improving the recognition rate of fabric defects and enabling fast and accurate detection of fabric defects. Attached Figure Description
[0037] Figure 1 This is a flowchart of the steps of the present invention;
[0038] Figure 2 This is a structural diagram of the SPD-SE module of the present invention;
[0039] Figure 3 This is a structural diagram of the improved YOLOV7-tiny model of the present invention;
[0040] Figure 4 These are experimental thermodynamic results for various network models in this embodiment;
[0041] Figure 5 This is a system block diagram of the present invention. Detailed Implementation
[0042] The present invention will be described in detail below with reference to specific implementation examples. These examples will help those skilled in the art to further understand the present invention, but do not limit the present invention in any way.
[0043] like Figure 1 As shown, in a preferred embodiment of the present invention, the above-mentioned improved YOLOV7-tiny fabric image defect detection method based on SPD-SE includes the following steps S1 to S4. The specific implementation process of each step will be described in detail below.
[0044] Step S1: Establish a fabric defect image dataset, including fabric defect images and their corresponding category labels; divide the fabric defect image dataset into a training set and a validation set according to a preset ratio of 7:3;
[0045] In this embodiment, the fabric defect image dataset is selected from the TILDA dataset. The TILDA dataset needs to be parsed and converted into a YOLO format readable by the YOLOv7-tiny model. After dividing the fabric defect image dataset into a 7:3 ratio, the training and validation sets are preprocessed separately. Specifically, each fabric defect image in the dataset is first cropped to a 640×640 shape using a transform, then converted into a tensor matrix, and finally loaded into the DataLoader with a batch size of 16. Here, batch size refers to the size of the input data for each training session of the deep learning network.
[0046] Step S2: Construct an improved YOLOV7-tiny model; the improved YOLOV7-tiny model is obtained by improving the backbone feature extraction network in the YOLOV7-tiny model based on the SPD-Conv module and the SE attention mechanism module;
[0047] It should be noted that current leading image object detection network models all rely on cross-scale feature fusion, and downsampling is an essential operation in this process. The purpose of downsampling is to generate thumbnails of the corresponding images for better feature fusion. However, existing techniques (such as max pooling) achieve downsampling by discarding some pixel information. This loss of half the information significantly impacts the model's detection accuracy. To address this issue, this invention proposes a lossless downsampling module—the SPD-SE module. This module avoids the fine-grained pixel loss phenomenon in downsampling operations, achieving downsampling based on the original information, thereby enabling accurate detection of fabric defects.
[0048] In this embodiment of the invention, the improved YOLOV7-tiny model specifically involves improving the backbone feature extraction network in the YOLOV7-tiny model. Specifically, for example... Figure 3As shown, two SPD-SE modules are introduced to replace the first two MX modules to form an improved YOLOv7-tiny model. The SPD-SE module consists of two parts: one involves improving the sampling method of the classic Spatial Pyramid Dilated Convolution (SPD) module, so that SPD retains the pixel-level distribution pattern of the original feature map to the greatest extent, thus constructing the improved SPD convolution module SPD-Conv; the other introduces the SE attention mechanism to learn the relationship between the channels after sampling and concatenation, thus constructing the SE attention mechanism module. Among them, the improved SPD convolution module in the SPD-SE module mainly improves the sampling method of the classic SPD convolution module, while the SE attention mechanism module in the SPD-SE module directly adopts the classic SE attention mechanism module without improvement. Specifically, the improved SPD convolution module is used to transform the size dimension and channel dimension of the input original feature map, increasing the number of feature map channels while reducing the size dimension, thereby compressing the feature map size; the SE attention mechanism module first obtains the weight values of each channel of the compressed feature map, and then uses the channel weight values to assign weights to the feature map, generating a weighted feature map, the size of which is completely consistent with the size of the compressed feature map.
[0049] like Figure 2 As shown, in this embodiment of the invention, the SPD-SE module in step S2 is constructed as follows:
[0050] S21. First, for the original feature map X with input dimensions S×S×C, the improved SPD convolutional module downsamples the original feature map using a sampling factor scale, dividing the original feature map X into scale... 2 Sub-feature maps; where S represents the side length of the original feature map and C represents the number of channels;
[0051] S22, Then, scale 2 The sub-feature maps are merged along the channel dimension to form a new compressed feature map X0. The spatial dimension of the compressed feature map X0 is 1 / scale of the original feature map X, and the channel dimension is scale of the original feature map X. 2 times;
[0052] S23. Next, the dimension is S / scale×S / scale×scale 2 The compressed feature map X0 of C is input into the SE attention mechanism module. The SE attention mechanism module first performs a global average pooling operation on the compressed feature map X0, which compresses the compressed feature map X0 in spatial dimension, forming a 1×1×scale image. 2The feature map X' of C is then passed through two consecutive fully connected layers to obtain a feature map with channel attention;
[0053] S24. Finally, the feature map with channel attention and the compressed feature map X0 input from the SE attention mechanism module are multiplied by weight coefficients channel by channel to finally output a feature map with channel attention and a dimension of S / scale×S / scale×scale. 2 C's target feature map.
[0054] It's important to note that the Spatial Pyramid Dilated Convolution (SPD) module is a novel CNN module specifically designed for low-resolution images and small objects, often referred to as the SPD convolution module (SPD-Conv). This module generates corresponding image thumbnails by transforming the size dimension to the channel dimension, thereby reducing the size dimension and increasing the channel dimension. However, the classic SPD convolution module uses interval sampling during the downsampling operation on the original feature map X of dimension S×S×C. For example, when scale=2, it means dividing the image pixel by pixel, with each 2 as a cycle. This results in S / 2 cycles in the x-direction of the feature map, and the same applies to the y-direction. Thus, the original feature layer is divided into S... 2 / 4 feature maps, at which point each small feature map is further divided into f 0,1 f 1,1 f 0,0 f 1,1 The feature maps with the same number are then recombine to form four feature maps. These feature maps are then concatenated along the channel dimension to form a complete feature map. This method cleverly avoids the loss of pixel-level information in the feature maps, but it disrupts the pixel distribution of the original feature maps, which reduces the detection accuracy of large and medium-sized targets. Therefore, this sampling method needs to be improved.
[0055] In this embodiment, considering that the classic SPD convolutional module sampling step uses the principle of equal-interval sampling, this method will disrupt the original feature layout. The improved version directly divides the original feature map X into scales. 2 =4 consecutive sub-feature maps. The same principle of size-to-channel dimension conversion is used to achieve downsampling. However, instead of interval sampling, the original features are... Figure 4The feature maps are divided into four equal parts to preserve the original pixel distribution to the greatest extent possible. Then, following the SPD post-processing operation, the equally divided feature maps are concatenated along the channel dimension. At this point, compared to SPD convolution, this invention retains four feature maps with complete pixel distributions. However, compared to the original feature map, the relationship information between the four equally divided feature maps is fragmented and lost. Therefore, this invention introduces an SE channel attention mechanism module (located at graph e in the improved SPD-SE module structure diagram) to learn and supplement the relationship division between channels.
[0056] In step S21, the improved SPD convolution module divides the original feature map into multiple sub-feature maps using a sampling factor scale as follows: In the spatial dimension, the original feature map X is divided equally along both sides using the sampling factor scale as the number of divisions; no division is performed in the channel dimension, so that the original feature map X is uniformly divided into scale... 2 Individual feature map.
[0057] Step S3: Input the training set and validation set into the constructed improved YOLOV7-tiny model for training to obtain the trained improved YOLOV7-tiny model;
[0058] In step S3, when training the improved YOLOV7-tiny model using the training and validation sets, the parameters of the improved YOLOV7-tiny model are updated through backpropagation. During the backpropagation process, the error between the predicted values outputs and the true labels is calculated using the MPDIoU loss function. The parameters (i.e., gradient values) of the improved YOLOV7-tiny model are optimized using the gradient descent method, thus completing the training of the improved YOLOV7-tiny model.
[0059] Specifically, when training the YOLOV7-tiny model, all gradients are initialized to 0, and the model training yields predicted values outputs. The loss is calculated by comparing the outputs with the true labels, and then backpropagation is performed to update the gradients.
[0060] In step S3, the number of epochs for training the improved YOLOV7-tiny model is 300, the batch size is 16, the DataLoader is 16, the initial learning rate is 0.0001, the optimizer is Adam, and the input image pixel is 640×640.
[0061] Step S4: Finally, input the image of the fabric defect to be detected into the trained improved YOLOV7-tiny model, and output the defect detection result of the fabric defect image.
[0062] To better demonstrate the specific implementation and technical effects of the present invention, the improved YOLOV7-tiny fabric image defect detection method based on SPD-SE shown in steps S1 to S4 of the above preferred implementation is applied to a specific example.
[0063] Example
[0064] The specific implementation process of the fabric image defect detection method based on SPD-SE and improved YOLOV7-tiny used in this embodiment is as described above and will not be repeated here.
[0065] In this embodiment, different models are compared with the method of the present invention, and the experimental thermograms of the fabric obtained by different models are shown below. Figure 4 As shown. Figure 4 In the diagram, image1-image2 represent two test images; the MaxPooling column represents the fabric image defect detection results obtained using the original YOLOV7-tiny pooling layer; the SPD column represents the fabric image defect detection results obtained using the classic SPD module of Raja Sunkara et al.; and the SPD-SE column represents the fabric image defect detection results obtained using the improved YOLOV7-tiny model of this invention.
[0066] from Figure 4 As can be clearly seen, the SPD module has improved recognition accuracy compared to pooling downsampling, but the model's focused area (red area in the figure) is numerous and complex. The SPD-SE downsampling module of this invention not only improves recognition accuracy, but also enhances the focus of useful features, which greatly shifts the model's attention to useful features, enabling more accurate detection of defects in fabric images.
[0067] It should also be noted that the fabric image defect detection method based on SPD-SE and improved YOLOV7-tiny in the above embodiments can essentially be executed by a computer program or module. Therefore, similarly, based on the same inventive concept, another preferred embodiment of the present invention also provides a fabric image defect detection system based on SPD-SE and improved YOLOV7-tiny, corresponding to the fabric image defect detection method based on SPD-SE provided in the above embodiments. Figure 5 As shown, it includes:
[0068] The data acquisition module is used to acquire a dataset of fabric defect images containing fabric defect images and their corresponding category labels, and to divide the fabric defect image dataset into a training set and a validation set according to a preset ratio;
[0069] The model acquisition module is used to replace the first two MX modules in the backbone feature extraction network of the YOLOV7-tiny model with the SPD-SE module to obtain an improved YOLOV7-tiny model. The SPD-SE module includes an improved SPD convolution module and an SE attention mechanism module.
[0070] The model optimization module is used to input the training set and the validation set into the constructed improved YOLOV7-tiny model for training, and obtain the trained improved YOLOV7-tiny model.
[0071] The data acquisition module is used to input the fabric defect image to be detected into the trained improved YOLOV7-tiny model and output the defect detection results of the fabric defect image.
[0072] It is understood that the fabric image defect detection method based on SPD-SE and improved YOLOV7-tiny described in S1 to S4 above can essentially be implemented by a computer program. Therefore, based on the same inventive concept, another preferred embodiment of the present invention also provides a computer program product corresponding to the fabric image defect detection method based on SPD-SE and improved YOLOV7-tiny provided in the above embodiments. This computer program / instructions, when executed by a processor, can implement the fabric image defect detection method based on SPD-SE and improved YOLOV7-tiny as described in the above embodiments.
[0073] Similarly, based on the same inventive concept, another preferred embodiment of the present invention also provides a computer electronic device corresponding to the improved YOLOV7-tiny fabric image defect detection method based on SPD-SE provided in the above embodiment, which includes a memory and a processor;
[0074] The memory is used to store computer programs;
[0075] The processor is configured to implement the improved YOLOV7-tiny fabric image defect detection method based on SPD-SE in the above embodiments when executing the computer program.
[0076] Furthermore, the logical instructions in the aforementioned memory can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.
[0077] Therefore, based on the same inventive concept, another preferred embodiment of the present invention also provides a computer-readable storage medium corresponding to the improved YOLOV7-tiny fabric image defect detection method based on SPD-SE provided in the above embodiments. The storage medium stores a computer program, which, when executed by a processor, can realize the improved YOLOV7-tiny fabric image defect detection method based on SPD-SE in the above embodiments.
[0078] It is understood that the aforementioned storage media may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Furthermore, the storage media may also be various media capable of storing program code, such as USB flash drives, external hard drives, magnetic disks, or optical discs.
[0079] It is understood that the processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0080] It should also be noted that those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of the system described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here. In the embodiments provided in this application, the division of steps or modules in the system and method is merely a logical functional division, and there may be other division methods in actual implementation. For example, multiple modules or steps may be combined or integrated together, and a module or step may also be split.
[0081] The embodiments described above are merely preferred embodiments of the present invention and are not intended to limit the scope of the present invention. Various modifications and improvements made by those skilled in the art to the technical solutions of the present invention without departing from the spirit of the present invention should fall within the protection scope of the present invention.
Claims
1. A fabric image defect detection method based on SPD-SE using an improved YOLOV7-tiny, characterized in that, Includes the following steps: Step S1: Establish a fabric defect image dataset, including fabric defect images and their corresponding category labels; divide the fabric defect image dataset into a training set and a validation set according to a preset ratio; Step S2: Construct an improved YOLOV7-tiny model; the improved YOLOV7-tiny model is mainly obtained by improving the backbone feature extraction network in the YOLOV7-tiny model using the SPD convolutional module and the SE attention mechanism module; Step S3: Input the training set and validation set into the constructed improved YOLOV7-tiny model for training to obtain the trained improved YOLOV7-tiny model; Step S4: Finally, input the image of the fabric defect to be detected into the trained improved YOLOV7-tiny model, and output the defect detection result of the fabric defect image to be detected. In step S2, the improved YOLOV7-tiny model is obtained by replacing the first two MX modules in the backbone feature extraction network of the YOLOV7-tiny model with SPD-SE modules. The SPD-SE module is mainly composed of an improved SPD convolution module and an SE attention mechanism module connected together; The improved SPD convolution module is used to convert the size dimension and channel dimension of the input original feature map, thereby increasing the number of feature map channels while reducing the size dimension, thus achieving feature map size compression. The SE attention mechanism module first obtains the weight values of each channel of the compressed feature map, and then uses the channel weight values to assign weights to the feature map to generate a weighted feature map. The size of the weighted feature map is exactly the same as the size of the compressed feature map. The SPD-SE module in step S2 is constructed as follows: Step S21: First, for the original feature map X with input dimensions S×S×C, the improved SPD convolutional module downsamples the original feature map using a sampling factor scale, dividing the original feature map X into scale... 2 Sub-feature maps; where S represents the side length of the original feature map and C represents the number of channels; In step S21, the improved SPD convolution module divides the original feature map into multiple sub-feature maps using a sampling factor scale in the following specific way: In the spatial dimension, the original feature map X is divided equally along both sides using the sampling factor "scale" as the number of divisions. No division is performed in the channel dimension, resulting in the original feature map X being uniformly divided into scales. 2 Individual feature maps; Step S22 Then, scale 2 The sub-feature maps are merged along the channel dimension to form a new compressed feature map X0. The spatial dimension of the compressed feature map X0 is 1 / scale of the original feature map X, and the channel dimension is scale of the original feature map X. 2 times; Step S23: Next, the dimension is S / scale×S / scale×scale 2 The compressed feature map X0 of C is input into the SE attention mechanism module. The SE attention mechanism module first performs a global average pooling operation on the compressed feature map X0, which compresses the compressed feature map X0 in spatial dimension, forming a 1×1×scale image. 2 The feature map X' of C is then passed through two consecutive fully connected layers to obtain a feature map with channel attention; Step S24: Finally, multiply the feature map with channel attention and the compressed feature map X0 input from the SE attention mechanism module by weight coefficients channel by channel, and finally output the feature map with channel attention and dimension S / scale×S / scale×scale. 2 C's target feature map.
2. The fabric image defect detection method based on SPD-SE and improved YOLOV7-tiny according to claim 1, characterized in that: In step S3, when training the improved YOLOV7-tiny model using the training and validation sets, the parameters of the improved YOLOV7-tiny model are updated through backpropagation. During the backpropagation process, the error between the predicted values outputs and the true labels is calculated using the loss function MPDIoU. The parameters of the improved YOLOV7-tiny model are then optimized using the gradient descent method, thus completing the training of the improved YOLOV7-tiny model.
3. The fabric image defect detection method based on SPD-SE and improved YOLOV7-tiny according to claim 1, characterized in that: In step S3, the number of epochs during training of the improved YOLOV7-tiny model is 300, the batch size is 16, the DataLoader is 16, the initial learning rate is 0.0001, the optimizer is Adam, and the input image pixel is 640×640.
4. A fabric image defect detection system for implementing the method according to any one of claims 1-3, characterized in that, include: The data acquisition module is used to acquire a dataset of fabric defect images containing fabric defect images and their corresponding category labels, and to divide the fabric defect image dataset into a training set and a validation set according to a preset ratio; The model acquisition module is used to replace the first two MX modules in the backbone feature extraction network of the YOLOV7-tiny model with the SPD-SE module to obtain an improved YOLOV7-tiny model. The SPD-SE module includes an improved SPD convolution module and an SE attention mechanism module. The model optimization module is used to input the training set and the validation set into the constructed improved YOLOV7-tiny model for training, and obtain the trained improved YOLOV7-tiny model. The data acquisition module is used to input the fabric defect image to be detected into the trained improved YOLOV7-tiny model and output the defect detection results of the fabric defect image.
5. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the fabric image defect detection method according to any one of claims 1-4.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the fabric image defect detection method according to any one of claims 1-4.