Bottle cap packaging defect detection method based on MLT-YOLO network
By improving the YOLO network model and introducing wavelet convolution and multi-branch feature pyramid network, a lightweight detection head was designed, which solved the efficiency and accuracy problems in bottle cap packaging defect detection and achieved efficient identification and localization in complex environments.
Patent Information
- Application Number
- CN202510988714.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-17
- Publication Date
- 2025-10-31
AI Technical Summary
Existing technologies suffer from low efficiency and difficulty in guaranteeing accuracy in detecting defects in bottle cap packaging, especially in identifying complex backgrounds and subtle defects.
An improved MLT-YOLO network model is adopted. By introducing wavelet convolution WTConv and multi-branch auxiliary feature pyramid network MAFPN into the backbone network of YOLO11n, a lightweight detection head CGNL is designed, a C3K2-WT feature extraction module and a lightweight detection head are constructed, and the loss function is optimized to improve detection accuracy and efficiency.
In complex backgrounds and production environments, it can efficiently and accurately identify and locate minute defects on bottle cap packaging, improving detection accuracy and reducing computational burden, making the model suitable for deployment on resource-constrained devices.
Smart Images

Figure CN120876409A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to a method for detecting bottle cap packaging defects based on MLT-YOLO networks. Background Technology
[0002] Glass bottles are one of the main containers for holding liquor, and the bottle cap, as the only barrier between the liquor and the outside world, plays a crucial role in maintaining the quality of the liquor. During the production, storage, and transportation of liquor, various factors can cause defects in the bottle cap seals, such as abnormal coding, deformation, breakage, and breaks. These defects not only affect the identification of key information such as the product appearance and production date, but can also allow air to enter the bottle, accelerating the spoilage of the liquor, causing the loss of aroma, and seriously affecting its taste and quality. Therefore, timely inspection of the bottle cap seal quality is crucial to ensuring product quality. Currently, manual inspection remains the mainstream method for detecting bottle cap defects. In industrial production scenarios, bottle cap seal defects are characterized by their small size, variety, and scattered distribution. Manual inspection is affected by subjective factors, resulting in low efficiency and difficulty in guaranteeing accuracy, which cannot meet the needs of large-scale production.
[0003] With the evolution of computer technology, especially deep learning, machine vision and deep learning technologies have opened up entirely new paths for detecting defects in bottle cap packaging. Deep learning algorithms, with their superior feature mining capabilities, complex network architecture design, and efficient data utilization, have demonstrated wide applicability in the field of object detection, with their generalization performance significantly surpassing traditional machine learning algorithms. YOLO, as a classic one-stage object detection algorithm, completes the entire detection process with a single forward propagation, offering significant advantages such as high detection speed, low hardware resource consumption, and convenient deployment, making it particularly competitive in lightweight deployment scenarios for edge devices.
[0004] In the field of bottle cap packaging defect detection, the application of deep learning methods has significantly improved detection efficiency and accuracy. However, existing methods are mostly aimed at simple positional defects in bottle cap packaging, and their effectiveness is not good at detecting complex defects such as bottle cap breaks, damage, and abnormal coding. These subtle defects are particularly difficult to detect in industrial production environments. Summary of the Invention
[0005] In view of this, the present invention provides a bottle cap packaging defect detection method based on MLT-YOLO network, which can effectively distinguish actual defects from background noise in complex backgrounds and production environments while maintaining high accuracy, so as to accurately identify and locate minor defects on bottle cap packaging.
[0006] In a first aspect, the present invention provides a method for detecting bottle cap packaging defects based on an MLT-YOLO network, the method comprising: Step 1: Obtain the dataset of bottle cap sealing defects, and obtain the training dataset, validation dataset, and test dataset; Step 2: Improve the YOLO11n network model to obtain the MLT-YOLO network model; Step 3: Train the MLT-YOLO network model using the training dataset and use the validation dataset to guide parameter updates to obtain the optimal weight file; Step 4: Call the optimal weight file and evaluate the MLT-YOLO network model using the test dataset to obtain the evaluation results.
[0007] Optionally, step 1 includes: After acquiring images of bottle cap packaging defects, preprocessing and labeling them, the processed image dataset is divided into training, validation and test datasets in a 7:2:1 ratio. After appropriate data augmentation, the datasets are stored in the specified paths, and the corresponding paths of the training, validation and test datasets are added to the model's YAML configuration file.
[0008] Optionally, step 2 includes: The YOLO11n network model was improved by introducing wavelet convolution WTConv into its backbone network to construct the C3K2-WT feature extraction module; the neck architecture was redesigned using the multi-branch auxiliary feature pyramid network MAFPN; the detector head with a large receptive field was removed and a lightweight detector head CGNL was designed to obtain the MLT-YOLO network model.
[0009] Optionally, it includes: Step 21: In the backbone network of the YOLO11n network model, wavelet convolution WTConv is used to replace the convolutional layer in the bottleneck structure Bottleneck, and the C3K2 feature extraction module is improved to construct the C3K2-WT feature extraction module. Step 22: Redesign the neck network structure using the Multi-Branch Auxiliary Feature Pyramid Network (MAFPN); to integrate the output features of the backbone network, introduce the Shallow Auxiliary Fusion (SAF) module and the High-Level Auxiliary Fusion (AAF) module; Step 23: Remove the detection head for large targets and construct a compensatory group normalized lightweight detection head CGNL, whose expression is: ; in, Used for scaling features; This represents a shared-group normalized convolution with a kernel size of 1×1. This represents a shared-group normalized convolution with a kernel size of 3×3; This indicates a 3×3 convolution kernel.
[0010] Optionally, step 21 includes: The original convolution in the C3K2 feature extraction module is replaced with wavelet convolution WTConv to construct the C3K2-WT module; firstly, the input features are processed... Figure X A convolution operation is performed, and the output feature map is evenly divided into two parts in the channel. The feature map of the main branch is subjected to multiple wavelet convolutions (WTConv) through multiple bottleneck structures (Bottleneck) to extract spatial features, and residual connections are used to prevent network degradation. The other part does not perform a convolution operation and is concatenated with the output feature map of the main branch in the channel dimension. Finally, nonlinear features are extracted through a 3×3 convolutional layer. The process of WTConv wavelet convolution includes: a. Input feature map Perform wavelet transform to decompose it into sub-graphs of different frequencies. For the low-frequency component of X, These represent the horizontal, vertical, and diagonal high-frequency components of X, respectively; then, the low-frequency components are recursively decomposed, with the following expression: ; Where i is 1, Representing input features Figure X ; b. Utilizing the properties of wavelet transform, a small-kernel convolution operation is performed on the sub-image in the wavelet domain to achieve coverage of a large receptive field with a small convolution kernel. The expression is as follows: ; in, This represents the weight tensor of a 3×3 depth convolution kernel; This represents the output subband after convolution; c. Reconstruct the convolved sub-image back to the original space using inverse wavelet transform to obtain the final output feature map Y, whose expression is: ; in, This represents the inverse wavelet transform.
[0011] Optionally, step 22 includes: d. Reconstruct the neck network structure using the Multi-Branch Auxiliary Feature Pyramid Network (MAFPN). Perform feature fusion using a shallow-layer auxiliary fusion (SAF) module in the shallow layers of the neck network. The implementation steps are as follows: d1. Baseline Feature Map Localization: Feature maps output by the backbone network. It serves as a benchmark for resolution matching, used to unify the spatial dimensions of feature maps at different levels; d2. Shallow Feature Map Downsampling: This involves downsampling high-resolution feature maps from shallow layers. Perform a 3×3 downsampling convolution operation with a batch normalization layer to match the resolution of the baseline feature map; d3. Deep Feature Map Upsampling (Up): Upsampling of low-resolution feature maps The result of performing SAF module operations ,Will Perform nearest neighbor interpolation upsampling to match the resolution of the baseline feature map; d4. Channel Control: Adjusting the channel dimension after downsampling using a 1×1 convolution. The number of channels was adjusted to , Half the number of channels, to balance the preservation of shallow information with the stability of deep feature learning; d5. Feature Map Concat: This step fuses feature maps from different levels with matched resolutions and adjusted channel counts to generate a feature map containing multi-scale information. ; d6. Let n = n+1 or n = n-1, and repeat d1 to d5 to generate sequentially. , .
[0012] e. In the deep layers of the neck network, use the Advanced Auxiliary Fusion (AAF) module to perform feature fusion, and remove AAF modules that are associated with large target detection heads and output low-resolution feature maps. The implementation steps are as follows: e1. Baseline Feature Map Localization: Feature map output by the SAF module As a benchmark, it is used to unify the spatial dimensions of feature maps at different levels; e2. Shallow Feature Map Downsampling: This involves downsampling the output of the SAF module. The feature maps are subjected to a 3×3 downsampling convolution operation with batch normalization, and the output of the AAF module is processed. The feature maps undergo the same downsampling operation to match the resolution of the baseline feature map; e3. Deep Feature Map Upsampling (Up): Upsampling the low-resolution feature map output by the SAF module. Nearest neighbor interpolation upsampling is used to match the resolution of the baseline feature map; e4. Channel Control: Use 1×1 convolution to adjust the number of channels in the downsampled shallow feature map and the upsampled deep feature map to ensure that the number of channels in different layers of feature maps is consistent during the stitching operation. e5. Feature Map Concat: This function fuses feature maps from different levels that have matching resolutions and the same number of channels through a concat operation, generating a feature map that contains multi-scale semantic information. ; e6. Let n = n-1 or n = n+1, and repeat e1 to e5 to generate the following values in sequence. , .
[0013] Optionally, step 3 includes: Configure the model training environment, read the training and validation datasets via YAML files, train the MLT-YOLO network model, optimize the loss function of the MLT-YOLO network model during training until training converges, and use the validation dataset to guide parameter updates to obtain the optimal weight file.
[0014] Optionally, step 4 includes: The MLT-YOLO network model was evaluated using the test dataset. In terms of detection accuracy, the mean accuracy (mAP) was used to evaluate the network model's detection performance on the augmented dataset. In terms of detection speed, the number of defective image frames per second (FPS) was used as the evaluation metric. In terms of network complexity, the number of network parameters (Params), floating-point operations (FLOPS), and model size were used to measure the network's lightweight nature.
[0015] In a second aspect, embodiments of the present invention provide a computer-readable storage medium comprising a stored program, wherein, when the program is executed, it controls the device where the computer-readable storage medium is located to perform the bottle cap packaging defect detection method based on the MLT-YOLO network in the first aspect or any possible implementation thereof.
[0016] Thirdly, embodiments of the present invention provide an electronic device, including: one or more processors; a memory; and one or more computer programs, wherein the one or more computer programs are stored in the memory, and the one or more computer programs include instructions that, when executed by the device, cause the device to perform the bottle cap packaging defect detection method based on the MLT-YOLO network in the first aspect or any possible implementation of the first aspect.
[0017] The technical solution provided by this invention includes a method that involves acquiring a dataset of bottle cap packaging defects to obtain a training dataset, a validation dataset, and a test dataset; improving the YOLO11n network model to obtain an MLT-YOLO network model; training the MLT-YOLO network model using the training dataset and using the validation dataset to guide parameter updates to obtain an optimal weight file; calling the optimal weight file and evaluating the MLT-YOLO network model using the test dataset to obtain evaluation results. This method maintains high accuracy while effectively distinguishing actual defects from background noise in complex backgrounds and production environments, accurately identifying and locating minor flaws in bottle cap packaging. Attached Figure Description
[0018] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 A flowchart of a bottle cap packaging defect detection method based on MLT-YOLO network provided in an embodiment of the present invention; Figure 2 The image shows the defect features of bottle cap packaging provided in the embodiments of the present invention, wherein (a) represents the location distribution features; and (b) represents the size features. Figure 3 A schematic diagram of the MLT-YOLO network architecture provided in an embodiment of the present invention; Figure 4 This is a schematic diagram of the compensatory group normalized lightweight detection head CGNL structure provided in an embodiment of the present invention; Figure 5 This is a schematic diagram of the C3K2-WT structure provided in an embodiment of the present invention; Figure 6a This is a schematic diagram of a shallow-assisted fusion SAF structure provided in an embodiment of the present invention; Figure 6b A schematic diagram of the advanced auxiliary fusion AAF structure provided in the embodiments of the present invention; Figure 7 The graph shows a comparison of test results between the MLT-YOLO network provided in this embodiment of the invention and existing models, where (a) is the curve of the Precision metric; (b) is the curve of the Recall metric; and (c) is... The curve of the indicator's change; (d) is The curve of the indicator's change; Figure 8The diagram shows a comparison of the maximum receptive field of the MLT-YOLO network and the YOLO11n network provided in the embodiments of the present invention, wherein (a) is the maximum receptive field of the original model; and (b) is the maximum receptive field after adding wavelet convolution. Figure 9 The HiResCAM heatmap comparison diagrams of the MLT-YOLO network and the YOLO11n network provided in the embodiments of the present invention are shown; where (a), (b), (c), and (d) are four images randomly selected from the validation set. Figure 10 This is a schematic diagram of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0020] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0021] It should be understood that the described embodiments are merely some, not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.
[0022] The terminology used in the embodiments of this invention is for the purpose of describing particular embodiments only and is not intended to limit the invention. The singular forms “a,” “the,” and “the” used in the embodiments of this invention are also intended to include the plural forms unless the context clearly indicates otherwise.
[0023] It should be understood that the term "and / or" used in this article is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Additionally, the character " / " in this article generally indicates that the preceding and following related objects have an "or" relationship.
[0024] Depending on the context, the word "if" as used here can be interpreted as "when," "when," "in response to determination," or "in response to detection." Similarly, depending on the context, the phrase "if determination" or "if detection (of the stated condition or event)" can be interpreted as "when determination," "in response to determination," "when detection (of the stated condition or event)," or "in response to detection (of the stated condition or event)."
[0025] Figure 1 The flowchart of the bottle cap packaging defect detection method based on MLT-YOLO network provided in the embodiments of the present invention is as follows: Figure 1 As shown, the method includes: Step 1: Obtain the dataset of bottle cap sealing defects, resulting in the training dataset, validation dataset, and test dataset.
[0026] In this embodiment of the invention, step 1 includes: After acquiring images of bottle cap packaging defects, preprocessing and labeling them, the processed image dataset is divided into training, validation and test datasets in a 7:2:1 ratio. After appropriate data augmentation, the datasets are stored in the specified paths, and the corresponding paths of the training, validation and test datasets are added to the model's YAML configuration file.
[0027] In this embodiment of the invention, the bottle cap sealing defect categories include bottle cap breakage, bottle cap deformation, bottle cap edge defects, bottle cap twisting, bottle cap breakage, and abnormal coding, etc., and their location distribution characteristics and size characteristics, such as... Figure 2 As shown in (a) and (b) in the figure. After unifying the public bottle cap packaging defect images and the self-built bottle cap packaging defect images to 640×640, the training set was preprocessed by translation, scaling, cropping, binarization and other methods. The LabelImg tool was used to label the location and category of defects in the images to generate corresponding YOLO format TXT label files.
[0028] Step 2: Improve the YOLO11n network model to obtain the MLT-YOLO network model.
[0029] In this embodiment of the invention, step 2 includes: The YOLO11n network model was improved by introducing wavelet convolution WTConv into its backbone network to construct the C3K2-WT feature extraction module; the neck architecture was redesigned using a multi-branch auxiliary feature pyramid network (MAFPN); the detector head with a large receptive field was removed, and a lightweight CGNL detector head was designed to obtain the MLT-YOLO network model.
[0030] In this embodiment of the invention, the MLT-YOLO network model is trained using data augmentation preprocessing and labeled images of bottle cap packaging defects. The MLT-YOLO network model is as follows: Figure 3As shown, the loss function of the MLT-YOLO network model is used and continuously optimized during training to improve the accuracy of bottle cap packaging defect detection. The end-to-end MLT-YOLO network model created using the YOLO framework integrates several key modules: the Conv module serves as the basic convolutional layer, responsible for extracting primary features from the image; the C3K2-WT module integrates wavelet convolution WTConv to enhance the network's information flow and feature representation capabilities, expanding the model's receptive field without adding additional parameters; the SPPF module processes inputs of different sizes through spatial pyramid pooling to extract multi-scale features; and the C2PSA module introduces a spatial attention mechanism to focus on key target regions in the image, suppressing irrelevant background information and improving the detection accuracy of small targets, while maintaining performance and reducing the number of parameters. The neck architecture is redesigned using the multi-branch auxiliary feature pyramid network MAFPN to retain as much shallow information as possible. Detection heads with large receptive fields are removed, and a compensatory group normalization lightweight detection head CGNL is proposed, improving the model's lightweightness while ensuring detection performance. The integration of these modules simplifies the network structure, enabling efficient deployment and operation on detection devices with limited computing power. This allows for real-time monitoring and identification of bottle cap packaging defects, thereby improving the accuracy and speed of defect detection.
[0031] In this embodiment of the invention, it includes: Step 21: In the backbone network of the YOLO11n network model, wavelet convolutions (WTConv) are used to replace the convolutional layers in the bottleneck structure Bottleneck, improving the C3K2 feature extraction module and constructing the C3K2-WT feature extraction module. WTConv is a unique convolutional layer that uses wavelet transform to expand the receptive field of the convolutional neural network (CNN) and enhance its response to low-frequency information, realizing the integration of image processing methods and convolutional layer design.
[0032] Step 22: The neck network structure is redesigned using the Multi-Branch Auxiliary Feature Pyramid Network (MAFPN), which effectively fuses multi-scale features and improves the performance of the target detection model. To better integrate the output features of the backbone network, a Superficial Assisted Fusion (SAF) module and an Advanced Assisted Fusion (AAF) module are introduced, which solves the problems of information loss and insufficient utilization in the feature fusion of traditional feature pyramid networks. Step 23: Remove the detection head for large targets and construct a compensatory group normalized lightweight detection head CGNL, whose expression is: ; in, Used to scale features and solve the problem of inconsistent target scales detected by each detection head; This represents a shared-group normalized convolution with a kernel size of 1×1; This represents a shared-group normalized convolution with a kernel size of 3×3. By using shared convolutions, the number of parameters can be significantly reduced, making the model lighter and easier to deploy on resource-constrained devices. This represents a 3×3 group of normalized convolutional kernels; such as Figure 4 As shown, and Represents the result after processing by the SAF module Feature layer and The final output of the feature layer contains feature information that is very useful for detecting small and medium-sized targets; A 1×1 convolutional kernel is used to fuse feature maps from different levels and map shared features to classification and regression branches to predict the target category and location; Complete Intersection over Union (CIOU) loss is used to measure the degree of matching between the predicted bounding box and the ground truth bounding box; Classification Loss (CLSLoss) loss is used to measure the difference between the class probability distribution predicted by the model and the ground truth label; Small Head and Medium Head represent the small target detection head and the medium target detection head, respectively.
[0033] In embodiments of the present invention, such as Figure 5 As shown, step 21 includes: The original convolution in the C3K2 feature extraction module is replaced with wavelet convolution WTConv to construct the C3K2-WT module; firstly, the input features are processed... Figure X A convolution operation is performed, and the output feature map is evenly split into two parts along the channel. The feature map of the main branch is subjected to multiple wavelet convolutions (WTConv) through multiple bottleneck structures (Bottleneck) to extract spatial features, and residual connections are used to prevent network degradation. The other part does not undergo a convolution operation and is concatenated with the output feature map of the main branch along the channel dimension. Finally, nonlinear features are extracted through a 3×3 convolutional layer. When C3K=True is set, C3K2-WT uses the C3K feature extraction module to replace the bottleneck structure (Bottleneck).
[0034] The process of WTConv wavelet convolution includes: a. Input feature map Perform wavelet transform to decompose it into sub-graphs of different frequencies. For the low-frequency component of X, These represent the horizontal, vertical, and diagonal high-frequency components of X, respectively; then, the low-frequency components are recursively decomposed, with the following expression: ; Where i is 1, Representing input features Figure X ; b. Utilizing the properties of wavelet transform, a small-kernel convolution operation is performed on the sub-image in the wavelet domain to achieve coverage of a large receptive field with a small convolution kernel. The expression is as follows: ; in, This represents the weight tensor of a 3×3 depth convolution kernel; This represents the output subband after convolution; c. Reconstruct the convolved sub-image back to the original space using inverse wavelet transform to obtain the final output feature map Y, whose expression is: ; in, This represents the inverse wavelet transform.
[0035] In embodiments of the present invention, such as Figure 6a and Figure 6b As shown, step 22 includes: d. Reconstruct the neck network structure using the Multi-Branch Auxiliary Feature Pyramid Network (MAFPN). In the shallow layers of the neck network, a shallow auxiliary fusion (SAF) module is used for feature fusion. The SAF module effectively preserves shallow layer information, which is crucial for detecting encapsulation defects. Furthermore, it combines with features extracted from deeper layers to provide richer feature representations for subsequent layers. The implementation steps are as follows: d1. Baseline Feature Map Localization: Feature maps output by the backbone network. It serves as a benchmark for resolution matching, used to unify the spatial dimensions of feature maps at different levels; d2. Shallow Feature Map Downsampling: This involves downsampling high-resolution feature maps from shallow layers. Perform a 3×3 downsampling convolution operation with a batch normalization layer to match the resolution of the baseline feature map, promoting cross-level feature alignment, especially if... This step is not performed for the shallowest level feature map. d3. Deep Feature Map Upsampling (Up): Upsampling of low-resolution feature maps The result of performing SAF module operations ,Will Perform nearest neighbor interpolation upsampling to match the resolution of the baseline feature map, especially if... This step is not performed for the deepest level feature map. d4. Channel Control: Adjusting the channel dimension after downsampling using a 1×1 convolution. The number of channels (C) is adjusted to , Half the number of channels (2C) is used to balance the preservation of shallow information with the stability of deep feature learning. This preserves key shallow details while avoiding their excessive influence on the representation of deep features, thus ensuring the stability of subsequent learning. d5. Feature Map Concat: Feature maps of different levels with matching resolutions and the same number of channels are concatified to generate feature maps containing multi-scale information. ; d6. Let n = n+1 or n = n-1, and repeat d1 to d5 to generate sequentially. , .
[0036] e. In the deep layers of the neck network, use the Advanced Auxiliary Fusion (AAF) module for feature fusion. Remove the AAF module that is associated with the large target detection head and outputs low-resolution feature maps. Since bottle cap encapsulation defects are mostly small targets, shallow high-resolution features are more critical for small target detection. Removing this module allows the model to concentrate computational resources when extracting small target features, speeding up the detection process. At the same time, it reduces the interference of deep semantic features of large targets on shallow detail features of small targets, improving the accuracy of small target detection. The implementation steps are as follows: e1. Baseline Feature Map Localization: Based on the feature map As a benchmark, it is used to unify the spatial dimensions of feature maps at different levels; e2. Shallow Feature Map Downsampling: This involves downsampling the output of the SAF module. The feature maps are subjected to a 3×3 downsampling convolution operation with batch normalization, and the output of the AAF module is processed. The feature maps undergo the same downsampling operation to match the resolution of the baseline feature map, in particular, if This step is not performed for the shallowest level feature map. e3. Deep Feature Map Upsampling (Up): Upsampling the low-resolution feature map output by the SAF module. Nearest neighbor interpolation upsampling is used to match the resolution of the baseline feature map, especially if... This step is not performed for the deepest level feature map. e4. Channel Control: Use 1×1 convolution to adjust the number of channels in the downsampled shallow feature map and the upsampled deep feature map to ensure that the number of channels in different layers of feature maps is consistent during the splicing operation, so that the model can obtain diversified outputs. e5. Feature Map Concat: This function fuses feature maps from different levels that have matching resolutions and the same number of channels through a concat operation, generating a feature map that contains multi-scale semantic information. ; e6. Let n = n-1 or n = n+1, and repeat e1 to e5 to generate the following values in sequence. , .
[0037] Step 3: Train the MLT-YOLO network model using the training dataset and use the validation dataset to guide parameter updates to obtain the optimal weight file.
[0038] In this embodiment of the invention, step 3 includes: Configure the model training environment, read the training and validation datasets via YAML files, train the MLT-YOLO network model, continuously optimize the loss function of the MLT-YOLO network model during training until training converges, and use the validation dataset to guide parameter updates to obtain the optimal weight file.
[0039] In this embodiment of the invention, configuring the model training environment includes installing relevant software and libraries, setting hardware parameter configurations, and ensuring all dependencies are configured correctly. For example, torchvision is used for image manipulation and must be compatible with the PyTorch version; numpy is used for efficient numerical computation; opencv-python is used for image processing; matplotlib is used for plotting and displaying images; and Pillow is an image processing library, etc.
[0040] Step 4: Call the optimal weight file and evaluate the MLT-YOLO network model using the test dataset to obtain the evaluation results.
[0041] In this embodiment of the invention, the evaluation includes visual analysis, detection accuracy evaluation, detection speed evaluation, and network complexity evaluation.
[0042] In this embodiment of the invention, step 4 includes: After configuring the data path, setting preset parameters (training rounds, batches, and defect categories, etc.), logging and monitoring, backup and version control, and security and permissions, the test dataset is read to evaluate the MLT-YOLO network model. In terms of detection accuracy, the mean accuracy (mAP) is used to evaluate the network model's detection performance on the augmented dataset. In terms of detection speed, the number of defect image frames per second (FPS) is used as the evaluation standard. In terms of network complexity, the number of network parameters (Params), floating-point operations (FLOPS), and model size are used to measure the network's lightweight nature.
[0043] The formula for the mean accuracy mAP is: ; Specific assessment methods include: I. Under the same training conditions and data, MLT-YOLO was compared with YOLOv5n, YOLO11n, YOLOv5s, YOLOv7-tiny, YOLOv7, YOLOv8n, YOLO12n and RT-DETR. The experimental results are shown in Table 1.
[0044] Table 1 Comparison of experimental results ; Comparing the experimental results of various object detection algorithms in the table, MLT-YOLO demonstrates a significant advantage in detection accuracy. In terms of average accuracy... In terms of metrics, MLT-YOLO achieves an accuracy of 0.836, a 1.6% improvement over the benchmark model YOLO11n, and higher than most models such as YOLOv5n (0.821) and YOLOv5s (0.83), only slightly higher than RT-DETR-l (0.833), demonstrating high detection accuracy. Its floating-point operations (FLOPS) are 5.7G, far lower than YOLOv5s (23.8G), YOLOv7 (105.2G), and the transformer-based RT-DETR-l (108.1), resulting in minimal computation and significantly reduced computational costs. The model size is only 4.2MB, the smallest among all models, facilitating model storage and deployment. With an FPS of 10⁹, its detection speed is fast, meeting the real-time requirements of industrial production environments. The number of parameters is 2.04 × 10⁹. 6 Similar to YOLOv5n but at a lower level, the MLT-YOLO network model exhibits low complexity. Experimental results demonstrate that the MLT-YOLO network model achieves a good balance in terms of accuracy, computational cost, model size, detection speed, and parameter count, while possessing higher resource utilization efficiency and deployment flexibility.
[0045] II. Under the same training conditions and data, plot the Precision, Recall, and Equation of MLT-YOLO compared to YOLOv5s, YOLOv8n, and YOLO11n network models during training. and The change curves of the four major indicators, such as Figure 7 As shown in (a), (b), (c) and (d), the MLT-YOLO network model performs better, with a more significant rise in the index curve and a higher stable value in the later stage.
[0046] III. In order to accurately evaluate the effectiveness of each improvement, under the same training conditions and data, ablation operations were performed on each improved module. The experimental results are shown in Table 2.
[0047] Table 2 Ablation Experiment Results ; As shown in Table 2, when only the C3K2-WT feature extraction module is introduced, the average precision mAP@0.5 increases from 0.820 to 0.825, while reducing floating-point operations (FLOPS) (from 6.3G to 6.1G) and parameter count (from...). Reduce to At the same time, it improves detection accuracy, and, for example... Figure 8 As shown in (a) and (b), the feature maps output by the C3K2-WT backbone network have a larger receptive field; the MAFPN feature pyramid network, applied to the existing C3K2-WT, achieves a higher average precision. The accuracy was further improved to 0.831, showing a significant increase; finally, the CGNL detection head was used to replace the original detection head, and the average accuracy was improved. Improved by 0.5%, floating-point operations (FLOPS) decreased to 5.7G, and the number of parameters (Params) was reduced to [missing value]. The FPS was increased to 109, achieving comprehensive optimization in accuracy, computational load, parameter count, and detection speed. This demonstrates that C3K2-WT, MAFPN, and CGNL played positive roles in accuracy improvement, structural optimization, and overall performance enhancement, respectively, synergistically contributing to a good balance between detection accuracy, computational efficiency, and detection speed in the MLT-YOLO network model.
[0048] IV. The HiResCAM heatmap generation algorithm was used to perform a heatmap visualization comparison of MLT-YOLO and YOLO11n, such as... Figure 9As shown in (a), (b), (c), and (d), MLT-YOLO clearly highlights key areas of the target, enabling precise feature extraction. Simultaneously, the high-response areas in the MLT-YOLO heatmap fit closely with the bounding box, indicating higher localization accuracy. The darker background areas in the MLT-YOLO heatmap demonstrate excellent background interference suppression capabilities, effectively preventing false detections due to background factors. Experimental results show that MLT-YOLO outperforms YOLO11n in target focus, localization, and anti-interference performance. In this embodiment of the invention, the loss function of the MLT-YOLO network model is continuously optimized during training to improve the accuracy of bottle cap packaging defect detection. The end-to-end MLT-YOLO network model created through the YOLO framework has a simplified network structure, which enables it to be better deployed and run on detection devices with limited computing power, thereby enabling real-time and efficient monitoring and identification of bottle cap packaging defects, and improving the accuracy and speed of defect detection.
[0049] This invention aims to improve the accuracy and efficiency of bottle cap packaging defect detection. To enhance the network's ability to identify important features, this invention introduces wavelet convolution WTConv into the backbone network of the YOLO11n network model, improving feature extraction capabilities while reducing computational load. Secondly, the neck architecture is redesigned using the multi-branch auxiliary feature pyramid network MAFPN to retain more shallow information. Finally, the detection head with a large receptive field is removed, and a lightweight detection head CGNL is proposed to achieve a lightweight head structure. This invention not only improves detection accuracy but also reduces computational burden, making the model suitable for running on resource-constrained devices. Compared with other algorithms, this invention increases detection accuracy and optimizes the efficiency and precision of the entire detection process.
[0050] This invention introduces wavelet convolution WTConv into the backbone of the YOLO11n network model to obtain the C3K2-WT feature extraction module, which can expand the receptive field of the model and improve the accuracy of packaging defect localization without increasing the amount of additional computation. The neck architecture is redesigned using the multi-branch auxiliary feature pyramid MAFPN to retain more shallow information, which helps to enhance the ability to capture small target defects. Finally, the detection head with a large receptive field is removed, and a lightweight detection head CGNL is proposed to achieve a lightweight head structure. Compared with the original model, the improved model reduces the floating-point operation by 0.6G, the model size is 4.2MB, the number of parameters used is 79% of the original model, the average accuracy of detection is improved by 1.6 percentage points, and the image frame rate (FPS) reaches 109. This method accurately distinguishes packaging defect categories and locates defect positions while having lower computational overhead and a smaller model size, making it more suitable for deployment at the edge and maintaining high real-time performance and accuracy in complex backgrounds and production environments.
[0051] The technical solution provided by this invention includes a method that involves acquiring a dataset of bottle cap packaging defects to obtain a training dataset, a validation dataset, and a test dataset; improving the YOLO11n network model to obtain an MLT-YOLO network model; training the MLT-YOLO network model using the training dataset and using the validation dataset to guide parameter updates to obtain an optimal weight file; calling the optimal weight file and evaluating the MLT-YOLO network model using the test dataset to obtain evaluation results. This method maintains high accuracy while effectively distinguishing actual defects from background noise in complex backgrounds and production environments, accurately identifying and locating minor flaws in bottle cap packaging.
[0052] The various steps in the embodiments of the present invention can be performed by an electronic device. This electronic device includes, but is not limited to, tablet computers, portable PCs, and desktop computers.
[0053] This invention provides a computer-readable storage medium including a stored program, wherein, when the program is running, the computer-readable storage medium controls the execution of the above-described embodiment of the bottle cap packaging defect detection method based on the MLT-YOLO network.
[0054] Figure 10 A schematic diagram of an electronic device provided in an embodiment of the present invention, such as... Figure 10 As shown, the electronic device 21 includes a processor 211, a memory 212, and a computer program 213 stored in the memory 212 and executable on the processor 211. When the computer program 213 is executed by the processor 211, it implements the bottle cap packaging defect detection method based on the MLT-YOLO network in the embodiment. To avoid repetition, it will not be described in detail here.
[0055] Electronic device 21 includes, but is not limited to, processor 211 and memory 212. Those skilled in the art will understand that... Figure 10 This is merely an example of electronic device 21 and does not constitute a limitation on electronic device 21. It may include more or fewer components than shown, or combine certain components, or different components. For example, electronic device may also include input / output devices, network access devices, buses, etc.
[0056] The processor 211 may be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.
[0057] The memory 212 can be an internal storage unit of the electronic device 21, such as a hard disk or RAM of the electronic device 21. The memory 212 can also be an external storage device of the electronic device 21, such as a plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, or FlashCard equipped on the electronic device 21. Furthermore, the memory 212 can include both internal and external storage units of the electronic device 21. The memory 212 is used to store computer programs and other programs and data required by network devices. The memory 212 can also be used to temporarily store data that has been output or will be output.
[0058] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0059] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for detecting bottle cap packaging defects based on MLT-YOLO networks, characterized in that, The method includes: Step 1: Obtain the dataset of bottle cap sealing defects, and obtain the training dataset, validation dataset, and test dataset; Step 2: Improve the YOLO11n network model to obtain the MLT-YOLO network model; Step 3: Train the MLT-YOLO network model using the training dataset and use the validation dataset to guide parameter updates to obtain the optimal weight file; Step 4: Call the optimal weight file and evaluate the MLT-YOLO network model using the test dataset to obtain the evaluation results.
2. The method according to claim 1, characterized in that, Step 1 includes: After acquiring images of bottle cap packaging defects, preprocessing and labeling them, the processed image dataset is divided into training, validation and test datasets in a 7:2:1 ratio. After appropriate data augmentation, the datasets are stored in the specified paths, and the corresponding paths of the training, validation and test datasets are added to the model's YAML configuration file.
3. The method according to claim 1, characterized in that, Step 2 includes: The YOLO11n network model was improved by introducing wavelet convolution WTConv into its backbone network to construct the C3K2-WT feature extraction module; the neck architecture was redesigned using the multi-branch auxiliary feature pyramid network MAFPN; the detector head with a large receptive field was removed and a lightweight detector head CGNL was designed to obtain the MLT-YOLO network model.
4. The method according to claim 3, characterized in that, include: Step 21: In the backbone network of the YOLO11n network model, wavelet convolution WTConv is used to replace the convolutional layer in the bottleneck structure Bottleneck, and the C3K2 feature extraction module is improved to construct the C3K2-WT feature extraction module. Step 22: Redesign the neck network structure using the Multi-Branch Auxiliary Feature Pyramid Network (MAFPN); to integrate the output features of the backbone network, introduce the Shallow Auxiliary Fusion (SAF) module and the High-Level Auxiliary Fusion (AAF) module; Step 23: Remove the detection head for large targets and construct a compensatory group normalized lightweight detection head CGNL, whose expression is: ; in, Used for scaling features; This represents a shared-group normalized convolution with a kernel size of 1×1. This represents a shared-group normalized convolution with a kernel size of 3×3; This indicates a 3×3 convolution kernel.
5. The method according to claim 4, characterized in that, Step 21 includes: The C3K2-WT module is constructed by replacing the original convolution in the C3K2 feature extraction module with wavelet convolution WTConv. First, the input feature map... A convolution operation is performed, and the output feature map is evenly divided into two parts in the channel. The feature map of the main branch is subjected to multiple wavelet convolutions WTConv through multiple bottleneck structures to extract spatial features, and residual connections are used to prevent network degradation. The other part does not perform a convolution operation and is concatenated with the output feature map of the main branch in the channel dimension. Finally, nonlinear features are extracted through a convolutional layer with a kernel size of 3×3. The process of WTConv wavelet convolution includes: a. Input feature map Perform wavelet transform to decompose it into sub-graphs of different frequencies. For the low-frequency component of X, These represent the horizontal, vertical, and diagonal high-frequency components of X, respectively; then, the low-frequency components are recursively decomposed, with the following expression: ; Where i is 1, Represents the input feature map X; b. Utilizing the properties of wavelet transform, a small-kernel convolution operation is performed on the sub-image in the wavelet domain to achieve coverage of a large receptive field with a small convolution kernel. The expression is as follows: ; in, This represents the weight tensor of a 3×3 depth convolution kernel; This represents the output subband after convolution; c. Reconstruct the convolved sub-image back to the original space using inverse wavelet transform to obtain the final output feature map Y, whose expression is: ; in, This represents the inverse wavelet transform.
6. The method according to claim 4, characterized in that, Step 22 includes: d. Reconstruct the neck network structure using the Multi-Branch Auxiliary Feature Pyramid Network (MAFPN). Perform feature fusion using a shallow-layer auxiliary fusion (SAF) module in the shallow layers of the neck network. The implementation steps are as follows: d1. Baseline Feature Map Localization: Feature maps output by the backbone network. It serves as a benchmark for resolution matching, used to unify the spatial dimensions of feature maps at different levels; d2. Shallow Feature Map Downsampling: This involves downsampling high-resolution feature maps from shallow layers. Perform a 3×3 downsampling convolution operation with a batch normalization layer to match the resolution of the baseline feature map; d3. Deep Feature Map Upsampling (Up): Upsampling of low-resolution feature maps The result of performing SAF module operations ,Will Perform nearest neighbor interpolation upsampling to match the resolution of the baseline feature map; d4. Channel Control: Adjusting the channel dimension after downsampling using a 1×1 convolution. The number of channels was adjusted to , Half the number of channels, to balance the preservation of shallow information with the stability of deep feature learning; d5. Feature Map Concat: This step fuses feature maps from different levels with matched resolutions and adjusted channel counts to generate a feature map containing multi-scale information. ; d6. Let n = n+1 or n = n-1, and repeat d1 to d5 to generate sequentially. , . e. In the deep layers of the neck network, use the Advanced Auxiliary Fusion (AAF) module to perform feature fusion, and remove AAF modules that are associated with large target detection heads and output low-resolution feature maps. The implementation steps are as follows: e1. Baseline Feature Map Localization: Feature map output by the SAF module As a benchmark, it is used to unify the spatial dimensions of feature maps at different levels; e2. Shallow Feature Map Downsampling: This involves downsampling the output of the SAF module. The feature maps are subjected to a 3×3 downsampling convolution operation with batch normalization, and the output of the AAF module is processed. The feature maps undergo the same downsampling operation to match the resolution of the baseline feature map; e3. Deep Feature Map Upsampling (Up): Upsampling the low-resolution feature map output by the SAF module. Nearest neighbor interpolation upsampling is used to match the resolution of the baseline feature map; e4. Channel Control: Use 1×1 convolution to adjust the number of channels in the downsampled shallow feature map and the upsampled deep feature map to ensure that the number of channels in different layers of feature maps is consistent during the stitching operation. e5. Feature Map Concat: This function fuses feature maps from different levels that have matching resolutions and the same number of channels through a concat operation, generating a feature map that contains multi-scale semantic information. ; e6. Let n = n-1 or n = n+1, and repeat e1 to e5 to generate the following values in sequence. , .
7. The method according to claim 1, characterized in that, Step 3 includes: Configure the model training environment, read the training and validation datasets via YAML files, train the MLT-YOLO network model, optimize the loss function of the MLT-YOLO network model during training until training converges, and use the validation dataset to guide parameter updates to obtain the optimal weight file.
8. The method according to claim 1, characterized in that, Step 4 includes: The MLT-YOLO network model was evaluated using the test dataset. In terms of detection accuracy, the mean accuracy (mAP) was used to evaluate the network model's detection performance on the augmented dataset. In terms of detection speed, the number of defective image frames per second (FPS) was used as the evaluation metric. In terms of network complexity, the number of network parameters (Params), floating-point operations (FLOPS), and model size were used to measure the network's lightweight nature.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein, when the program is executed, it controls the device on which the computer-readable storage medium is located to perform the bottle cap packaging defect detection method based on the MLT-YOLO network as described in any one of claims 1 to 8.
10. An electronic device, characterized in that, include: One or more processors; Memory; And one or more computer programs, wherein the one or more computer programs are stored in the memory, the one or more computer programs including instructions that, when executed by the device, cause the device to perform the bottle cap packaging defect detection method based on the MLT-YOLO network according to any one of claims 1 to 8.