ECA-based improved YOLOV7-tiny fabric image defect detection method and system
By introducing ECA improved attention mechanism module in the YOLOV7-tiny model, the problem of low accuracy in fabric defect detection is solved, and the rapid and accurate detection of fabric defects is achieved.
Patent Information
- Application Number
- CN202411898961.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2044-12-23
AI Technical Summary
The existing YOLOV7-tiny model is not effective in fabric defect detection, making it difficult to effectively identify multi-dimensional defect characteristics in fabric, resulting in low detection accuracy.
In the backbone feature extraction network of the YOLOV7-tiny model, the last smooth convolution layer CBL that replaces the first MCB module is an ECA improved attention mechanism module, including the extrusion module and the excitation module, and learn the channel importance weight through one-dimensional convolution and sigmod activation functions.
The ECA attention mechanism in fabric defect detection has improved the channel attention analysis ability of multi-dimensional defect characteristics, accelerates the convergence speed of model, improves the recognition accuracy, and achieves rapid and accurate detection of fabric defects.
Smart Images

Figure CN119832315A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of fabric defect detection, and in particular relates to a fabric image defect detection method and system based on an improved YOLOV7-tiny using ECA. Background Art
[0002] Automatic fabric defect detection techniques are broadly classified into three types: traditional methods, classical object detection models, and deep learning-based methods. Based on the basic principles of image processing, current detection techniques are classified into structural, statistical, spectral, and learning methods. Lan Di et al. used quaternion images to represent fabrics and enhanced defect visibility through two-dimensional fractional Fourier transform. Although effective for various defect types, the utility of feature amplification is reduced if the defect features disappear during the downsampling process. 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 has difficulties in dynamic parameter optimization. On the other hand, Li et al. fused the histogram of oriented gradients (HOG) with a low-rank decomposition model, and the results were commendable detection results. Nevertheless, the intensive computational requirements of HOG limit the detection speed of this method. These traditional methods can accurately locate defects in 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 a deep CNN model to identify fabric defect images, the local information of the image is generally extracted through the convolution kernel. However, the influence of each local information on whether the image can be correctly identified is different. In order to let the model know the importance of different local information in the image, the attention mechanism came into being. The visual attention mechanism is an innate ability of the human brain. When we see a picture, we first quickly scan the picture and then lock the target area that needs to be focused on. For example, when we observe a picture, our attention is easily focused on the face, the title of the article, and the first sentence of the article. Imagine that if every local information is not missed, it will inevitably consume a lot of energy, which is not conducive to human survival and evolution. Similarly, introducing a similar mechanism in a deep learning network can simplify the model and speed up the calculation. Due to the characteristics of the deep learning model's intermediate layer feature parameters that are difficult to analyze, the importance of each pixel cannot be considered when designing the attention mechanism module. In order to consider the goal of lightweight, researchers generally represent the feature information of a single channel feature map by maximum pooling or average pooling. In this way, the feature map will become through pooling, and then the importance of each channel is determined through parameter learning and back propagation update.
[0004] The existing attention mechanism uses global pooling to represent all the information of a channel. However, the pooling results and model parameters will affect the model's classification of channel importance, and changes in both will slow down the update convergence speed of the model parameters. In addition, maximum pooling and average pooling cannot replace all the information of an entire channel feature map. If two different feature maps A and B have the same results after pooling, this will cause some interference to the classification of channel importance.
[0005] As a target detection model, YOLOV7-tiny is suitable for most fields. However, due to the characteristics of fabric defects themselves, it brings many difficulties to target detection. In practical applications, the cloth defect detection effect of YOLOV7-tiny is poor. Therefore, it is necessary to improve it based on the YOLOV7-tiny network model to improve the detection accuracy. Summary of the invention
[0006] The purpose of the present invention is to solve the problems existing in the prior art and provide a fabric image defect detection method and system based on an improved YOLOV7-tiny of ECA.
[0007] In order to achieve the above-mentioned invention object, the present invention specifically adopts the following technical solutions:
[0008] In a first aspect, the present invention provides a method for detecting fabric image defects based on an improved YOLOV7-tiny using ECA, comprising the following steps:
[0009] S1. Obtain a fabric defect image dataset including 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 convolution layer CBL of the first MCB module in the backbone feature extraction network of the YOLOV7-tiny model with an ECA improved attention mechanism module to obtain an improved YOLOV7-tiny model, wherein the ECA improved attention mechanism module includes a squeezing module and an excitation module;
[0011] S3, inputting the training set and the verification set into the constructed improved YOLOV7-tiny model for training to obtain a 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 result of the fabric defect image to be detected.
[0013] Based on the above scheme, each step can be implemented in the following preferred specific manner.
[0014] As a preferred embodiment of the first aspect, in step S2, the processing flow in the ECA improved attention mechanism module is as follows:
[0015] S21. First, for the original feature map with the input dimension of B×H×W×C, the squeezing module assigns the channel importance of each channel in the original feature map to 1, so that the original feature map is compressed into a feature vector with the dimension of B×1×1×C; wherein 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 input in one training respectively;
[0016] S22, then, the excitation module obtains the one-dimensional convolution kernel size according to the number of channels of the feature vector, and uses the one-dimensional convolution kernel size in the one-dimensional convolution to obtain the weight value of each channel in the feature vector;
[0017] S23, then, the excitation module uses the sigmoid activation function to limit the weight value 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 excitation module multiplies the importance weight coefficient of the channel and the original feature map channel by channel to generate a weighted feature map.
[0019] As a preferred embodiment of the first aspect, in the ECA improved attention mechanism module of step S23, the importance weight coefficient of each channel is obtained by processing according to the following formula:
[0020] w=σ(C1D k (E 1×C ))
[0021] Among them, w is the importance weight coefficient of each channel; σ() represents the sigmoid activation function; C1D k () represents the one-dimensional convolution when the convolution kernel size is k; E 1×C Represents a feature vector of dimension B×1×1×C.
[0022] As a preferred embodiment of the first aspect above, in step S3, when the improved YOLOV7-tiny model is trained using the training set and the validation set, the parameters of the improved YOLOV7-tiny model are updated by back propagation. The back propagation process calculates the error between the predicted value outputs and the true label labels through the MPDIoU loss function, and optimizes the parameters of the improved YOLOV7-tiny model by the gradient descent method to complete the training of the improved YOLOV7-tiny model.
[0023] As a preferred embodiment of the first aspect, in step S3, the number of rounds 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 size of the improved YOLOV7-tiny model is 640×640.
[0024] In a second aspect, the present invention provides a fabric image defect detection system based on an improved YOLOV7-tiny of ECA, comprising:
[0025] A data acquisition module is used to acquire a fabric defect image dataset including fabric defect images and their corresponding category labels, and divide the fabric defect image dataset into a training set and a verification set according to a preset ratio;
[0026] A model acquisition module, used for replacing the last smooth convolution layer CBL of the first MCB module in the backbone feature extraction network of the YOLOV7-tiny model with an ECA improved attention mechanism module to obtain an improved YOLOV7-tiny model, wherein the ECA improved attention mechanism module includes a squeezing module and an excitation module;
[0027] A model optimization module, used for inputting the training set and the verification set into the constructed improved YOLOV7-tiny model for training, so as to obtain a 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 result of the fabric defect image to be detected.
[0029] In a third aspect, the present invention provides a computer program product, comprising 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 one of the schemes of the first aspect above.
[0030] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the fabric image defect detection method based on the improved YOLOV7-tiny based on ECA as described in any of the schemes of the first aspect above is implemented.
[0031] In a fifth aspect, the present invention provides a computer electronic device comprising a memory and a processor;
[0032] The memory is used to store computer programs;
[0033] The processor is used to implement the improved YOLOV7-tiny fabric image defect detection method based on ECA as described in any scheme of the first aspect above when executing the computer program.
[0034] Compared with the prior art, the present invention has the following beneficial effects:
[0035] 1. The present invention can improve the channel attention analysis capability of the ECA attention mechanism on multi-dimensional defect features during fabric defect detection, so that the improved YOLOV7-tiny model pays more attention to useful feature areas.
[0036] 2. The improved YOLOV7-tiny model of the present invention can accelerate convergence, focus on useful features, and improve recognition accuracy, thereby achieving fast and accurate detection of fabric defects.
[0037] 3. The present invention improves the existing classic ECA channel attention mechanism module, and introduces the improved ECA channel attention mechanism module into the YOLOV7-tiny model, thereby realizing fast and accurate detection of fabric defects. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 is a flow chart of the steps of the present invention;
[0039] Figure 2 It is a structural diagram of the ECA improved attention mechanism module of the present invention;
[0040] Figure 3 This is the module structure diagram of the classic ECA channel attention mechanism;
[0041] Figure 4 This is the structure diagram of the improved YOLOV7-tiny model of the present invention;
[0042] Figure 5 This is a fabric defect experiment result diagram obtained by the present invention using the improved YOLOV7-tiny model;
[0043] Figure 6 This is a picture of fabric defect experiment results obtained using the classic ECA channel attention mechanism module;
[0044] Figure 7 It is a system block diagram of the present invention. DETAILED DESCRIPTION
[0045] In order to make the above-mentioned purpose, features and advantages of the present invention more obvious and easy to understand, the specific implementation mode of the present invention is described in detail below in conjunction with the accompanying drawings. In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention can be implemented in many other ways different from those described herein, and those skilled in the art can make similar improvements without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below. The technical features in each embodiment of the present invention can be combined accordingly without conflicting with each other.
[0046] like Figure 1 As shown, in a preferred implementation of the present invention, the above-mentioned fabric image defect detection method based on ECA improved YOLOV7-tiny includes the following steps S1 to S4. The specific implementation process is described in detail below.
[0047] S1. Obtain a fabric defect image dataset including 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 an embodiment of the present invention, the fabric defect image dataset is selected from the TILDA dataset, and the TILDA dataset needs to be parsed and converted into the Yolo format readable by the YOLOV7-tiny model. After the above-mentioned fabric defect image dataset is divided into a ratio of 7:3, the training set and the validation set are preprocessed respectively. Specifically, each fabric defect image in the fabric defect image dataset is first cropped into a shape of 640×640 using the transform transformation, and then the cropped fabric defect image is converted into the form of a tensor tensor matrix, and then the DataLoader data is loaded with batch_size=16. The batch_size here refers to the data size input each time the network is trained in deep learning.
[0049] S2. Replace the last smooth convolution layer CBL of the first MCB module in the backbone feature extraction network of the YOLOV7-tiny model with an ECA improved attention mechanism module to obtain an improved YOLOV7-tiny model. The ECA improved attention mechanism module includes a squeezing module and an excitation module.
[0050] In an embodiment of the present invention, the improved YOLOV7-tiny model specifically improves the backbone feature extraction network in the YOLOV7-tiny model. Specifically, Figure 4As shown in the figure, the last smooth convolution layer CBL of the first MCB module in the backbone feature extraction network of the YOLOV7-tiny model is replaced with the ECA improved attention mechanism module to obtain the improved YOLOV7-tiny model. Figure 2 As shown in the figure, the ECA improved attention mechanism module is specifically divided into two modules: squeeze and excitation. Among them, the squeeze module is used to compress the original feature map of dimension B×H×W×C into a feature vector of dimension B×1×1×C; the excitation module first performs a one-dimensional convolution on the feature vector of dimension B×1×1×C to obtain the weight value of each channel, and then uses the weight value of the channel 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 the original feature map.
[0051] The following is an introduction to the principle of ECA channel attention mechanism. Figure 3 As shown in the figure, the classic ECA channel attention mechanism module first performs global average pooling on each channel of the original feature map, and pools the pixels into a single pixel to represent the channel information. The formula is as follows:
[0052] y i =(GAP(c i ))
[0053] y=cat channel y i (i∈[0~C-1])
[0054] Among them, GAP() represents the global average pooling operation; c i represents the i-th channel feature map; y i represents the result of global average pooling of the i-th channel; C represents the total number of channels; cat channel Indicates splicing on the channel dimension.
[0055] Then use one-dimensional convolution to learn the importance of each channel. The formula is as follows;
[0056] w=σ(C1D k (y))
[0057] Among them, w is the importance weight coefficient of each channel, σ() represents the sigmoid activation function; C1D() represents one-dimensional convolution; k represents the convolution kernel size.
[0058] Finally, the learned channel importance components are weighted to the corresponding channels of the original feature map. During back propagation, both the pooling results and the one-dimensional convolution parameters will be updated and changed. Both changes are not conducive to the convergence of the model and may fall into a local optimal solution. In addition, neither maximum 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 results after pooling operations, this will cause certain interference to the division of channel importance. Therefore, it is necessary to improve the classic ECA channel attention mechanism. Specifically, assuming that there is a feature map X (B, H, W, C), the operation of discarding the pooling result to replace the entire feature map information, in accordance with the principle of equal treatment, the present invention assigns the importance of each channel to 1, that is, (B, 1, 1, C), and then performs channel importance learning through one-dimensional convolution; finally, the learned channel importance components are weighted to the corresponding channels of the original feature map. The method of the present invention introduces the principle of controlled variables, and the factors affecting the model to distinguish the importance of the channel are only controlled on the parameter update of the one-dimensional convolution, which reduces the parameter change and speeds up the model convergence speed. And avoids the misinterpretation caused by the same pooling results of different feature maps. The purpose of the present invention is to take the ECA channel attention mechanism as an example, improve the ECA channel attention mechanism, so that it can speed up the model convergence speed and improve certain model performance compared with before.
[0059] It should be noted that in the embodiments of the present invention, the purpose is to take the ECA channel attention mechanism as an example to improve the ECA channel attention mechanism so that it can accelerate the model convergence speed and improve certain model performance compared with the previous one. 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 the input dimension of B×H×W×C, the squeezing module assigns the channel importance of each channel in the original feature map to 1, so that the original feature map is compressed into a feature vector with the dimension of B×1×1×C; wherein 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 input in one training respectively;
[0061] S22, then, the excitation module obtains a one-dimensional convolution kernel size k according to the number of channels C of the feature vector B×1×1×C, and uses the one-dimensional convolution kernel size k in the one-dimensional convolution to obtain the weight value of each channel in the feature vector with a dimension of B×1×1×C;
[0062] S23, then, the excitation module uses the sigmoid activation function to limit the weight value 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 excitation module multiplies the importance weight coefficient of the channel and the original feature map channel by channel to generate a weighted feature map.
[0064] Furthermore, in the ECA improved attention mechanism module of the embodiment of the present invention, the importance weight coefficient of each channel is obtained by processing according to the following formula:
[0065] w=σ(C1D k (E 1×C ))
[0066] Among them, w is the importance weight coefficient of each channel, σ() represents the sigmoid activation function; C1D k () represents the one-dimensional convolution when the convolution kernel size is k; E 1×C Represents a feature vector of dimension B×1×1×C.
[0067] S3. Input the training set and the verification set into the constructed improved YOLOV7-tiny model for training to obtain a trained improved YOLOV7-tiny model.
[0068] It should be noted that when the improved YOLOV7-tiny model is trained using the training set and the validation set in step S3, the parameters of the improved YOLOV7-tiny model are updated by back propagation. The back propagation process calculates the error between the predicted value outputs and the true label labels through the MPDIoU loss function, and the parameters of the improved YOLOV7-tiny model (i.e., the gradient value) are optimized by the gradient descent method to complete the training of the improved YOLOV7-tiny model. Specifically, when the improved YOLOV7-tiny model is trained, all gradients are initialized to 0, the improved YOLOV7-tiny model is trained to obtain the predicted value outputs, the loss loss is calculated by the outputs and the true label labels, and then the gradient is updated by back propagation.
[0069] In step S3 of the embodiment of the present 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 result of the fabric defect image to be detected.
[0071] In order to better demonstrate the specific implementation and technical effects of the present invention, an improved YOLOV7-tiny fabric image defect detection method based on ECA shown in steps S1 to S4 in the above preferred implementation is applied to a specific example.
[0072] Example
[0073] The specific implementation process of the fabric image defect detection method based on ECA improved YOLOV7-tiny adopted in this embodiment is as described above and will not be repeated here.
[0074] This embodiment uses evaluation indicators to evaluate the obtained defect detection results. Specifically, this embodiment uses six common evaluation indicators in the field of target detection (i.e., precision P, recall rate Recall (R), comprehensive score F1-score, average mean precision mAP, model parameters Parm. and frames per second FPS. These evaluation indicators used in this embodiment include two aspects: positioning accuracy and model complexity. This embodiment of the present invention uses precision P, recall rate Recall, comprehensive score F1-score and average mean precision mAP to evaluate the classification and positioning accuracy of the proposed method. The calculation formula is as follows.
[0075]
[0076] In the above formula:
[0077]
[0078] Where C is the number of categories of defects in the dataset samples; TP k (Ture Positive) refers to the number of true k-class samples that are correctly identified; FN k (False Negative) refers to the number of real k-class samples that are incorrectly identified. FP k (False Positive) refers to samples that are incorrectly identified as real samples; AP k YesP k -R k The area enclosed by the curve and the coordinate axis; the comprehensive indicator mAP is the mean of the average precision (AP) of all categories of detection results; P k is the precision of the k-th sample; subscript k is the ordinal number of the sample category; R k is the recall rate of the k-th class sample; similarly, the F1-score evaluation index is also calculated by combining the P and R values. In particular, the model parameters (Parm.) and FPS evaluation index are used to consider the complexity of the model proposed in this paper.
[0079] Embodiment 1:
[0080] The experimental results of Example 1 are shown in Table 1 and Figure 5 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] Among them, all represents all defects; wire represents wire defects; spot represents spot defects; hole represents hole defects; dark_thread represents dark thread 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 calculation of the AP of all images of each category when IoU is set to 0.5, and then all categories are averaged; mAP@.5:.95 represents the average mAP at different IoU thresholds (from 0.5 to 0.95, step size 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 the comparative example 1 and the embodiment are basically the same, except that: the improved YOLOV7-tiny model in step S2 of the comparative example 1 is obtained by replacing the last smooth convolution layer CBL of the first MCB module in the backbone feature extraction network of the YOLOV7-tiny model with a classic ECA attention mechanism module, and the classic ECA attention mechanism module is obtained by replacing the last smooth convolution layer CBL of the first MCB module in the backbone feature extraction network of the YOLOV7-tiny model with a classic ECA attention mechanism module, such as Figure 3 shown.
[0086] The experimental results of comparative example 1 are shown in Table 2 and Figure 6 shown.
[0087] Table 2: Evaluation index results of comparative examples
[0088]
[0089]
[0090] By comparing the above table, it is not difficult to see that after the same 300 rounds of training, the performance of the improved ECA module in each subcategory, whether mAP@.5 or mAP@.5:.95, is significantly better than the corresponding indicators of the original ECA attention module, with fast convergence speed and high 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 embodiment 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 ECA and improved YOLOV7-tiny corresponding to the improved YOLOV7-tiny fabric image defect detection method based on ECA provided in the above embodiment, such as Figure 7 As shown, it includes:
[0092] A data acquisition module is used to acquire a fabric defect image dataset including fabric defect images and their corresponding category labels, and divide the fabric defect image dataset into a training set and a verification set according to a preset ratio;
[0093] A model acquisition module, used for replacing the last smooth convolution layer CBL of the first MCB module in the backbone feature extraction network of the YOLOV7-tiny model with an ECA improved attention mechanism module to obtain an improved YOLOV7-tiny model, wherein the ECA improved attention mechanism module includes a squeezing module and an excitation module;
[0094] A model optimization module, used for inputting the training set and the verification set into the constructed improved YOLOV7-tiny model for training, so as to obtain a 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 result of the fabric defect image to be detected.
[0096] It can be understood that the improved YOLOV7-tiny fabric image defect detection method based on ECA described in S1 to S4 above can be substantially 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 embodiment, which includes a computer program / instruction. When the computer program / instruction is executed by a processor, the improved YOLOV7-tiny fabric image defect detection method based on ECA as described in the above embodiment can be implemented.
[0097] Similarly, based on the same inventive concept, another preferred embodiment of the present invention further provides a computer electronic device corresponding to the improved YOLOV7-tiny fabric image defect detection method based on ECA provided in the above embodiment, which includes a memory and a processor;
[0098] The memory is used to store computer programs;
[0099] The processor is used to implement the fabric image defect detection method based on the improved YOLOV7-tiny based on ECA in the above embodiment when executing the computer program.
[0100] In addition, the logic instructions in the above-mentioned memory can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment 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 embodiment, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the improved YOLOV7-tiny fabric image defect detection method based on ECA in the above embodiment can be implemented.
[0102] It is understandable that the above storage medium may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage. The storage medium may also be a U disk, a mobile hard disk, a magnetic disk or an optical disk, etc., which can store program codes.
[0103] It is understandable that the above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0104] It should also be noted that those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the system described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. In the various embodiments provided in this application, the division of steps or modules in the system and method is only a logical function division, and there may be other division methods in actual implementation, such as multiple modules or steps can be combined or integrated together, and a module or step can also be split.
[0105] The above-described embodiment is only a preferred solution of the present invention, but it is not intended to limit the present invention. A person skilled in the relevant technical field may make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, any technical solution obtained by equivalent replacement or equivalent transformation falls within the protection scope of the present invention.
Claims
1. A fabric image defect detection method based on ECA improved YOLOV7-tiny, characterized in that: The following steps are involved: S1. Obtain a fabric defect image dataset including 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 convolution layer CBL of the first MCB module in the backbone feature extraction network of the YOLOV7-tiny model with an ECA improved attention mechanism module to obtain an improved YOLOV7-tiny model, wherein the ECA improved attention mechanism module includes a squeezing module and an excitation module; S3, inputting the training set and the verification set into the constructed improved YOLOV7-tiny model for training to obtain a 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.
2. The fabric image defect detection method based on the improved YOLOV7-tiny of ECA as claimed in claim 1, characterized in that: In step S2, the processing flow in the ECA improved attention mechanism module is as follows: S21. First, for the original feature map with the input dimension of B×H×W×C, the squeezing module assigns the channel importance of each channel in the original feature map to 1, so that the original feature map is compressed into a feature vector with the dimension of B×1×1×C; wherein 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 input in one training respectively; S22, then, the excitation module obtains the one-dimensional convolution kernel size according to the number of channels of the feature vector, and uses the one-dimensional convolution kernel size in the one-dimensional convolution to obtain the weight value of each channel in the feature vector; S23, then, the excitation module uses the sigmoid activation function to limit the weight value 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 excitation module multiplies the importance weight coefficient of the channel and the original feature map channel by channel to generate a weighted feature map.
3. The fabric image defect detection method based on the improved YOLOV7-tiny of ECA as claimed in claim 1, characterized in that: In the ECA improved attention mechanism module of step S23, the importance weight coefficient of each channel is obtained according to the following formula: w =σ(C1D k (AND 1×C )) Among them, w is the importance weight coefficient of each channel; σ() represents the sigmoid activation function; C1D k () represents the one-dimensional convolution when the convolution kernel size is k; E 1×C Represents a feature vector of dimension B×1×1×C.
4. The fabric image defect detection method based on the improved YOLOV7-tiny of ECA as claimed in claim 1, characterized in that: In step S3, when the improved YOLOV7-tiny model is trained using the training set and the validation set, the parameters of the improved YOLOV7-tiny model are updated by back propagation. The back propagation process calculates the error between the predicted value outputs and the true label labels through the MPDIoU loss function, and optimizes the parameters of the improved YOLOV7-tiny model by the gradient descent method to complete the training of the improved YOLOV7-tiny model.
5. The fabric image defect detection method based on the improved YOLOV7-tiny of ECA as claimed in claim 1, characterized in that: In step S3, the number of rounds 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 size of the improved YOLOV7-tiny model is 640×640.
6. A fabric image defect detection system based on ECA-modified YOLOV7-tiny, characterized in that: include: A data acquisition module is used to acquire a fabric defect image dataset including fabric defect images and their corresponding category labels, and divide the fabric defect image dataset into a training set and a verification set according to a preset ratio; A model acquisition module, used for replacing the last smooth convolution layer CBL of the first MCB module in the backbone feature extraction network of the YOLOV7-tiny model with an ECA improved attention mechanism module to obtain an improved YOLOV7-tiny model, wherein the ECA improved attention mechanism module includes a squeezing module and an excitation module; A model optimization module, used for inputting the training set and the verification set into the constructed improved YOLOV7-tiny model for training, so as to obtain a 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 result of the fabric defect image to be detected.
7. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, the fabric image defect detection method based on the improved YOLOV7-tiny of ECA as described in any one of claims 1 to 5 can be implemented.
8. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by the processor, the fabric image defect detection method based on the improved YOLOV7-tiny of ECA as described in any one of claims 1 to 5 is implemented.
9. A computer electronic device, characterized in that: including memory and processor; The memory is used to store computer programs; The processor is used to implement the fabric image defect detection method based on the improved YOLOV7-tiny based on ECA as described in any one of claims 1 to 5 when executing the computer program.
Citation Information
Patent Citations
Motor imagery electroencephalogram signal classification method based on channel attention and multi-scale time domain convolution
CN114266276A
YOLOv5 fabric defect detection method for improving CA attention mechanism
CN116385425A
SAR image aircraft target detection method based on improved YOLOv5
CN116630798A
Fabric defect detection method and device, terminal equipment and medium
CN116993698A
Fabric defect detection method based on improved YOLOv7-Tiny network model
CN117173111A
Cited By
Training method and device of prediction model, prediction method and device, medium and electronic equipment
CN120705587A