Fabric image defect detection method and system based on improved YOLOV7-tiny
By introducing an improved ECA attention mechanism module into the YOLOV7-tiny model, the problem of poor detection performance in fabric defect detection is solved, achieving higher detection accuracy and speed, and adapting to the diversity of fabric textures and backgrounds.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG UNIV
- Filing Date
- 2024-12-23
- Publication Date
- 2026-06-26
Smart Images

Figure CN119832315B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of fabric defect detection, and particularly relates to an improved YOLOV7-tiny fabric image defect detection method and system based on ECA. Background Technology
[0002] Automatic fabric defect detection technologies can be broadly categorized into three types: traditional methods, classical object detection models, and deep learning-based methods. Based on fundamental image processing principles, current detection techniques can be divided into structural, statistical, spectroscopic, and learning methods. Lan Di et al. used quaternion images to represent fabrics and enhanced defect visibility through two-dimensional fractional Fourier transform. While effective for various defect types, the effectiveness of feature amplification diminishes if defect features disappear during downsampling. Xuan Ji et al. used Gabor filters with SLIC for preliminary defect identification. Although this method is effective in capturing subtle differences in fabric texture, it faces difficulties in dynamic parameter optimization. On the other hand, Li et al. fused oriented gradient histograms (HOG) with low-rank decomposition models, achieving commendable detection results. However, the computationally intensive nature of HOG limits the detection speed of this method. These traditional methods can accurately locate defects within specific fabric patterns or backgrounds. Nevertheless, modern production standards still require adaptation to different textures and backgrounds, as well as high detection accuracy and efficiency.
[0003] When using deep CNN models to identify fabric defect images, local information is typically extracted from the image using convolutional kernels. However, the influence of each local information on whether the image can be correctly identified varies. To enable the model to understand the importance of different local information in the image, attention mechanisms have emerged. Visual attention is an innate ability of the human brain. When we see an image, we first quickly scan it and then lock onto the target area that needs our focus. For example, when observing an image, our attention easily focuses on faces, article titles, and the first sentence of an article. Imagine if every piece of local information were overlooked; it would consume a lot of energy, which would be detrimental to human survival and evolution. Similarly, introducing a similar mechanism into deep learning networks can simplify the model and accelerate computation. Due to the numerous and difficult-to-analyze feature parameters in the intermediate layers of deep learning models, the importance of each pixel cannot be considered when designing the attention mechanism module. To achieve lightweight design, researchers generally represent the feature information of a single channel by max pooling or average pooling. The resulting feature map becomes a single channel through pooling, and then the importance of each channel is determined through parameter learning and backpropagation updates.
[0004] Existing attention mechanisms use global pooling to represent all the information of a channel. However, both the pooling result and the model parameters affect the model's classification of channel importance, and changes in both will slow down the convergence speed of model parameter updates. Furthermore, neither max pooling nor average pooling can replace all the information of an entire channel feature map. If two different feature maps A and B have the same pooling result, it will interfere with the classification of channel importance.
[0005] YOLOV7-tiny is suitable for most fields as a target detection model, but due to the inherent characteristics of fabric defects, it brings many challenges to target detection. In practical applications, YOLOV7-tiny has poor fabric defect detection performance. Therefore, it is necessary to improve the YOLOV7-tiny network model to improve detection accuracy. Summary of the Invention
[0006] The purpose of this invention is to solve the problems existing in the prior art and to provide an improved YOLOV7-tiny fabric image defect detection method and system based on ECA.
[0007] To achieve the above-mentioned objectives, the present invention specifically adopts the following technical solution:
[0008] In a first aspect, the present invention provides an improved YOLOV7-tiny fabric image defect detection method based on ECA, comprising the following steps:
[0009] S1. Obtain a dataset of fabric defect images containing fabric defect images and their corresponding category labels, and divide the fabric defect image dataset into a training set and a validation set according to a preset ratio;
[0010] S2. Replace the last smooth convolutional layer CBL of the first MCB module in the backbone feature extraction network of the YOLOV7-tiny model with the ECA improved attention mechanism module to obtain the improved YOLOV7-tiny model. The ECA improved attention mechanism module includes a squeezing module and an activation module.
[0011] S3. Input the training set and the validation set into the constructed improved YOLOV7-tiny model for training to obtain the trained improved YOLOV7-tiny model;
[0012] S4. 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 to be detected.
[0013] Based on the above scheme, each step can be implemented in the following preferred manner.
[0014] As a preferred embodiment of the first aspect above, the processing flow in the ECA improved attention mechanism module in step S2 is as follows:
[0015] S21. First, for the original feature map with dimensions B×H×W×C, the compression module assigns a channel importance value of 1 to each channel in the original feature map, so that the original feature map is compressed into a feature vector with dimensions B×1×1×C; where B, H, W, and C represent the number of fabric defect images, the height of the fabric defect images, the width of the fabric defect images, and the number of channels in a training session, respectively.
[0016] S22. Then, the activation module obtains the size of the one-dimensional convolution kernel based on the number of channels in the feature vector, and uses the size of the one-dimensional convolution kernel in the one-dimensional convolution to obtain the weight value of each channel in the feature vector.
[0017] S23. Next, the excitation module uses the sigmoid activation function to limit the weight values of each channel to between 0 and 1, and uses the output of the sigmoid activation function as the importance weight coefficient of each channel.
[0018] S24. Finally, the activation module multiplies the importance weight coefficients of each channel with the original feature map channel by channel to generate a weighted feature map.
[0019] As a preferred embodiment of the first aspect above, in the ECA improved attention mechanism module of step S23, the importance weight coefficients of each channel are obtained according to the following formula:
[0020] w=σ(C1D k (E 1×C ))
[0021] Where w is the importance weight coefficient for each channel; σ() represents the sigmoid activation function; C1D k () represents a one-dimensional convolution with a kernel size of k; E 1×C This represents a feature vector with dimensions B×1×1×C.
[0022] As a preferred embodiment of the first aspect mentioned above, in step S3, when training the improved YOLOV7-tiny model using the training set and validation set, 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, and the parameters of the improved YOLOV7-tiny model are optimized using the gradient descent method to complete the training of the improved YOLOV7-tiny model.
[0023] As a preferred embodiment of the first aspect mentioned above, in step S3, the number of training rounds 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 size of the fabric defect image input to the improved YOLOV7-tiny model is 640×640.
[0024] Secondly, the present invention provides an improved YOLOV7-tiny fabric image defect detection system based on ECA, comprising:
[0025] 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;
[0026] The model acquisition module is used to replace the last smooth convolutional layer CBL of the first MCB module in the backbone feature extraction network of the YOLOV7-tiny model with the ECA improved attention mechanism module to obtain the improved YOLOV7-tiny model. The ECA improved attention mechanism module includes a squeezing module and an activation module.
[0027] 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.
[0028] 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.
[0029] Thirdly, 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 ECA as described in any of the solutions of the first aspect above.
[0030] Fourthly, 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 ECA as described in any of the solutions of the first aspect above.
[0031] Fifthly, the present invention provides a computer electronic device, which includes a memory and a processor;
[0032] The memory is used to store computer programs;
[0033] The processor is configured to, when executing the computer program, implement the improved YOLOV7-tiny fabric image defect detection method based on ECA as described in any of the embodiments of the first aspect above.
[0034] Compared with the prior art, the present invention has the following advantages:
[0035] 1. This invention can improve the channel attention analysis capability of the ECA attention mechanism for multidimensional defect features during fabric defect detection, making the improved YOLOV7-tiny model pay more attention to useful feature regions.
[0036] 2. The improved YOLOV7-tiny model of this invention can accelerate convergence, focus on useful features, and improve recognition accuracy, thus enabling rapid and accurate detection of fabric defects.
[0037] 3. This invention improves upon the existing classic ECA channel attention mechanism module and introduces the improved ECA channel attention mechanism module into the YOLOV7-tiny model, thereby achieving rapid and accurate detection of fabric defects. Attached Figure Description
[0038] Figure 1 This is a flowchart of the steps of the present invention;
[0039] Figure 2 This is a structural diagram of the ECA improved attention mechanism module of the present invention;
[0040] Figure 3 This is a block diagram of the classic ECA channel attention mechanism module.
[0041] Figure 4 This is a structural diagram of the improved YOLOV7-tiny model of this invention;
[0042] Figure 5 This is an image showing the experimental results of fabric defects obtained using the improved YOLOV7-tiny model in this invention;
[0043] Figure 6 This is an experimental result image of fabric defects obtained using the classic ECA channel attention mechanism module;
[0044] Figure 7 This is a system block diagram of the present invention. Detailed Implementation
[0045] To make the above-mentioned objects, features, and advantages of the present invention more apparent and understandable, the specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Many specific details are set forth in the following description to provide a thorough understanding of the present invention. However, the present invention can be practiced in many other ways different from those described herein, and those skilled in the art can make similar modifications without departing from the spirit of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below. Technical features in the various embodiments of the present invention can be combined accordingly without mutual conflict.
[0046] 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 ECA includes the following steps S1 to S4. The specific implementation process of each step will be described in detail below.
[0047] S1. Obtain a fabric defect image dataset containing fabric defect images and their corresponding category labels, and divide the fabric defect image dataset into a training set and a validation set according to a preset ratio.
[0048] It should be noted that in this embodiment of the invention, the fabric defect image dataset is selected from the TILDA dataset, and the TILDA dataset needs to be parsed and converted into YOLO format that can be read by the YOLOv7-tiny model. After dividing the above fabric defect image dataset into a 7:3 ratio, the training set and validation set are preprocessed separately. Specifically, firstly, each fabric defect image in the dataset is cropped to a 640×640 shape using the transform method, then the cropped fabric defect images are converted into tensor matrices, and then 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 network in deep learning.
[0049] S2. Replace the last smooth convolutional layer CBL of the first MCB module in the backbone feature extraction network of the YOLOV7-tiny model with the ECA improved attention mechanism module to obtain the improved YOLOV7-tiny model. The ECA improved attention mechanism module includes a squeezing module and an activation module.
[0050] 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 4As shown, by replacing the last smooth convolutional layer (CBL) of the first MCB module in the backbone feature extraction network of the YOLOV7-tiny model with the ECA improved attention mechanism module, the improved YOLOV7-tiny model can be obtained. Figure 2 As shown, the ECA improved attention mechanism module is specifically divided into two modules: squeezing and activation. The squeezing module compresses the original feature map of dimension B×H×W×C into a feature vector of dimension B×1×1×C. The activation module first performs a one-dimensional convolution on the feature vector of dimension B×1×1×C to obtain the weight values of each channel, and then uses the channel weight values to assign weights to the original feature map to generate a weighted feature map. The size of the weighted feature map is exactly the same as that of the original feature map.
[0051] The following section will first introduce the principle of the ECA channel attention mechanism. For example... Figure 3 As shown, the classic ECA channel attention mechanism module first performs global average pooling on each channel of the original feature map, pooling each pixel into a single pixel to represent the information of that channel. The formula is as follows:
[0052] y i =(GAP(c i ))
[0053] y = cat channel y i (i∈[0~C-1])
[0054] Where GAP() represents the global average pooling operation; c i Represents the feature map of the i-th channel; y i This represents the result of global average pooling for the i-th channel; C represents the total number of channels; cat channel This indicates that concatenation is performed along the channel dimension.
[0055] Then, one-dimensional convolution is used to learn the importance of each channel, as shown in the following formula;
[0056] w=σ(C1D k (y))
[0057] Where w is the importance weight coefficient for each channel, σ() represents the sigmoid activation function; C1D() represents one-dimensional convolution; and k represents the convolution kernel size.
[0058] Finally, the learned channel importance components are weighted and applied to the corresponding channels of the original feature map. During backpropagation, both the pooling results and the one-dimensional convolution parameters are updated and changed. This dual change is detrimental to model convergence and may lead to local optima. Furthermore, neither max pooling nor average pooling can replace all the information of an entire channel feature map. If two different feature maps A and B have the same pooling result, it will interfere with the classification of channel importance. Therefore, the classic ECA channel attention mechanism needs to be improved. Specifically, assuming a feature map X(B,H,W,C), the operation of discarding the pooling result to replace the information of the entire feature map, adhering to the principle of treating all channels equally, assigns an importance value of 1 to each channel, i.e., (B,1,1,C), and then learns channel importance through one-dimensional convolution; finally, the learned channel importance components are weighted and applied to the corresponding channels of the original feature map. The method of this invention introduces the principle of controlled variables, limiting the factors affecting the classification of channel importance in the model to the parameter updates of one-dimensional convolution, reducing parameter variations and accelerating model convergence. It also avoids erroneous interference caused by the same pooling result from different feature maps. The purpose of this invention is to improve the ECA channel attention mechanism, taking it as an example, to accelerate model convergence and improve model performance compared to previous methods.
[0059] It should be noted that, in this embodiment of the invention, the purpose is to improve the ECA channel attention mechanism, taking it as an example, so that it can accelerate the model convergence speed and improve the model performance to a certain extent compared to the previous one. For example... Figure 2 As shown, in step S2, the processing flow in the ECA improved attention mechanism module is as follows:
[0060] S21. First, for the original feature map with dimensions B×H×W×C, the compression module assigns a channel importance value of 1 to each channel in the original feature map, so that the original feature map is compressed into a feature vector with dimensions B×1×1×C; where B, H, W, and C represent the number of fabric defect images, the height of the fabric defect images, the width of the fabric defect images, and the number of channels in a training session, respectively.
[0061] S22. Then, the activation module obtains the one-dimensional convolution kernel size k based on the number of channels C of the feature vector of dimension B×1×1×C, and uses the one-dimensional convolution kernel size k in the one-dimensional convolution to obtain the weight values of each channel in the feature vector of dimension B×1×1×C.
[0062] S23. Next, the excitation module uses the sigmoid activation function to limit the weight values of each channel to between 0 and 1, and uses the output of the sigmoid activation function as the importance weight coefficient of each channel.
[0063] S24. Finally, the activation module multiplies the importance weight coefficients of each channel with the original feature map channel by channel to generate a weighted feature map.
[0064] Furthermore, in the ECA improved attention mechanism module of this embodiment, the importance weight coefficient of each channel is obtained according to the following formula:
[0065] w=σ(C1D k (E 1×C ))
[0066] Where w is the importance weight coefficient for each channel, σ() represents the sigmoid activation function; C1D k () represents a one-dimensional convolution with a kernel size of k; E 1×C This represents a feature vector with dimensions B×1×1×C.
[0067] S3. Input the training set and the validation set into the constructed improved YOLOV7-tiny model for training to obtain the trained improved YOLOV7-tiny model.
[0068] It should be noted 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 backpropagation, the error between the predicted values (outputs) and the true labels (labels) is calculated using the MPDIoU loss function. The parameters (i.e., gradient values) of the improved YOLOV7-tiny model are then optimized using gradient descent, completing the training of the improved YOLOV7-tiny model. Specifically, when training the improved YOLOV7-tiny model, all gradients are initialized to 0. The improved YOLOV7-tiny model is trained to obtain predicted values (outputs). The loss is calculated by comparing the outputs with the true labels, and then backpropagation is performed to update the gradients.
[0069] In step S3 of this embodiment of the invention, 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 fabric defect image of the improved YOLOV7-tiny model is 640×640.
[0070] S4. 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 to be detected.
[0071] To better demonstrate the specific implementation and technical effects of the present invention, the improved YOLOV7-tiny fabric image defect detection method based on ECA shown in steps S1 to S4 of the above preferred implementation is applied to a specific example.
[0072] Example
[0073] The specific implementation process of the improved YOLOV7-tiny fabric image defect detection method based on ECA used in this embodiment is as described above and will not be repeated here.
[0074] This embodiment uses evaluation metrics to assess the obtained defect detection results. Specifically, this embodiment uses six common evaluation metrics in the field of object detection (i.e., precision P, recall(R), F1-score, mean precision mAP, model parameters Parm., and frames per second (FPS). These evaluation metrics used in this embodiment include two aspects: localization accuracy and model complexity. This embodiment of the invention uses precision P, recall, F1-score, and mean precision mAP to evaluate the classification and localization accuracy of the proposed method. The calculation formulas are shown below.
[0075]
[0076] In the above formula:
[0077]
[0078] Where C represents the number of defect categories in the dataset samples; TP k True Positive refers to the number of true k-class samples that are correctly classified; FN k (False Negative) refers to the number of true k-class samples that were incorrectly classified. k (False Positive) refers to a sample that is incorrectly identified as a true sample; AP k It is P k -R k The area enclosed by the curve and the coordinate axes; the comprehensive index mAP is the mean of the average accuracy (AP) of all categories of detection results; P k R represents the precision of the k-th class of samples; the subscript k is the ordinal number of the sample class; k Let be the recall rate of the k-th class of samples; similarly, the F1-score evaluation metric is also calculated using a combination of P and R values. In particular, the model parameters (Parm.) and FPS evaluation metrics are used to assess the complexity of the model proposed in this paper.
[0079] Example 1:
[0080] The experimental results of Example 1 are shown in Table 1 and Figure 5 As shown.
[0081] Table 1: Evaluation Index Results of Example 1
[0082] Class Images Labels P R mAP@.5 mAP@.5:.95 all 790 760 0.87 0.796 0.881 0.575 wire 790 187 0.88 0.717 0.858 0.504 spot 790 195 0.896 0.973 0.973 0.726 hole 790 190 0.894 0.932 0.967 0.631 dark_thread 790 188 0.809 0.564 0.727 0.438
[0083] Where, all represents all defects; wire represents line defects; spot represents spot defects; hole represents hole defects; dark_thread represents dark line defects; Images represents the number of fabric defect images; Labels represents the number of labels; p represents precision; R represents recall; mAP@0.5 represents the AP calculated for all images in each class when IoU is set to 0.5, and then the average is calculated for all classes; mAP@.5:.95 represents the average mAP at different IoU thresholds (from 0.5 to 0.95, with a step size of 0.05) (0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95).
[0084] Comparative Example 1:
[0085] The implementation steps of Comparative Example 1 and the Implementation Example are basically the same, except that: in step S2 of Comparative Example 1, the improved YOLOV7-tiny model is obtained by replacing the last smooth convolutional layer CBL of the first MCB module in the backbone feature extraction network of the YOLOV7-tiny model with the classic ECA attention mechanism module. The classic ECA attention mechanism module, such as... Figure 3 As shown.
[0086] The experimental results of Comparative Example 1 are shown in Table 2 and Figure 6 As shown.
[0087] Table 2: Evaluation Indicator Results for the Comparison
[0088]
[0089]
[0090] Comparing the table above, it is easy to see that, after 300 training rounds, the improved ECA module significantly outperforms the original ECA attention module in all subcategories, whether it is mAP@.5 or mAP@.5:.95, demonstrating faster convergence speed and higher recognition accuracy and speed.
[0091] It should also be noted that the improved YOLOV7-tiny fabric image defect detection method based on ECA 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 an improved YOLOV7-tiny fabric image defect detection system based on ECA, corresponding to the improved YOLOV7-tiny fabric image defect detection method based on ECA provided in the above embodiments, such as... Figure 7 As shown, it includes:
[0092] 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;
[0093] The model acquisition module is used to replace the last smooth convolutional layer CBL of the first MCB module in the backbone feature extraction network of the YOLOV7-tiny model with the ECA improved attention mechanism module to obtain the improved YOLOV7-tiny model. The ECA improved attention mechanism module includes a squeezing module and an activation module.
[0094] 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.
[0095] 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.
[0096] It is understood that the improved YOLOV7-tiny fabric image defect detection method based on ECA 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 improved YOLOV7-tiny fabric image defect detection method based on ECA provided in the above embodiments. This product includes a computer program / instructions, which, when executed by a processor, can implement the improved YOLOV7-tiny fabric image defect detection method based on ECA as described in the above embodiments.
[0097] 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 ECA provided in the above embodiments, which includes a memory and a processor;
[0098] The memory is used to store computer programs;
[0099] The processor is configured to implement the improved YOLOV7-tiny fabric image defect detection method based on ECA in the above embodiments when executing the computer program.
[0100] 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.
[0101] 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 ECA 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 ECA in the above embodiments.
[0102] 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.
[0103] 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.
[0104] 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.
[0105] The embodiments described above are merely preferred embodiments of the present invention and are not intended to limit the invention. Those skilled in the art can make various changes and modifications without departing from the spirit and scope of the invention. Therefore, all technical solutions obtained through equivalent substitution or transformation fall within the protection scope of the present invention.
Claims
1. An improved YOLOv7-tiny fabric image defect detection method based on ECA, characterized in that, Includes the following steps: S1. Obtain a dataset of fabric defect images containing fabric defect images and their corresponding category labels, and divide the fabric defect image dataset into a training set and a validation set according to a preset ratio; S2. Replace the last smooth convolutional layer CBL of the first MCB module in the backbone feature extraction network of the YOLOV7-tiny model with the ECA improved attention mechanism module to obtain the improved YOLOV7-tiny model. The ECA improved attention mechanism module includes a squeezing module and an activation module. S3. Input the training set and the validation set into the constructed improved YOLOV7-tiny model for training to obtain the trained improved YOLOV7-tiny model; S4. Input the fabric defect image 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 processing flow in the ECA improved attention mechanism module is as follows: S21. First, for the original feature map with dimensions B×H×W×C, the compression module assigns a channel importance value of 1 to each channel in the original feature map, so that the original feature map is compressed into a feature vector with dimensions B×1×1×C; where B, H, W, and C represent the number of fabric defect images, the height of the fabric defect images, the width of the fabric defect images, and the number of channels in a training session, respectively. S22. Then, the activation module obtains the size of the one-dimensional convolution kernel based on the number of channels in the feature vector, and uses the size of the one-dimensional convolution kernel in the one-dimensional convolution to obtain the weight value of each channel in the feature vector. S23. Next, the activation module uses the sigmoid activation function to limit the weight values of each channel to between 0 and 1, and uses the output of the sigmoid activation function as the importance weight coefficient of each channel. S24. Finally, the activation module multiplies the importance weight coefficients of each channel with the original feature map channel by channel to generate a weighted feature map.
2. The improved YOLOV7-tiny fabric image defect detection method based on ECA as described in claim 1, characterized in that, In step S23, the importance weight coefficients of each channel in the ECA improved attention mechanism module are obtained according to the following formula: ; in, The importance weighting coefficient for each channel; This represents the sigmoid activation function; This represents a one-dimensional convolution with a kernel size of k. This represents a feature vector with dimensions B×1×1×C.
3. The improved YOLOV7-tiny fabric image defect detection method based on ECA as described in 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 MPDIoU loss function. The parameters of the improved YOLOV7-tiny model are optimized using the gradient descent method, thus completing the training of the improved YOLOV7-tiny model.
4. The improved YOLOV7-tiny fabric image defect detection method based on ECA as described in claim 1, characterized in that, In step S3, the number of training rounds for 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 size of the fabric defect image input to the improved YOLOV7-tiny model is 640×640.
5. A fabric image defect detection system based on ECA and improved YOLOv7-tiny, 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 last smooth convolutional layer CBL of the first MCB module in the backbone feature extraction network of the YOLOV7-tiny model with the ECA improved attention mechanism module to obtain the improved YOLOV7-tiny model. The ECA improved attention mechanism module includes a squeezing module and an activation 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 to be detected. The processing flow in the ECA improved attention mechanism module within the model acquisition module is as follows: S21. First, for the original feature map with dimensions B×H×W×C, the compression module assigns a channel importance value of 1 to each channel in the original feature map, so that the original feature map is compressed into a feature vector with dimensions B×1×1×C; where B, H, W, and C represent the number of fabric defect images, the height of the fabric defect images, the width of the fabric defect images, and the number of channels in a training session, respectively. S22. Then, the activation module obtains the size of the one-dimensional convolution kernel based on the number of channels in the feature vector, and uses the size of the one-dimensional convolution kernel in the one-dimensional convolution to obtain the weight value of each channel in the feature vector. S23. Next, the activation module uses the sigmoid activation function to limit the weight values of each channel to between 0 and 1, and uses the output of the sigmoid activation function as the importance weight coefficient of each channel. S24. Finally, the activation module multiplies the importance weight coefficients of each channel with the original feature map channel by channel to generate a weighted feature map.
6. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they can implement the improved YOLOV7-tiny fabric image defect detection method based on ECA as described in any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the improved YOLOV7-tiny fabric image defect detection method based on ECA as described in any one of claims 1 to 4.
8. A computer electronic device, characterized in that, Including memory and processor; The memory is used to store computer programs; The processor is configured to, when executing the computer program, implement the improved YOLOV7-tiny fabric image defect detection method based on ECA as described in any one of claims 1 to 4.