An industrial packaging bottle cap production defect visual detection method based on lightweight improved YOLOv5s
By improving the YOLOv5s network with lightweight technology, a bottle cap defect recognition model was constructed, which solved the problem of detecting various defects on the liquor bottle cap production line, achieving efficient and low-cost bottle cap defect recognition and improving detection accuracy and efficiency.
Patent Information
- Application Number
- CN202310203750.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-03
- Publication Date
- 2026-01-16
- Estimated Expiration
- 2043-03-03
AI Technical Summary
Existing technologies lack mature machine vision methods for defect detection on liquor bottle cap production lines, resulting in high detection difficulty and increased costs, especially for identifying multiple defects and small target defects.
A lightweight, improved YOLOv5s network was adopted. A new backbone network and neck network were constructed, and an efficient channel attention mechanism (ECA) was combined to build a bottle cap defect recognition model. A dataset was built using annotation tools and trained to achieve the recognition of bottle cap defects.
It maintains high detection accuracy while reducing model parameters, lowers equipment deployment costs, effectively identifies single and multiple bottle cap defects, and improves detection efficiency and accuracy.
Smart Images

Figure CN116485715B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of target detection, in particular to an industrial packaging bottle cap production defect visual detection method based on a lightened improved YOLOv5s. BACKGROUND
[0002] At present, visual technology develops rapidly, and the quality detection of the production line by using visual technology is a relatively mature scheme and the future development trend. In the face of the packaging production line of liquor bottle caps, visual technology will save production cost and reduce the working pressure of workers compared with manual quality detection. As a branch of visual technology that develops rapidly in recent years, deep learning has higher and higher detection model precision, and the model parameters are also larger and larger, so better equipment is needed to deploy the algorithm, which will increase the production cost.
[0003] The main process of the packaging of the liquor bottle cap is to first center the bottle body with the machine hole, then lower the punching machine, and generate the bottle cap thread and twist point under high-speed rotation and extrusion. However, defects will inevitably occur in the factory production line, so quality detection is needed. Six kinds of production defects may occur in the production process, such as damage, bad edge, breakpoint, date error, deformation, and spinning; the main causes of the above defects are: 1. The machine is not centered or the liquor bottle is stuck in the middle position of the machine flow during entry, so that the bottle cap is damaged due to collision during descent, resulting in deformation defects; 2. The machine is slightly tilted or has an error during high-speed rotation, resulting in bottle cap damage defects and connection point breakpoint defects; 3. The force applied to the bottle cap during machine rotation may not be sufficient, resulting in a bad edge defect of the bottle cap edge that cannot be normally packaged; and the pressure is too small, so that the bottle cap cannot be extruded with threads at the bottle opening thread, resulting in looseness and spinning defects; 4. The last one is that a certain probability problem may occur during date printing, which is defined as a date error defect. In addition, in the actual production situation of the assembly line, in addition to single defects, two or more defects may occur during the production process, and some defects belong to small target defect detection, which will inevitably increase the recognition difficulty of the detection task.
[0004] Based on the above analysis, in view of the problem that there is still a lack of a mature machine vision method to realize defect detection for the liquor bottle cap on the existing production line, it is necessary to design a liquor bottle cap defect detection method to solve the problem of bottle cap defect detection on the production line, and to realize the lowest investment of production cost by deploying on low-cost equipment. SUMMARY
[0005] The purpose of the present application is to provide an industrial packaging bottle cap production defect visual detection method based on a lightened improved YOLOv5s to solve the above-mentioned problem of bottle cap defect detection on the production line.
[0006] To this end, the technical scheme of the present application is as follows:
[0007] An industrial packaging bottle cap production defect visual detection method based on a lightweight improved YOLOv5s, the steps are as follows:
[0008] S1, in the form of collecting bottle cap side view images, sequentially image acquisition is performed on a plurality of bottle caps to obtain a sufficient number of bottle cap side view images for data set construction;
[0009] S2, using the labeling tool labelimg, the bottle cap defect part in each image obtained by step S1 is sequentially circled and annotated to construct a bottle cap defect data set; wherein the bottle cap defect data set should include bottle cap images with the above six defects;
[0010] S3, based on the lightweight YOLOv5s network, a bottle cap defect recognition model is constructed, the steps are as follows:
[0011] S301, a new backbone network is constructed to replace the backbone network in the original YOLOv5s network; the new backbone network is composed of a CBRM module, a first Shuffle2 module, a first Shuffle1 module, a second Shuffle2 module, a second Shuffle1 module, a third Shuffle2 module and a third Shuffle1 module connected in sequence, and the output ends of the first Shuffle1 module, the second Shuffle1 module and the third Shuffle1 module are also connected with the input ends of the second concat layer, the first concat layer and the first Conv convolutional layer in the FPN structure of the neck network respectively; the CBRM module is composed of a conv convolutional layer, a BN layer, a ReLU activation function and a max pooling layer connected in sequence; the convolution kernel size of the conv convolutional layer and the max pooling layer is 3*3, the sliding step of the convolution kernel is 2, and the padding number is 1; the first Shuffle2 module, the second Shuffle2 module and the third Shuffle2 module have the same network structure, and all of them use the down sampling module of ShuffleNet V2; the first Shuffle1 module, the second Shuffle1 module and the third Shuffle1 module have the same network structure, and all of them use the basic module of ShuffleNetV2;
[0012] S302, a first ECA module is added after the second C3-2 layer in the FPN structure, and the connection between the first ECA module and the first Conv convolutional layer in the PAN structure is deleted, so that the output end of the second C3-2 layer is connected with the input end of the first ECA module, and the output end of the first ECA module is connected with the input end of the first Conv convolutional layer in the PAN structure and the input end of the Detect module in the head network for processing the 80x80x128 feature layer; a second ECA module is added after the first C3-2 layer in the PAN structure, and the connection between the second ECA module and the second Conv convolutional layer in the PAN structure is deleted, so that the output end of the first C3-2 layer is connected with the input end of the second ECA module, and the output end of the second ECA module is connected with the input end of the second Conv convolutional layer in the PAN structure and the input end of the Detect module in the head network for processing the 40x40x256 feature layer; a third ECA module is added after the second C3-2 layer in the PAN structure, so that the output end of the second C3-2 layer is connected with the input end of the third ECA module, and the output end of the third ECA module is connected with the input end of the Detect module in the head network for processing the 20x20x512 feature layer;
[0013] S4, the bottle cap defect data set constructed by step S2 is randomly divided into a training set and a validation set; the training set is input into the bottle cap defect recognition model, and the images with defects are taken as input and the categories of defects are taken as output, so as to train the bottle cap defect recognition model; the validation set is used for verification in the training process;
[0014] S5, the trained bottle cap defect recognition model is used for defect detection of the bottle cap.
[0015] Further, in step S2, the bottle cap defect part in the image is annotated in the form of a circle, that is, a minimum bounding rectangle of the defect is drawn in the image, and the defect type is annotated on the rectangle.
[0016] Further, in step S2, the bottle cap defect data set is composed of a plurality of bottle cap images with a single defect and a plurality of bottle cap images with multiple defects, and the proportions of the two in the bottle cap defect data set are the same.
[0017] Further, in step S4, in the training process of the model, the initial learning rate is set to 0.01, the cosine annealing learning rate adjustment strategy is adopted, and the Adam gradient optimizer is used to find the optimum.
[0018] Compared with the prior art, the industrial packaging bottle cap production defect visual detection method based on the lightweight improved YOLOv5s effectively solves the detection problem of various defect types existing in the bottle cap production process, in a visual image detection manner, a bottle cap defect recognition model is constructed in combination with the lightweight YOLOv5s network, and the recognition difficulty of the bottle cap defect is improved; according to experimental verification, the method maintains a high detection accuracy under the condition of effectively reducing the model parameters, provides a more lightweight algorithm for liquor bottle cap production quality inspection, and reduces the production cost of equipment deployment. BRIEF DESCRIPTION OF DRAWINGS
[0019] Figure 1 The flowchart of the industrial packaging bottle cap production defect visual detection method based on the lightweight improved YOLOv5s of the application;
[0020] Figure 2 The structure diagram of the bottle cap image acquisition system in the industrial packaging bottle cap production defect visual detection method based on the lightweight improved YOLOv5s of the application;
[0021] Figure 3 The physical diagram of the bottle cap image acquisition system in the industrial packaging bottle cap production defect visual detection method based on the lightweight improved YOLOv5s of the application;
[0022] Figure 4 The bottle cap defect labeling diagram in the bottle cap defect data set in the industrial packaging bottle cap production defect visual detection method based on the lightweight improved YOLOv5s of the application;
[0023] Figure 5 The model structure diagram of the bottle cap defect detection method based on YOLOv5s in the industrial packaging bottle cap production defect visual detection method based on the lightweight improved YOLOv5s of the application;
[0024] Figure 6 The model structure diagram of the bottle cap defect detection method based on the lightweight improved YOLOv5s of the application;
[0025] Figure 7 The detection effect diagram of a single bottle cap defect obtained by using the industrial packaging bottle cap production defect visual detection method based on the lightweight improved YOLOv5s of the application;
[0026] Figure 8 The detection effect diagram of multiple bottle cap defects obtained by using the industrial packaging bottle cap production defect visual detection method based on the lightweight improved YOLOv5s of the application. DETAILED DESCRIPTION
[0027] The application will be further described below in conjunction with the drawings and specific embodiments, but the following embodiments are by no means limiting to the application.
[0028] Referring to Figure 1 The industrial packaging bottle cap production defect visual detection method based on the lightweight improved YOLOv5s includes the following specific implementation steps:
[0029] S1, collecting bottle cap images:
[0030] Referring to Figure 2 and Figure 3 In the manner of collecting bottle cap side view images, a plurality of bottle caps are sequentially imaged to obtain a sufficient number of bottle cap side view images for data set construction; wherein at least four high-definition images are collected along the circumferential direction of each bottle cap to obtain images that can display the complete image of the bottle cap.
[0031] In the specific implementation process, the side view image of the bottle cap is obtained by using a bottle cap image collection system; the bottle cap image collection system includes an image collection table, a ring-shaped light source, and a camera; specifically, the image collection table adopts an iron stand, which is composed of a horizontal bottom plate and a fixed rod vertically fixed on one side of the horizontal bottom plate; the ring-shaped light source is a ring-shaped LED light source with an inner diameter greater than the outer diameter of the wine bottle cap; the ring-shaped light source is fixed on the fixed rod of the image collection table by a light source fixing device in a horizontal manner and is centrally located above the horizontal bottom plate, and the setting height of the ring-shaped light source satisfies that it maintains an appropriate distance from the top of the wine bottle cap to avoid contact with the bottle cap surface or affect the image imaging effect due to the reflection of the bottle cap; the camera adopts a monocular camera, which is fixed on the adjacent side of the horizontal bottom plate by a camera bracket in a manner that the camera lens horizontally faces the wine bottle cap. When imaging, the wine bottle is placed vertically at the center of the horizontal bottom plate, so that the wine bottle is placed at the center position of the ring-shaped light source; the illumination of the ring-shaped light source illuminates the bottle cap part to ensure that the defect part of the bottle cap can be clearly captured.
[0032] S2, constructing a bottle cap defect data set;
[0033] Specifically, the specific implementation steps of this step S2 are as follows:
[0034] The images collected by step S1 are transmitted to a computer, and a labeling tool labelimg is used to sequentially label the defects of the bottle caps in the images to construct a bottle cap defect data set; wherein,
[0035] 1) According to the six main production defects in the production process, the cap defects involved in this step are defined to include: deformation, damage, data error, break point, break point and spinning;
[0036] 2) The labeling method for cap defects in the cap image is to draw the minimum bounding rectangle box of the defect in the image, and label the defect type of the rectangle box;
[0037] 3) The cap defect dataset should include cap images with the above six defects;
[0038] As a preferred technical solution of the embodiment, the cap defect dataset is composed of cap images with a single defect and cap images with multiple defects, and the proportion of the two in the cap defect dataset is the same; more preferably, the occurrence proportion of different types of defects in the cap image with a single defect in the cap defect dataset is the same, and the occurrence proportion of different types of defects in the cap image with multiple defects in the cap defect dataset is the same;
[0039] S3, based on the lightweight YOLOv5s network, a cap defect recognition model is constructed:
[0040] Referring to Figure 5 and Figure 6 , the cap defect recognition model of the application is based on the YOLOv5s network, and is improved by replacing the backbone network, adding an attention mechanism module in the neck network, and modifying the connection relationship between the head network and the neck network based on the strong information extraction capability, excellent object detection and recognition precision, and image analysis processing principle.
[0041] The cap defect recognition model is based on the improved method of the original YOLOv5s network as follows:
[0042] S301, a new backbone network is constructed, and the new backbone network replaces the backbone network in the original YOLOv5s network; the new backbone network is composed of a CBRM module, a first Shuffle2 module, a first Shuffle1 module, a second Shuffle2 module, a second Shuffle1 module, a third Shuffle2 module and a third Shuffle1 module connected in sequence, and the output ends of the first Shuffle1 module, the second Shuffle1 module and the third Shuffle1 module are also connected with the input ends of the second concat layer, the first concat layer and the first Conv convolutional layer in the FPN structure of the neck network respectively; wherein,
[0043] The CBRM module is composed of a conv convolutional layer, a BN layer, a ReLU activation function and a max pooling layer connected in sequence; the convolution kernel size of the conv convolutional layer and the max pooling layer is 3x3, the sliding step of the convolution kernel is 2, and the padding quantity is 1;
[0044] The first Shuffle2 module, the second Shuffle2 module and the third Shuffle2 module have the same network structure, and specifically adopt the down-sampling module of ShuffleNet V2;
[0045] The first Shuffle1 module, the second Shuffle1 module and the third Shuffle1 module have the same network structure, and specifically adopt the basic module of ShuffleNet V2;
[0046] In the new backbone network, the Shuffle2 module and the Shuffle1 module are used alternately three times; wherein, referring to Figure 6 , the Shuffle1 module first adopts Channel split to divide the channel into two, realizes the effect of grouped convolution, then passes through a Conv convolution with a convolution kernel of 1x1, a DWConv convolution with a convolution kernel of 3x3 and a step of 1, and a Conv convolution with a convolution kernel of 1x1, finally, and the other road which does not perform any processing is Concat fused and then Channel Shuffle operation is performed; while the Shuffle2 module directly divides the input into two roads for processing at the same time, one of which adopts the same composition as the basic module, but the DWConv convolution has a step of 2, and the other road first passes through a DWConv convolution with a step of 2, and then a Conv convolution with a convolution kernel of 1x1; finally, the two roads are Concat fused and then Channel Shuffle operation is performed as the basic module. Based on this, the new backbone network effectively improves the calculation efficiency of the convolutional neural network, reduces the huge parameters, and enhances the feature expression ability and detection precision of the deep learning model, so that the model can have more lightweight while ensuring the detection precision;
[0047] S302, the neck network of the original YOLOv5s network is adopted, and in order to make up for the problem of insufficient model accuracy caused by lightweight design, an efficient channel attention mechanism (Efficient Channel Attention, ECA) is added in the neck network, that is, an ECA module, to obtain a new neck network, which realizes the decrease of the overall model parameter quantity while still maintaining the detection accuracy almost the same as YOLOv5;
[0048] The neck network of the original YOLOv5s network is composed of an FPN structure and a PAN structure; the FPN structure is sequentially connected by a first Conv convolutional layer, a first Upsample layer, a first concat layer, a first C3-2 layer, a second Conv convolutional layer, a second Upsample layer, a second concat layer and a second C3-2 layer; and the PAN structure is sequentially connected by a first Conv convolutional layer, a first concat layer, a first C3-2 layer, a second Conv convolutional layer, a second concat layer and a second C3-2 layer.
[0049] Based on this, the improved method of the new neck network is:
[0050] 1) A first ECA module is added after the second C3-2 layer in the FPN structure, and the connection between the second C3-2 layer and the first Conv convolutional layer in the PAN structure is deleted, so that the output end of the second C3-2 layer is connected to the input end of the first ECA module, and the output end of the first ECA module is connected to the input end of the first Conv convolutional layer in the PAN structure and the input end of the Detect module in the head network for processing the 80x80x128 feature layer;
[0051] 2) A second ECA module is added after the first C3-2 layer in the PAN structure, and the connection between the first C3-2 layer and the second Conv convolutional layer in the PAN structure is deleted, so that the output end of the first C3-2 layer is connected to the input end of the second ECA module, and the output end of the second ECA module is connected to the input end of the second Conv convolutional layer in the PAN structure and the input end of the Detect module in the head network for processing the 40x40x256 feature layer;
[0052] 3) A third ECA module is added after the second C3-2 layer in the PAN structure, so that the output end of the second C3-2 layer is connected to the input end of the third ECA module, and the output end of the third ECA module is connected to the input end of the Detect module in the head network for processing the 20x20x512 feature layer.
[0053] In the new neck network, the ECA module is used to first perform global average pooling on the input feature map, then extract the feature relationship between each K channel of the obtained average feature map using a one-dimensional convolution, and finally obtain the weight of the feature relationship through the Sigmoid function; it can be seen that the addition of the ECA module is used to enhance the features transmitted by the neck network to the detection end, thereby suppressing the invalid features of the feature map, and the enhanced features are further passed down for feature fusion.
[0054] S4, training and verifying the bottle cap defect recognition model:
[0055] The specific implementation steps of this step S4 are as follows:
[0056] S401, the bottle cap defect data set constructed by step S2 is randomly divided into a training set and a validation set in a ratio of 4:1; in this embodiment, the bottle cap defect data set consists of 2320 images, of which 1867 images are used as the training set and 453 images are used as the validation set.
[0057] S402, the training set obtained by step S2 is input into the bottle cap defect recognition model constructed by step S3, and the images with defects are input as the input and the categories of the defects are output as the output, so as to train the bottle cap defect recognition model; specifically, the training process adopts the Pytorch 1.10.0 deep learning framework, runs on the Quadro RTX 5000 and adopts the CUDA for GPU accelerated training, the input image size is automatically modified to 640x640 for training, the initial learning rate is set to 0.01, the cosine annealing learning rate adjustment strategy is adopted, the Adam gradient optimizer is used to find the optimal, and the batch size of the input picture is automatically calculated for training; in this embodiment, the training round is 250 rounds, and the number of defect recognition categories learned by the training is set to 6;
[0058] During the training process, after each round of training is completed, the weights generated by the bottle cap defect recognition model are input into the validation set to verify the model, and the recognition accuracy is obtained; the weights corresponding to the best round of recognition accuracy in the 250 rounds of training are saved, and the training is completed.
[0059] S5, using the trained bottle cap defect recognition model to detect defects of the bottle cap:
[0060] The method of step S1 is used to sequentially collect images of the bottle caps to be detected; in order to ensure the comprehensiveness of the detection, four side view images of each bottle cap to be detected are collected along the circumferential direction of the bottle cap, so as to ensure that the four images can cover the complete image of the bottle cap;
[0061] Referring to Figure 7 and Figure 8 the images collected by the above method are input into the trained bottle cap defect recognition model obtained by step S4, and a detection result image with a defect part mark and a display of a defect category and a confidence is obtained.
[0062] From Figure 7It can be seen from the figure that the trained bottle cap defect recognition model can effectively recognize the single defect existing on the bottle cap; wherein, part (a) of the figure is a schematic diagram of the identified deformation defect, part (b) is a schematic diagram of the identified damage defect, part (c) is a schematic diagram of the identified date error defect, part (d) is a schematic diagram of the identified bad edge defect, part (e) is a schematic diagram of the identified spinning defect, and part (f) is a schematic diagram of the identified breakpoint defect.
[0063] From Figure 8 It can be seen from the figure that the trained bottle cap defect recognition model can effectively recognize the multiple defects existing on the bottle cap; wherein, part (a) of the figure is a schematic diagram of one deformation defect and multiple damage defects, part (b) is a schematic diagram of one deformation defect and multiple breakpoint defects, part (c) is a schematic diagram of one deformation defect, one damage defect and one bad edge defect, and part (d) is a schematic diagram of one date error defect and multiple deformation defects.
[0064] In order to further verify the effect of the present application, Precision (P), Recall (R), mAP@.5, mAP@.5:.95, FLOPs, model size are used as evaluation indexes to compare the detection effect of the bottle cap defect detection model constructed by the present application and other similar lightweight models. Among them, P and R are the proportion of the number of correctly predicted positive samples; AP (Average Precision) is represented by the area surrounded by the P-R curve and its coordinate axes, which is drawn by taking R and P values as the horizontal and vertical coordinate axes; mAP (Mean Average Precision) is the average value of multiple defect AP values; FLOPs and model size are the calculation complexity of the model and the size of the optimal model parameter file saved after training.
[0065] The specific calculation formula of the above physical quantity is as follows:
[0066]
[0067]
[0068] In the formula, TP (True Positive) and FP (False Positive) are both the number of samples predicted to be true, but TP is actually true and FP is actually false; FN (False Negative) and TN (True Negative) are the number of samples predicted to be false, but FN is actually true and TN is actually false; N is the number of defect types, and based on the consideration that different IoU threshold settings affect the accuracy, a more balanced evaluation index mAP@.5, mAP@.5:.95 is used; wherein mAP@.5 is the mAP when IoU = 0.5; and mAP@.5:.95 is the average mAP under different threshold conditions when the IoU threshold range is 0.5 to 0.95 with a step of 0.05.
[0069] The specific test results are shown in Table 1.
[0070] Table 1: Ablation experiment test results
[0071]
[0072] In Table 1, YOLOv5s+SGD represents a model obtained by using the YOLOv5s network and using the SGD optimizer for training; YOLOv5s+Adam represents a model obtained by using the YOLOv5s and using the Adam optimizer for training; YOLOv5s(ECA)+Adam represents a model obtained by using only the method of step S302 of the present application to improve the YOLOv5s network to obtain a network, and using the Adam optimizer for training; Improved algorithm+SGD represents a model obtained by using only the method of step S301 of the present application to improve the YOLOv5s network to obtain a network, and using the SGD optimizer for training; Improved algorithm+Adam represents a model obtained by using only the method of step S301 of the present application to improve the YOLOv5s network to obtain a network, and using the Adam optimizer for training; Improved algorithm(CA)+Adam represents a model obtained by using only the method of step S302 of the present application to improve the YOLOv5s network, and replacing the ECA module with a CA module to obtain a network, and using the Adam optimizer for training; Improved algorithm(SE)+Adam represents a model obtained by using only the method of step S301 of the present application to improve the YOLOv5s network to obtain a network, and replacing the ECA module with an SE module to obtain a network, and using the Adam optimizer for training; Improved algorithm(CBAM)+Adam represents a model obtained by using only the method of step S301 of the present application to improve the YOLOv5s network to obtain a network, and replacing the ECA module with a CBAM module to obtain a network, and using the Adam optimizer for training; and the present application+Adam represents a model obtained by using the bottle cap defect detection model of the present application and using the Adam optimizer for training.
[0073] According to the test results in Table 1, the bottle cap defect detection model of the application can realize the detection accuracy of 82.9% mAP@.5, 48.2% mAP@.5:.95, overall, only 0.3% less than the original YOLOv5s algorithm in mAP@.5:.95, while FLOPs and model parameter file size are reduced from 16.3 GFLOPs to 6.9 FLOPS and 14.5 MB to 7 MB, and the model can realize a total of 51.7% reduction in parameter quantity.
[0074] Compared with other models, the model of the present application can achieve a detection accuracy of 82.9% mAP@.5 and 48.5% mAP@.5:.95, the model complexity FLOPs is 16.3 GFLOPS, and the model parameters are 14.5 MB, which are slightly better than YOLOv5s+SGD in various evaluation indexes, which can show that the use of Adam gradient optimizer can indeed improve the detection accuracy; on the basis of the foregoing, the ECA mechanism is added, and the YOLOv5s is improved by 1.2% mAP@.5 and 0.1% mAP@.5:.95, while the model file size remains unchanged, and the calculation complexity FLOPs increases by only 0.2 GFLOPS; after the lightweight backbone network, the FLOPs and file size of the model are reduced by more than 50%, but the model accuracy also decreases slightly, which can be referred to the comparison between the improved algorithm+SGD and the improved algorithm+Adam and YOLOv5s+SGD; in combination with the accuracy improvement brought by Adam and ECA mechanism, the lightweight algorithm of the present application is proposed, and the improved algorithm+Adam can achieve a detection accuracy of 82.9% mAP@.5 and 48.2% mAP@.5:.95, which is only reduced by 0.3% in mAP@.5:.95 compared with the original algorithm, and the FLOPs and model parameter file size are reduced from 16.3 GFLOPs to 6.9 FLOPS and 14.5 MB to 7 MB, respectively, and the model can achieve a reduction of 51.7% in the overall parameter amount. In addition, considering the use of multiple attention mechanisms to verify the effect of ECA mechanism on improving the detection accuracy, the improved algorithm(CA)+Adam, improved algorithm(SE)+Adam and improved algorithm(CBAM)+Adam experiments are carried out, and different attention mechanisms are used to analyze the effect of improving the detection accuracy while improving the backbone network. However, the effect is not satisfactory, and the improved algorithm(CA)+Adam with only CA attention mechanism can improve 1.7% mAP@.5, but reduce 0.8% in mAP@.5:.95, and the model parameter lightweight is not as good as the effect of ECA mechanism, and the addition of other attention almost reduces the detection accuracy, and is not as lightweight as ECA. Therefore, the algorithm of the present application(the present application+Adam) obtained by using ECA attention mechanism to enhance the detection accuracy, improving the lightweight feature extraction network and using Adam optimizer and other series of measures can realize almost the same detection accuracy as the original YOLOv5 algorithm, greatly reduce the model parameters, and be more lightweight.
[0075] Through the comparison of the above-mentioned multiple models, the effectiveness of the model improved based on the original YOLOv5s algorithm of the application can be verified, but in addition, there are still many excellent lightweight algorithms. In order to further prove, the lightweight versions of YOLOv3 and the currently best YOLOv7 algorithm, that is, YOLOv3-tiny and YOLOv7-tiny, are selected again for comparison experiments to explore the reliability of the model of the application.
[0076] The specific test results are shown in Table 2.
[0077] Table 2:
[0078]
[0079] According to the experimental results in Table 2, YOLOv7-tiny and the network model of the application are smaller than YOLOv5s, but YOLOv3-tiny is 20.6% larger than YOLOv5s; secondly, in terms of accuracy, using the Adam optimizer for gradient optimization can improve the accuracy of the model; YOLOv7-tiny increases 0.1% mAP@.5:.95 while mAP@.5 increases 0.9% compared with YOLOv5s+Adam, and the model size is reduced by 15.1%; and the network model of the application still maintains the detection accuracy of less than 1.2% difference from YOLOv7-tiny and YOLOv5s under the condition of reducing 51.7% of the YOLOv5s algorithm and 43.1% of the yolov7-tiny algorithm model parameters, which can prove the effectiveness and lightweight of the improved algorithm.
[0080] The above is only the preferred embodiment of the present application, and does not limit the present application in any form. Although the present application has been disclosed as above with the preferred embodiment, it is not intended to limit the present application. Any skilled person in the art can make some changes or modifications to the above-mentioned disclosed technical content without departing from the scope of the technical solution of the present application, and any simple modification, equivalent change and modification of the above-mentioned embodiments based on the technical essence of the present application are still within the scope of the technical solution of the present application.
Claims
1. An industrial packaging bottle cap production defect visual detection method based on lightweight improved YOLOv5, characterized by, The steps are as follows: S1, in the manner of collecting bottle cap side view images, sequentially image collection is performed on a plurality of bottle caps to obtain a sufficient number of bottle cap side view images for data set construction; S2, using a labeling tool labelimg, the bottle cap defect part in each image obtained from step S1 is sequentially circled and annotated to construct a bottle cap defect data set; wherein the bottle cap defect data set should include bottle cap images with the six defects described above; S3, a bottle cap defect recognition model is constructed based on a lightweight YOLOv5s network, and the steps are as follows: S301, a new backbone network is constructed to replace the backbone network in the original YOLOv5s network; the new backbone network is composed of a CBRM module, a first Shuffle2 module, a first Shuffle1 module, a second Shuffle2 module, a second Shuffle1 module, a third Shuffle2 module and a third Shuffle1 module connected in sequence, and the output ends of the first Shuffle1 module, the second Shuffle1 module and the third Shuffle1 module are also connected with the input ends of the second concat layer, the first concat layer and the first Conv convolutional layer in the FPN structure of the neck network respectively; the CBRM module is composed of a conv convolutional layer, a BN layer, a ReLU activation function and a max pooling layer connected in sequence; the convolution kernel size of the conv convolutional layer and the max pooling layer is 3*3, the sliding step of the convolution kernel is 2, and the padding number is 1; the first Shuffle2 module, the second Shuffle2 module and the third Shuffle2 module have the same network structure, and all of them adopt the down-sampling module of ShuffleNet V2; the first Shuffle1 module, the second Shuffle1 module and the third Shuffle1 module have the same network structure, and all of them adopt the basic module of ShuffleNet V2. S302, a first ECA module is added after the second C3-2 layer in the FPN structure, and the connection between the first ECA module and the first Conv convolutional layer in the PAN structure is deleted, so that the output end of the second C3-2 layer is connected with the input end of the first ECA module, and the output end of the first ECA module is connected with the input end of the first Conv convolutional layer in the PAN structure and the input end of the Detect module in the head network for processing the 80x80x128 feature layer; a second ECA module is added after the first C3-2 layer in the PAN structure, and the connection between the second ECA module and the second Conv convolutional layer in the PAN structure is deleted, so that the output end of the first C3-2 layer is connected with the input end of the second ECA module, and the output end of the second ECA module is connected with the input end of the second Conv convolutional layer in the PAN structure and the input end of the Detect module in the head network for processing the 40x40x256 feature layer; a third ECA module is added after the second C3-2 layer in the PAN structure, so that the output end of the second C3-2 layer is connected with the input end of the third ECA module, and the output end of the third ECA module is connected with the input end of the Detect module in the head network for processing the 20x20x512 feature layer; S4, the bottle cap defect data set constructed by step S2 is randomly divided into a training set and a validation set; the training set is input into the bottle cap defect recognition model, and the image with defects is taken as the input and the category of the defect is taken as the output, so as to train the bottle cap defect recognition model; the validation set is used for verification in the training process; S5, the trained bottle cap defect recognition model is used for defect detection of the bottle cap.
2. The industrial packaged bottle cap production defect visual detection method based on the lightweight improved YOLOv5s according to claim 1, characterized in that, In step S2, the bottle cap defect part in the image is annotated in the form of a circle, that is, a minimum bounding rectangle of the defect is drawn in the image, and the defect type is annotated on the rectangle.
3. The industrial packaged bottle cap production defect visual inspection method based on the lightweight improved YOLOv5s according to claim 1, characterized in that, In step S2, the bottle cap defect data set is composed of a plurality of bottle cap images with single defect and a plurality of bottle cap images with multiple defects, and the proportions of the two in the bottle cap defect data set are the same.
4. The industrial packaged bottle cap production defect visual inspection method based on the lightweight improved YOLOv5s according to claim 1, characterized in that, In step S4, in the training process of the model, the initial learning rate is set to 0.01, the cosine annealing learning rate adjustment strategy is adopted, and the Adam gradient optimizer is used to find the optimum.
Citation Information
Patent Citations
Cigarette packet appearance defect detection method based on YOLOV5 network
CN113781435A
Plastic surface defect detection method based on improved YOLOv5s
CN114943683A