Glove defect detection method based on improved YOLOv5
By improving the YOLOv5 model, adding a small target detection layer, introducing the CCA attention mechanism, and optimizing the loss function, the problems of low efficiency and insufficient accuracy in defect detection in nitrile glove production were solved, achieving efficient and accurate defect detection.
Patent Information
- Application Number
- CN202311049368.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-21
- Publication Date
- 2025-12-26
- Estimated Expiration
- 2043-08-21
AI Technical Summary
Existing technologies for defect detection in nitrile glove production suffer from problems such as cumbersome processing, high requirements for hardware and environment, inconvenience in deployment, and false positives and false negatives. Furthermore, manual inspection is inefficient and has a high false positive rate, making it difficult to meet the needs of large-scale production.
An improved YOLOv5 model was adopted, which was optimized by adding a small target detection layer, introducing a CCA attention mechanism module, and using EIOU and Alpha-IoU loss functions to improve the accuracy and efficiency of glove defect detection.
Under the same equipment conditions, the accuracy of glove defect detection has been significantly improved, especially the detection performance of small targets, achieving higher detection accuracy and faster detection rate, meeting the needs of real-time detection.
Smart Images

Figure CN117078629B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of defect detection, and particularly relates to a glove defect detection method based on an improved YOLOv5. BACKGROUND
[0002] Under the accelerating digitalization process of global manufacturing, the demand for nitrile gloves is increasing year by year. With the continuous expansion of the production scale of nitrile gloves, surface defects often occur in the production process, and defect detection has become a major difficulty in the production process. This puts higher requirements on the accuracy and speed of nitrile glove quality detection. Common surface defects of nitrile gloves include tearing, scratches, etc.
[0003] Currently, the defect detection of nitrile gloves is mainly carried out by manual methods, but manual detection has the problems of low efficiency, high false detection rate and high omission rate, and it is difficult to meet the demand of the expanding production scale of nitrile gloves. In order to ensure the quality of nitrile glove production while reducing labor costs, the transformation of glove defect detection mode from manual detection to automatic detection is urgently needed.
[0004] With the wide application of deep learning, the accuracy and efficiency of object detection have been greatly improved, and future defect detection of nitrile medical gloves will mainly focus on the detection of defect targets. Based on a large number of literature, the target detection algorithm can be roughly divided into two categories: two-stage target detection algorithm and single-stage target detection algorithm. The classic algorithms of two-stage target detection include R-CNN, SPP-Net, Fast R-CNN, Faster R-CNN, etc. In view of the low efficiency of the two-stage target detection algorithm, YOLO is proposed, which eliminates the candidate frame extraction branch in the algorithm, and directly realizes feature extraction, candidate frame classification and regression in the same branch-free deep convolutional network, so that the network structure becomes simple, and the target detection algorithm based on deep learning can meet the demand of real-time detection task under the current computing capacity.
[0005] Since the YOLO algorithm was proposed, various network structures have been continuously integrated to improve detection performance, but there are few studies on defect detection of nitrile medical gloves. Most of them still stay in the physical detection and simple convolutional neural network implemented target detection, and there are problems such as complicated processing process, high requirements for hardware and environment, inconvenience of deployment, false detection and omission. SUMMARY
[0006] To solve the above technical problems, the application provides a glove defect detection method based on an improved YOLOv5 to solve the problems of complicated processing process, high requirements for hardware and environment, inconvenience of deployment, false detection and omission in the prior art.
[0007] To achieve the above object, the glove defect detection method based on improved YOLOv5 provided by the application comprises the following steps:
[0008] Collecting glove pictures and constructing a glove dataset;
[0009] Constructing a YOLOv5 model and optimizing the YOLOv5 model to obtain an improved YOLOv5 glove detection model;
[0010] Training the improved YOLOv5 glove detection model based on the glove dataset to obtain a glove defect detection model;
[0011] Detecting defects of gloves through the glove defect detection model.
[0012] Preferably, the method for optimizing the YOLOv5 model comprises improving the small target detection layer of the YOLOv5 model, adding a CCA attention mechanism module, and improving the loss function of the YOLOv5 model.
[0013] Preferably, the method for improving the small target detection layer of the YOLOv5 model comprises performing up-sampling processing on the feature map after the 17th layer of the small target detection layer of the YOLOv5 model, combining the feature map with a size of 160X160 obtained at the 20th layer with the feature map of the 2nd layer in the backbone network through concat at the 20th layer, and adding a segmentation detection module at the 31st layer.
[0014] Preferably, the processing method of the CCA attention mechanism module comprises performing global average pooling processing on a feature image to obtain two one-dimensional features, splicing the two one-dimensional features in the W dimension, then passing through a convolution and a nonlinear activation function, splitting the features in the channel dimension to obtain two feature maps with specific spatial direction long-range dependence, and performing feature fusion on the two feature maps with specific spatial direction long-range dependence and the original feature to obtain a feature map with attention weight in the width and height directions.
[0015] Preferably, the method for improving the loss function of the YOLOv5 model comprises adding an EIOU loss function to the loss function of the YOLOv5 model, and then improving the loss function of the YOLOv5 model through Alpha-IoU.
[0016] Preferably, the EIOU loss function comprises an overlap loss, a distance loss and a width-height loss.
[0017] Preferably, the method for improving the loss function of the YOLOv5 model through Alpha-IoU comprises inducing the ordinary IOU loss in the YOLOv5 model into an alpha-IoU loss through Box-Cox transformation.
[0018] Preferably, the defect detection includes horizontal tear detection, vertical tear detection and scratch detection.
[0019] Compared with the prior art, the present application has the following advantages and technical effects:
[0020] The present application provides a glove defect detection method based on improved YOLOv5. To enhance the detection performance of small targets such as glove scratches, the YOLOv5 model is improved. Under the condition that the experimental equipment remains unchanged, compared with the original YOLOv5, the detection accuracy of the three defect detection models of horizontal tear detection, vertical tear detection and scratch detection is greatly improved. BRIEF DESCRIPTION OF DRAWINGS
[0021] The accompanying drawings, which form a part of this application, are included to provide a further understanding of the application and are incorporated in and constitute a part of this application. The embodiments of this application illustrated in the drawings and their description are presented to explain the present application and are not intended to limit the present application. In the drawings:
[0022] Figure 1 A flow chart of the glove defect detection method of the embodiment of the present application;
[0023] Figure 2 A network structure diagram of the improved YOLOv5 of the embodiment of the present application;
[0024] Figure 3 A CCA attention mechanism architecture diagram of the embodiment of the present application;
[0025] Figure 4 A global average pooling architecture diagram of the embodiment of the present application. DETAILED DESCRIPTION
[0026] It should be noted that the embodiments and features in the embodiments of the present application can be combined with each other without conflict. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0027] It should be noted that the steps shown in the flow chart of the accompanying drawings can be executed in a computer system such as a group of computer executable instructions, and although the logical order is shown in the flow chart, in some cases, the steps shown or described herein can be executed in an order different from that shown herein.
[0028] As Figure 1 shown, the present application provides a glove defect detection method based on improved YOLOv5, which includes the following steps:
[0029] Collecting glove pictures and constructing a glove dataset;
[0030] The YOLOv5 model is constructed, and the YOLOv5 model is optimized to obtain an improved YOLOv5 glove detection model;
[0031] The improved YOLOv5 glove detection model is trained based on the glove dataset to obtain a glove defect detection model;
[0032] The glove defect detection model is used for defect detection of the glove.
[0033] Further optimization scheme, the method for optimizing the YOLOv5 model is to increase a small target feature detection layer, add the proposed CCA attention mechanism module, replace CIoU with EIoU loss function, improve the detection of tearing defects, and use Alpha-IoU loss function to improve the detection accuracy of scratch defects. The improved YOLOv5 overall network structure is as shown in Figure 2 .
[0034] The improvement method of the small target detection layer is as follows:
[0035] The main reason for the poor small target detection effect is the small target size problem. The original YOLOv5 model has only three target detection layers of different scales. Taking the input 608x608 of the network as an example, the sizes of the three feature maps are 19x19, 38x38 and 76x76. The largest 76x76 is responsible for detecting small targets, and the corresponding feature map on 608x608 has a receptive field of 608 / 76=8x8.
[0036] That is, if the width or height of the target in the original image is less than 8 pixels, the network is difficult to learn the feature information of the target. In addition, many images have a large resolution, and if simple downsampling is performed, the downsampling multiple is too large, which is easy to lose data information. However, if the multiple is too small, the network forward propagation needs to save a large number of feature maps in the memory, which greatly consumes GPU resources, and is easy to cause memory explosion, and cannot be normally trained and inferred. The added small target feature extraction layer continues to perform upsampling and other processing on the feature map after the 17th layer, so that the feature map continues to expand. At the same time, at the 20th layer, the feature map with a size of 160x160 obtained is concatenated with the feature map of the 2nd layer in the backbone network to obtain a larger feature map for small target detection. At the 31st layer, a segmentation detection module is added, a total of four layers are used for detection, and the accuracy of scratch small defect detection is improved.
[0037] The CA attention mechanism can consider the attention of the channel dimension and the spatial dimension at the same time, in order to make the model pay more attention to useful channel information. The architecture of the proposed CCA attention mechanism is as shown in Figure 3As shown, by performing one-dimensional adaptive average pooling in the X-axis and Y-axis directions on the input features respectively, independent directional perception features retaining X-axis and Y-axis information are obtained, wherein one spatial direction captures long-range dependencies and the other spatial direction retains precise location information. The proposed CCA attention mechanism can focus more on the channel relationship of the network on the basis of focusing on the spatial relationship of the network.
[0038] As Figure 4 shown in formula 1, the feature map is changed from [C, H, W] to [C, 1, 1] by the global average pooling method, and then two 1x1x1 convolutions are used for information processing, finally obtaining a C-dimensional vector. We regard the input mapping feature U as the combination of channels The global spatial information is embedded into the vector z, which encodes the channel-dependent dependencies.
[0039]
[0040] The sigmoid function is used to pass Normalization is performed on to bring it to the [0, 1] interval, and the corresponding mask is obtained. Finally, through channel-wise multiplication, the feature map after information calibration is obtained, which emphasizes useful features and suppresses useless features. The obtained vector is used to recalibrate or excite U to
[0041]
[0042] indicates the rescaled channel importance. With the learning of the network, these activations will be adaptively adjusted, ignoring less important channels and emphasizing important channels, improving the expressiveness of the network to focus on the key positions of the picture, thereby improving the network performance.
[0043] After learning the channel relationship of the network, Coordinate Attention encodes the channel relationship and long-range dependencies through precise location information, and the specific operation is divided into two steps of Coordinate information embedding and Coordinate Attention generation.
[0044] The two one-dimensional features obtained are spliced in the W dimension, then passed through a convolution and a nonlinear activation function, and then the features are split in the channel dimension to obtain two feature maps with specific spatial direction long-range dependencies through convolution and Sigmoid activation function. These two feature maps can be applied to the input feature map complementarily to enhance the target of interest. Through feature fusion with the original feature, a feature map with attention weight in the width and height direction is finally obtained.
[0045] The improved method of the loss function is as follows:
[0046] After a lot of research, we believe that the introduction of the EIOU loss function in this experiment has a good recognition and detection effect on the vertical angle and horizontal angle of the tear defect. Its definition is as follows:
[0047] L EIOU =L IOU +L dis +L asp
[0048]
[0049] This function mainly includes overlap loss L IOU , distance loss L dis and width-height loss L asp three parts, where c represents the diagonal distance of the smallest rectangle that can wrap two boxes, (b,b gt ) is the distance between the centers of the two boxes, c w and c h represent the width and height of the smallest rectangle that can wrap two boxes. (w,w gt ) and (h,h gt ) represent the difference between the width and height of the two boxes. The EIOU loss not only considers the distance factor of the two rectangular boxes, but also minimizes the difference between the width and height of the two boxes, so it can improve the detection accuracy of small targets to a certain extent and improve the convergence stability of the model.
[0050] In the process of experimental research, the author found that although the use of EIOU loss function can effectively improve the detection accuracy of tears, it cannot accurately identify small defects such as scratches. Therefore, according to the characteristics of small and difficult-to-identify scratches and more noise interference in the factory environment, we use the Alpha-IoU proposed by Jiabo He in 2021 to improve the loss function of the YOLOv5 model.
[0051] Different from other variants, the alpha-IoU is a new IoU loss function proposed by introducing a power transformation to the existing IoU loss, with a Power IoU term and an additional Power regularization term and a single Power parameter alpha, which can significantly outperform the existing IoU-based loss.
[0052] The vanilla IoU loss is defined as
[0053] L IoU = 1 - IoU (4)
[0054] The general form of alpha-IoU is defined as
[0055] L α-IoU = 1 - IoU α (5)
[0056] The vanilla IoU loss can be induced to alpha-IoU loss by applying Box-Cox transformation
[0057]
[0058] L α -IoU increases the loss and gradient of high IoU targets when alpha > 1, which in turn improves the bbox regression accuracy, where the choice of alpha is crucial to the alpha-IoU loss, and in most cases, taking alpha = 3 works best. The author found that when alpha = 2, it accelerates the learning of all positive IoU targets at AP 50 50 in the study of medical nitrile glove defect detection,
[0059] The calculation formula is as follows:
[0060]
[0061] The vanilla IoU loss is defined as Since the penalty condition has different effects on the properties of vanilla alpha-IoU, by analyzing the vanilla alpha-IoU (formula 7), it can be concluded that the power transformation of L α-IoU -IoU retains the key properties of L-IoU, including non-negativity, indistinguishable identity, symmetry, and triangular inequality, in addition to which L α-IoU Also includes the following five major features. Order Preservingness guarantees that L-IoU and L α-IoUare monotonically decreasing functions. Relative Loss Reweighting makes the weighting factor monotonically increase with the increase of IoU (from 1 to a) when a > 1, and can help the model focus more on the High IoU targets to improve the performance of positioning and detection. Relative Gradient Reweighting makes the above reweighting factor monotonically increase with the increase of IoU when a > 1, which allows the model to learn the target with adaptive speed (i.e. different gradients) according to the IoU of the target.
[0062] In order to verify the improvement of the model by using the loss function, the loss function used is compared with other commonly used loss functions. Through comparison, the larger the mAP value, the higher the detection accuracy, and the better the network performance. On the same data set, the improved model after 100 iterations has higher recall rate and the highest mAP0.5 compared with the model using mainstream attention module, and improves by 2.9% compared with YOLOv5s network.
[0063] The comparison experiments of each improved module are as follows:
[0064] In order to strengthen the extraction ability of YOLOv5s model for spatial information features, the feature extraction network of YOLOv5s is redesigned in this paper. Module A is set to increase small target feature detection, module B is set to introduce CCA attention mechanism, module C is set to use Alpha-IoU loss function to replace CIOU to improve scratch detection accuracy, and module D is set to use EIOU to replace CIOU to improve tear detection accuracy. Table 2 is the data generated under the condition of using vertical angle shooting data set and equal training parameters 100epoch.
[0065] Table 1
[0066]
[0067] As shown in Table 1 above, after adding the small target detection layer, mAP0.5 is improved by 3.5 percentage points, after adding the CA attention mechanism, mAP0.5 is improved by 1.6 percentage points, after using the Alpha-IoU loss function, mAP0.5 is improved by 2.5 percentage points, and after using the EIoU loss function, mAP0.5 is improved by 1.1 percentage points. By adding the CA attention mechanism, increasing the small target detection layer and using the Alpha-IoU and EIoU loss functions, the detection effect of the network on small targets can be effectively improved. Through data analysis, it can be concluded that the improvement of these modules has a gain effect on the feature extraction ability, further verifying that the improved model is more suitable for the detection of defects of nitrile medical glove model.
[0068] The algorithm can achieve a detection accuracy of 94.3% mAP0.5 on the nitrile medical glove target detection task. Compared with the YOLOv5s algorithm before improvement, the mAP0.5 of the algorithm of the embodiment has a 2.8 percentage point improvement, the P has a 1.5 percentage point improvement, and the R has a 3.7 percentage point improvement. Compared with the YOLOv7 algorithm which is currently more stable and has a higher use frequency in the YOLO detection algorithm, although the algorithm is lacking in recall rate, the algorithm has a higher precision P value and a higher mAP.
[0069] In order to further strengthen the training, obtain the best weight sent into the detection network, realize higher precision and faster monitoring rate of the monitoring effect, set the learning rate lr of the initial training to 0.005, set the picture batch quantity to 32, and train each data set for 10000 epochs. The training result is shown in Table 2.
[0070] Table 2
[0071]
[0072] In order to better verify the detection performance of the algorithm for small defect targets, the original YOLOv5s network and the improved YOLOv5 network are used to select part of the image data from the test set for testing. Through comparison of three types of detection results of horizontal tear detection, vertical tear detection and vertical scratch detection, it can be concluded that the algorithm is obviously higher than the original model in detection accuracy. In the test, YOLOv5 has false detection for horizontal tear detection and cannot accurately detect the target, while the improved algorithm of the embodiment can accurately detect the tear and scratch targets. The main reason is that the model increases the detection layer of small targets, so as to have stronger resolution, the coordinate attention mechanism brings a larger receptive field, increases the perception ability of the model to defects, and the EIOU and Alpha-IoU loss functions used for different types of defects can improve the positioning accuracy during prediction, and can more accurately detect small targets.
[0073] Finally, the trained glove defect detection model is used for glove defect detection.
[0074] As can be seen from the above, the significant advantages of the present application compared with the prior art are as follows:
[0075] The application provides a glove defect detection method for improving YOLOv5. In order to enhance the detection performance of small targets such as scratches, a small target detection layer is added to improve the detection effect of the detection network on glove scratches. In order to improve the extraction of defect features and obtain a larger receptive field, the CCA attention mechanism is introduced to further improve the feature extraction capability of the network on the tear and scratch targets. In order to improve the positioning accuracy and reduce the target missing detection rate, the EIoU loss function is used to improve the regression performance of the network. Under the condition that the experimental equipment is unchanged, compared with the original YOLOv5s, the mAP of the three defect detection models of horizontal tear detection, vertical tear detection and scratch detection can reach 99.3%, 99.8% and 99.6% respectively, which is increased by 4.2%, 5.3% and 12.4% respectively. On the basis of greatly improving the map, the frame rate can reach 113 frames / s in the experimental environment, which can meet the real-time detection requirements of the glove defects.
[0076] The above is only a preferred specific embodiment of the application, but the protection scope of the application is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical range disclosed in the application, which should be covered in the protection scope of the application. Therefore, the protection scope of the application should be subject to the protection scope of the claims.
Claims
1. A glove defect detection method based on improved YOLOv5, characterized in that, The method comprises the following steps: Collecting glove pictures and constructing a glove dataset; Constructing a YOLOv5 model and optimizing the YOLOv5 model to obtain an improved YOLOv5 glove detection model; The method for optimizing the YOLOv5 model comprises: improving the small target detection layer of the YOLOv5 model; adding a CCA attention mechanism module; and improving the loss function of the YOLOv5 model; The method for improving the small target detection layer of the YOLOv5 model comprises: performing up-sampling processing on the feature map after the 17th layer of the small target detection layer of the YOLOv5 model; at the 20th layer, combining the feature map with a size of 160X160 obtained with the feature map of the 2nd layer in the backbone network through concat; and at the 31st layer, adding a segmentation detection module; The processing method of the CCA attention mechanism module comprises: performing global average pooling processing on a feature image to obtain two one-dimensional features, splicing the two one-dimensional features in the W dimension, and then performing a convolution and a nonlinear activation function, splitting the features in the channel dimension to obtain two feature maps with specific spatial direction long-range dependence, and performing feature fusion on the two feature maps with specific spatial direction long-range dependence and the original feature to obtain a feature map with attention weight in the width and height directions; The method for improving the loss function of the YOLOv5 model comprises: adding an EIOU loss function to the loss function of the YOLOv5 model, and then improving the loss function of the YOLOv5 model through Alpha-IoU; Training the improved YOLOv5 glove detection model based on the glove dataset to obtain a glove defect detection model; Detecting defects of the glove through the glove defect detection model.
2. The glove defect detection method based on the improved YOLOv5 according to claim 1, wherein the EIOU loss function comprises an overlap loss, a distance loss and a width-height loss.
3. The glove defect detection method based on the improved YOLOv5 according to claim 1, wherein the method for improving the loss function of the YOLOv5 model through Alpha-IoU comprises: inducing the ordinary IOU loss in the YOLOv5 model into an alpha-IoU loss through Box-Cox transformation.
4. The glove defect detection method based on the improved YOLOv5 according to claim 1, wherein the defect detection comprises horizontal tear detection, vertical tear detection and scratch detection.