Corrugated carton surface defect detection method based on Slim-YOLOv8
By optimizing the YOLOv8 network and building the Slim-YOLOv8 model, the real-time and accuracy problems of corrugated carton defect detection on the tobacco production assembly line are solved, and high-accuracy defect detection is achieved, meeting the detection needs of the assembly line.
Patent Information
- Application Number
- CN202411357274.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2025-01-14
AI Technical Summary
The existing technology cannot meet the real-time and accurate defect detection requirements of corrugated cartons on the tobacco production line, especially since visual inspection is prone to missed and missed, and is subjectively affected by people. Deep learning algorithms are still in real-time and accurate. Need to improve.
The YOLOv8 network is optimized by lightweight paradigm and online re-parameterization method, and the Slim-YOLOv8 model is built, and the neck network is reduced through Slim-neck and the backbone network is enhanced through online re-parameterization. Combined with GSConv and OREPA modules, auxiliary training heads are introduced to realize corrugated paper Box surface defect detection.
It realizes high accuracy detection of all-round defect locations and sizes of corrugated cartons on the tobacco production line, with fewer parameters, which improves the real-time and accuracy of detection, reduces the memory usage of model training and inference, and improves training efficiency.
Smart Images

Figure CN119313625A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of defect detection, and in particular to a corrugated box surface defect detection method based on Slim-YOLOv8. Background Art
[0002] At present, the inspection of corrugated paper boxes for tobacco leaves on the tobacco processing line mainly relies on visual information. However, this method cannot be sustained for a long time and is greatly affected by human subjectivity. It is prone to missed inspections and wrong inspections, and cannot meet the needs of current industry development.
[0003] With the rapid development of convolutional neural networks, deep learning has gradually become the mainstream method for surface defect detection. Defect detection networks based on deep learning can be structurally divided into two types: two-stage networks represented by Faster-RCNN and one-stage networks represented by SSD or YOLO. The main difference between the two is that the two-stage network needs to first generate candidate boxes that may contain defects, and then further perform target detection. The one-stage network directly uses the features extracted from the network to predict the location and category of defects. In 2022, Jia Weiping et al. proposed a surface defect detection method for corrugated paper boxes for cigarettes based on YOLOv3, and compared it with FasterRCNN, established a recycling performance evaluation system for corrugated paper boxes for cigarettes, and proved the effectiveness of corrugated paper box defect detection based on deep learning, but its algorithm performance needs to be improved in real time and accuracy. Considering that real-time defect detection is required for multiple surfaces of corrugated boxes filled with tobacco leaves in the tobacco production line, higher requirements are placed on the real-time and accuracy of the algorithm. In this paper, a lightweight paradigm and an online re-parameterization method are adopted to optimize the YOLOv8 network, and a corrugated box defect detection algorithm suitable for the tobacco production line is proposed. Summary of the invention
[0004] The purpose of the present invention is to provide a corrugated box surface defect detection method based on Slim-YOLOv8, which uses fewer parameters and has high accuracy, and can successfully realize the comprehensive defect position and size detection of corrugated boxes on a tobacco production line.
[0005] To achieve the above object, the present invention provides a corrugated box surface defect detection method based on Slim-YOLOv8, comprising the following steps:
[0006] S1. Collecting images of surface defects of corrugated paper boxes, constructing a data set of surface defects of corrugated paper boxes and preprocessing the data set to obtain a preprocessed data set of surface defects of corrugated paper boxes;
[0007] S2. Build the Slim-YOLOv8 model.
[0008] S21, use Slim-neck to reduce the neck network of the YOLOv8 model;
[0009] S22. Use online reparameterization to enhance the backbone network of the YOLOv8 model;
[0010] S23, introduce auxiliary training head to train the network;
[0011] S3, input the preprocessed corrugated box surface defect dataset into the constructed Slim-YOLOv8 model for defect detection;
[0012] S4. Output defect detection results.
[0013] Preferably, in step S21, Slim-neck is used to reduce the neck network of the YOLOv8 model, comprising the following steps:
[0014] S211. Use lightweight convolution operation GSConv to replace traditional convolution operation;
[0015] S212. Continue to introduce GSBottleneck based on GSConv.
[0016] Preferably, in step S211, the specific operations are as follows:
[0017] First, use a CBS to downsample the input features to get the first convolution result;
[0018] Then, use DWCBS to perform depth-separable convolution to obtain the second convolution result, and then concatenate the two convolution results;
[0019] Finally, a shuffle operation is performed to piece together the corresponding number of channels of the two convolutions.
[0020] Preferably, in step S211, CBS is a convolution block composed of a convolution layer, a batch normalization layer and a SiLU activation function in sequence; DWCBS is a convolution block composed of a deep convolution layer, a batch normalization layer and a SiLU activation function in sequence.
[0021] Preferably, in step S212, GSBottleneck is a dual-branch residual structure consisting of a single CBS branch and a dual GSConv branch;
[0022] Use GSBottleneck to build the VoV-GSCSP module as CSPLayer to replace the C2f module in the neck network of the YOLOv8 model.
[0023] Preferably, in step S22, the backbone network of the YOLOv8 model is enhanced by online reparameterization, comprising the following steps:
[0024] S221, replacing the BN layer in the heavy parameter block with a linear scaling layer;
[0025] S222, fuse the convolutional layer and the linear scaling layer, and then add a BN layer after the residual connection;
[0026] S223. Convert and fuse all convolutional layers into a single 3×3 convolution to achieve equivalent conversion from multi-branch to single-branch.
[0027] Preferably, in step S221, the scaling factor α of the linear scaling layer is calculated as follows:
[0028] α=[α[1],α[2],…,α[c]]
[0029] During the forward propagation process, the input feature map x[i] is multiplied by the scaling factor α to obtain the output feature map y[i]:
[0030] y[i]=α[i]×x[i]
[0031] where α[i] is the scaling factor for the i-th channel.
[0032] Preferably, the output defect detection results include: scratches, breaks, creases, and stains.
[0033] Therefore, the present invention adopts the above-mentioned corrugated box surface defect detection method based on Slim-YOLOv8, and the technical effects are as follows:
[0034] (1) GSConv combines the advantages of ordinary convolution and depthwise separable convolution. It has the ability of traditional convolution to effectively connect channel information, minimizes the negative impact of insufficient precision caused by the separation of channel information of the input image in DWCBS, and effectively utilizes its lightweight advantages of reducing the number of parameters and floating-point operations.
[0035] (2) After using the slim-neck paradigm, the number of parameters in the neck network of the model will be greatly reduced, and the appropriate number of depth-separable convolutional layers and shuffle layers will enhance the nonlinear expression ability of the network to a certain extent;
[0036] (3) The OREPA re-parameter block consists of six branches, each of which is followed by a linear scaling layer, which is used to optimize each branch in different directions and facilitate integration with other network structures of the branch. During training, the complex re-parameter block will be compressed into a simple convolutional layer and BN layer. Since the multi-branch structure has excellent feature expression capabilities, the re-parameter block can greatly enhance the feature extraction capability of the backbone network. At the same time, because it can be compressed into a simple single-branch structure during training, the memory occupied during model training is greatly reduced, and a larger batch size can be used to train the network, which will further help the model convergence; the extremely high training efficiency also helps us better adjust the model training hyperparameters;
[0037] (4) The present invention uses fewer parameters and has a high accuracy rate, and can successfully realize the full range of defect position and size detection of corrugated paper boxes on the tobacco production line. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 This is the YOLOv8 network structure diagram;
[0039] Figure 2 It is the structure diagram of GSConv;
[0040] Figure 3 The structure diagram of GSBottleneck and VoVGSCSP;
[0041] Figure 4 It is a comparison between the traditional reparameterization module and the OREPA transformation process;
[0042] Figure 5 It is the network structure of slim-YOLOv8;
[0043] Figure 6 This is the OREPA structure diagram. DETAILED DESCRIPTION
[0044] The technical solution of the present invention is further described below through the accompanying drawings and embodiments.
[0045] Unless otherwise defined, technical or scientific terms used in the present invention shall have the common meanings understood by one having ordinary skills in the field to which the present invention belongs.
[0046] Embodiment 1
[0047] like Figure 1 As shown in the figure, the network structure of YOLOv8 is mainly composed of three parts: backbone network, neck network and detection head.
[0048] The present invention provides a corrugated box surface defect detection method based on Slim-YOLOv8, which specifically comprises the following steps:
[0049] S1. Collecting images of surface defects of corrugated paper boxes, constructing a data set of surface defects of corrugated paper boxes and performing preprocessing to obtain a preprocessed data set of surface defects of corrugated paper boxes. The preprocessing operation is well known to those skilled in the art and will not be described in detail here.
[0050] S2. Build the Slim-YOLOv8 model (such as Figure 5 As shown); this network model is improved based on YOLOv8, adopts the slim-neck paradigm to reduce the neck network, and uses online reparameterization to enhance the backbone network. The improved model is called the slim-YOLOv8 network model.
[0051] S21, use Slim-neck to reduce the neck network of the YOLOv8 model;
[0052] S211. Use lightweight convolution operation GSConv to replace traditional convolution operation;
[0053] The structure of GSConv is as follows Figure 2 As shown, it combines traditional convolution and depth-wise separable convolution;
[0054] Figure 2 In , CBS is a convolutional block consisting of Conv layer, Batch Normalization layer and SiLU activation function in sequence. DWCBS is a depth-wise separable convolutional block consisting of DWConv layer, Batch Normalization layer and SiLU activation function in sequence.
[0055] The specific operations of step S211 are as follows:
[0056] First, GSConv uses a CBS to downsample the input features to obtain the first convolution result;
[0057] Then, use DWCBS to perform depth-separable convolution to obtain the second convolution result, and then concatenate the two convolution results;
[0058] Finally, a shuffle operation is performed to piece together the corresponding number of channels of the two convolutions.
[0059] S212, based on GSConv, GSBottleneck is introduced. Figure 3 As shown in , GSBottleneck is a dual-branch residual structure consisting of a single CBS branch and a dual GSConv branch. Finally, GSBottleneck is used to construct the VoV-GSCSP module as CSPLayer to replace the C2f module in the neck network of the baseline model. Figure 3As shown in the figure, the VoV-GSCSP module consists of CBS, GSConv and GSbottleneck. After using the slim-neck paradigm, the number of parameters of the neck network of the model will be greatly reduced, and the appropriate amount of depth-separable convolutional layers and shuffle layers will enhance the nonlinear expression ability of the network to a certain extent.
[0060] S22. Use online reparameterization to enhance the backbone network of the YOLOv8 model;
[0061] In the network structure of slim-YOLOv8, OREPA is introduced and the C2f module is optimized to C2f_OREPA module. On the basis of retaining the C2f structure, its Bottleneck is changed to OREPA heavy parameter block, such as Figure 6 As shown in the figure. The OREPA re-parameter block consists of six branches, each of which is followed by a linear scaling layer, which is used to optimize each branch in different directions and facilitate integration with other network structures of the branch. During training, the complex re-parameter block will be compressed into a simple convolution layer and BN layer. Since the multi-branch structure has excellent feature expression capabilities, the re-parameter block can greatly enhance the feature extraction capability of the backbone network. At the same time, because it can be compressed into a simple single-branch structure during training, the memory occupied during model training is greatly reduced, allowing us to use a larger batch size to train the network, which will further help the model converge. In addition, the extremely high training efficiency also helps us better adjust the model training hyperparameters.
[0062] Structural reparameterization can improve model performance without increasing the cost of inference time. Specifically, it uses complex topological structures to enhance network fitting ability during training, and converts these topological structures into simple single-branch structures during inference. Figure 4 As shown in the figure, assuming that the topology used in model training is a heavy parameter block with three branches, the model will perform three-step transformation operations on the structure before reasoning.
[0063] S221. Structural reparameterization utilizes the multi-branch topology structure to facilitate the lossless conversion of the multi-branch structure to a single branch during training and reasoning, thereby achieving "zero cost" to improve the model reasoning performance. However, complex reparameter blocks will cause huge additional training costs, and the high training costs will make it difficult to explore reparameter blocks with better performance. The reason why the traditional reparameter module can only complete the transfer of branch structures during the reasoning process but not during the training process is because the BN layer is linear during reasoning but nonlinear during training. To solve this problem, the BN layer in the reparameter block is replaced with a linear scaling layer;
[0064] The scaling factor α of the linear scaling layer is calculated as follows:
[0065] α=[α[1],α[2],…,α[c]]
[0066] During the forward propagation process, the input feature map x[i] is multiplied by the scaling factor α to obtain the output feature map y[i]:
[0067] y[i]=α[i]×x[i]
[0068] where α[i] is the scaling factor for the i-th channel.
[0069] The linear scaling layer has a similar effect to the BN layer, both of which promote multi-branch optimization in different directions.
[0070] S222, fuse the convolutional layer and the linear scaling layer, and then add a BN layer after the residual connection;
[0071] S223. Convert and fuse all convolutional layers into a single 3×3 convolution to achieve equivalent conversion from multi-branch to single-branch.
[0072] S23, introduce auxiliary training head to train the network;
[0073] S3, input the preprocessed corrugated box surface defect dataset into the constructed Slim-YOLOv8 model for defect detection;
[0074] S4. Output defect detection results.
[0075] The present invention will be further described below through specific examples.
[0076] A corrugated box surface defect dataset was collected in a cardboard production plant, including a total of 1,057 real scene images. After preprocessing the dataset, it was randomly divided into training set, validation set, and test set in a ratio of 8:1:1. The surface of the carton contains scratches, damage, creases, stains and other defect types, and each sample image contains defects of different numbers and types, with a total of 2,630 labels.
[0077] In terms of the hardware and software configuration of the experimental platform, the operating system used in the experiment is Ubuntu, the GPU is Nvidia RTX 3090 (24GB), and the deep learning framework is Pytorch.
[0078] In terms of model hyperparameters, due to the use of OREPA, the extremely high training efficiency allows us to try various hyperparameters, and select the one with better overall model performance in multiple experiments. Slim-YOLOv8 uses batch gradient descent with momentum for training, and the optimization function sets the momentum to 0.9. In addition, the cosine annealing method is used to dynamically update the learning rate, with an initial learning rate of 0.03 and a final learning rate of 0.003. Finally, OREPA also supports the use of larger batch sizes to train the model, and 100 epochs were trained with a batch size of 32.
[0079] In order to demonstrate the excellent performance of slim-YOLOv8, a large number of comparative experiments were conducted on the above datasets using other models, as shown in Table 1. Each model was trained for 100 epochs with appropriate training parameters. The models used for comparison are divided into two parts.
[0080] The first part is most of the models in the YOLO series. Since slim-YOLOv8 is improved on the basis of the YOLO series, the use of the YOLO series models for comparative experiments can reflect the effectiveness of the improvements made by the present invention. In the comparative experiments of this part of the model, the training parameters used are exactly the same as those of slim-YOLOv8. As can be seen from Table 1, among the models in the entire YOLO series, YOLOv8 has the best overall performance and achieves higher detection performance with a small amount of model parameters. This is also the reason why YOLOv8 is selected as the baseline model for improvement. Finally, it was achieved that the mAP50 and mAP50-95 were improved by 1.4% and 1.1% respectively with v8n as the baseline model, and the mAP50 and mAP50-95 were improved by 1.3% and 1% respectively with v8s as the baseline model.
[0081] The second part is the classic network model, which includes the anchor based algorithm Retinanet, the anchor free algorithm FCOS, and the classic two-stage detection model Faster RCNN, which are all one-stage detection models. And because these models appeared earlier, we added the commonly used FPN feature fusion module to them for comparison with slim-YOLOv8. Since these models are very different from slim-YOLOv8 in structure and cannot adapt well to the training parameters of slim-YOLOv8, we use the default hyperparameters provided by these models for training.
[0082] Table 1 Comparative experiment
[0083]
[0084]
[0085] Therefore, the present invention adopts the above-mentioned corrugated paper box surface defect detection method based on Slim-YOLOv8, which uses fewer parameters and has high accuracy, and can successfully realize the comprehensive defect position and size detection of corrugated paper boxes on the tobacco production line.
[0086] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that they can still modify or replace the technical solution of the present invention with equivalents, and these modifications or equivalent replacements cannot cause the modified technical solution to deviate from the spirit and scope of the technical solution of the present invention.
Claims
1. A corrugated box surface defect detection method based on Slim-YOLOv8, characterized in that: The following steps are involved: S1. Collecting images of surface defects of corrugated paper boxes, constructing a data set of surface defects of corrugated paper boxes and preprocessing the data set to obtain a preprocessed data set of surface defects of corrugated paper boxes; S2. Build the Slim-YOLOv8 model. S21, use Slim-neck to reduce the neck network of the YOLOv8 model; S22. Use online reparameterization to enhance the backbone network of the YOLOv8 model; S23, introduce auxiliary training head to train the network; S3, input the preprocessed corrugated box surface defect dataset into the constructed Slim-YOLOv8 model for defect detection; S4. Output defect detection results.
2. According to a method for detecting surface defects of corrugated paper boxes based on Slim-YOLOv8 in claim 1, it is characterized in that: In step S21, Slim-neck is used to reduce the neck network of the YOLOv8 model, including the following steps: S211. Use lightweight convolution operation GSConv to replace traditional convolution operation; S212. Continue to introduce GSBottleneck based on GSConv.
3. A method for detecting surface defects of corrugated paper boxes based on Slim-YOLOv8 according to claim 2, characterized in that: In step S211, the specific operations are as follows: First, use a CBS to downsample the input features to get the first convolution result; Then, use DWCBS to perform depth-separable convolution to obtain the second convolution result, and then concatenate the two convolution results; Finally, a shuffle operation is performed to piece together the corresponding number of channels of the two convolutions.
4. A method for detecting surface defects of corrugated paper boxes based on Slim-YOLOv8 according to claim 3, characterized in that: In step S211, CBS is a convolutional block composed of a convolutional layer, a batch normalization layer and a SiLU activation function in sequence; DWCBS is a convolutional block composed of a deep convolutional layer, a batch normalization layer and a SiLU activation function in sequence.
5. A method for detecting surface defects of corrugated paper boxes based on Slim-YOLOv8 according to claim 4, characterized in that: In step S212, GSBottleneck is a dual-branch residual structure consisting of a single CBS branch and a dual GSConv branch; Use GSBottleneck to build the VoV-GSCSP module as CSPLayer to replace the C2f module in the neck network of the YOLOv8 model.
6. A method for detecting surface defects of corrugated paper boxes based on Slim-YOLOv8 according to claim 5, characterized in that: In step S22, the backbone network of the YOLOv8 model is enhanced by online reparameterization, including the following steps: S221, replacing the BN layer in the heavy parameter block with a linear scaling layer; S222, fuse the convolutional layer and the linear scaling layer, and then add a BN layer after the residual connection; S223. Convert and fuse all convolutional layers into a single 3×3 convolution to achieve equivalent conversion from multi-branch to single-branch.
7. A method for detecting surface defects of corrugated paper boxes based on Slim-YOLOv8 according to claim 6, characterized in that: In step S221, the scaling factor α of the linear scaling layer is calculated as follows: α=[α[1],α[2],…,α[c]] During the forward propagation process, the input feature map x[i] is multiplied by the scaling factor α to obtain the output feature map y[i]: y[i]=α[i]×x[i] where α[i] is the scaling factor for the i-th channel.
8. A method for detecting surface defects of corrugated paper boxes based on Slim-YOLOv8 according to claim 7, characterized in that: Output defect detection results include: scratches, breaks, creases, and stains.