A method for detecting minute defects in cigarette boxes based on CDM-YOLOv8 network

By enhancing feature extraction, dynamic multi-scale fusion, and optimizing frequency domain downsampling through the CDM-YOLOv8 network, the problems of missed detection and false detection in the detection of minor defects in cigarette boxes are solved, achieving efficient and accurate defect identification and localization, and meeting the real-time requirements of industrial production.

CN122090141APending Publication Date: 2026-05-26CHINA TOBACCO ANHUI IND CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHINA TOBACCO ANHUI IND CO LTD
Filing Date
2026-02-05
Publication Date
2026-05-26

AI Technical Summary

Technical Problem

Existing methods for detecting defects in cigarette boxes are difficult to effectively identify small, irregularly shaped defects in complex environments, and it is difficult to balance detection accuracy and efficiency, which can easily lead to missed detections and false detections, and cannot meet the real-time requirements of industrial production.

Method used

A detection method based on the CDM-YOLOv8 network is adopted. Through a feature extraction enhancement module, a dynamic multi-scale fusion module, a frequency domain downsampling optimization module, and a YOLOv8 detection head, combined with multi-branch feature extraction, deformable convolution, and frequency domain banding processing, the ability to identify small defects is enhanced and the false negative rate is reduced.

Benefits of technology

It improves the accuracy and stability of detecting minor defects in cigarette boxes, reduces the false negative rate, meets the real-time requirements of industrial production lines, reduces the cost of manual re-inspection, and improves production efficiency and product consistency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122090141A_ABST
    Figure CN122090141A_ABST
Patent Text Reader

Abstract

This invention discloses a method for detecting minute defects in cigarette boxes based on a CDM-YOLOv8 network, comprising: Step 1, acquiring an image of the cigarette box surface and constructing a defect detection dataset; Step 2, performing feature extraction enhancement on the input image, extracting defect-related features through multi-branch convolution, deformable convolution, and spatial attention mechanisms; Step 3, dynamically fusing features at different scales, and performing frequency domain banding processing on the fused features during the downsampling stage, employing a differentiated downsampling strategy to preserve defect edge and texture information; Step 4, outputting the category and location information of the defects based on the detection head. This invention solves the problems of easy loss of minute defects in cigarette boxes during downsampling and easy missed detection in complex backgrounds. By enhancing feature representation capabilities and preserving high-frequency defect information while ensuring computational efficiency, it improves the detection accuracy of minute defects in cigarette boxes and reduces the missed detection rate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer vision and industrial inspection technology, specifically a method for detecting minute defects in cigarette boxes based on the CDM-YOLOv8 network. Background Technology

[0002] With the continuous improvement of industrial automation, machine vision-based appearance defect detection technology has been widely applied in tobacco products, food packaging, printed materials, and electronic products to replace manual inspection and improve inspection efficiency and consistency. Cigarette boxes, as typical printed packaging products, directly affect product appearance and market image due to their surface quality; therefore, rapid and accurate detection of surface defects in cigarette boxes is of great significance.

[0003] Existing methods for detecting defects in cigarette packs mainly include detection methods based on traditional image processing and target detection methods based on deep learning. Traditional image processing methods typically rely on manually designed edge, texture, or color features, which are sensitive to changes in lighting and background noise, making them difficult to adapt to complex and ever-changing real-world production environments. In recent years, deep learning-based detection methods have been increasingly applied to cigarette pack defect detection due to their strong feature representation capabilities. For example, patent CN109969495A is used to accurately detect defects such as missing label paper or skewed cigarette packs. Patent CN119228779A involves acquiring images of the cigarette pack's appearance, performing image segmentation, grayscale processing, denoising, image enhancement, and data standardization, then using strong and weak data enhancement and feature extractors for feature extraction. Finally, it optimizes the detection accuracy and robustness of the defect detection model by calculating the similarity between positive and negative samples in the feature space and the total loss function.

[0004] However, in actual industrial production, surface defects on cigarette boxes are typically small in size, irregular in shape, and easily blend into the background texture. Existing detection methods are prone to weakening or even losing defect features during multi-scale feature fusion and downsampling, leading to missed detections. Furthermore, industrial inspection demands high real-time performance. Some methods improve accuracy by stacking complex network structures, but this increases computational load, making it difficult to balance detection accuracy and efficiency. Therefore, how to improve the detection accuracy of minute defects in cigarette boxes while ensuring detection efficiency remains a pressing problem to be solved in current technologies. Summary of the Invention

[0005] This invention addresses the shortcomings of existing technologies by proposing a method for detecting minute defects in cigarette boxes based on a CDM-YOLOv8 network. The aim is to achieve stable identification and accurate location of minute defects on the surface of cigarette boxes under complex industrial production line conditions, including fluctuating lighting, small defect size, and irregular shapes. This reduces missed and false detections, and maintains consistency and reliability of detection results while meeting production cycle requirements. Ultimately, this enhances the online inspection capability of cigarette box appearance quality, providing effective support for production process quality control, anomaly tracing, and rejection of non-conforming products. It also reduces manual re-inspection costs and quality risks, improving production efficiency and product consistency.

[0006] To achieve the above-mentioned objectives, the present invention adopts the following technical solution: The present invention provides a method for detecting minute defects in cigarette boxes based on a CDM-YOLOv8 network, characterized by the following steps: Step 1: Collect images of the cigarette box surface from the industrial production line, perform preprocessing and annotation, and form a sample set containing image and defect annotation pairs. ;in, This represents the i-th cigarette box surface sample after preprocessing. express The actual annotation information, among which, , , These represent the length, height, and number of channels of the sample on the surface of the cigarette box, respectively. ; This represents the total number of samples on the surface of the cigarette box; Step 2: Construct a cigarette box defect detection network based on the CDM-YOLOv8 network, including: a feature extraction enhancement module, a dynamic multi-scale fusion module, a frequency domain downsampling optimization module, and a YOLOv8 detection head, and then... The process is performed, and the corresponding defect detection results are obtained. ; Step 3: Based on and Constructing the total loss function of the cigarette box defect detection network ; Step 4: Iteratively train the cigarette box defect detection network using the SGD optimizer and calculate the total loss function. Adjust the network parameters until the total loss function is achieved. The process continues until convergence, thus obtaining a trained cigarette box defect detection model, which is used to locate and classify defects in cigarette box surface images.

[0007] The method for detecting minute defects in cigarette boxes based on CDM-YOLOv8 networks described in this invention is characterized in that step 1 includes the following steps: Step 1.1: Use an industrial camera to capture the raw cigarette box image stream and preprocess it to obtain a preprocessed set of cigarette box surface samples. ; Step 1.2: Labeling The defect box and category are obtained. Authentic labeling information ,in, express The size of the bounding box containing the j-th defect, and , express The center of the bounding box containing the j-th defect. , They represent The width and height of the bounding box containing the j-th defect; express The true category of the j-th defect, and , This represents the total number of defect categories. express The number of defects in the sample.

[0008] Furthermore, step 2 includes the following steps: Step 2.1: The feature extraction enhancement module... The process is performed to obtain the i-th multi-scale enhanced cigarette box defect feature. ,in, express The Middle Enhanced cigarette box defect characteristics at various scales; Indicates the number of scales; Step 2.2: The dynamic multi-scale feature fusion module... Dynamic weighted fusion is performed to obtain the fusion feature of the i-th cigarette box defect. ; Step 2.3: Frequency domain downsampling optimization module Frequency domain transformation and downsampling are performed to obtain the i-th downsampling optimized feature. ; Step 2.4: The YOLOv8 detection head adopts a decoupled structure for... Model the location and category information of defects on the cigarette box surface, and generate defect location and category prediction results. .

[0009] Further steps include the following: Step 2.1.1: Use equation (1) to... Perform channel transformation to obtain the basic features of the i-th cigarette box. ,in, This indicates the number of channels in the feature map after channel transformation; (1) In equation (1), The convolution kernel parameters are represented as 1×1 convolutions. This is the bias for the convolution operation. For convolution operations, Indicates the SiLU activation function; Step 2.1.2: Use equations (2) and (3) to... Multi-branch directional feature extraction is performed to obtain the fused feature of the i-th multi-scale / multi-directional cigarette box defect texture and edge information. ; (2) (3) In equations (2) and (3), Indicates the first The receptive field size or orientation of the convolutional kernel used in each convolutional branch, This indicates a splicing operation based on the channel dimension. Represented as convolution kernel parameters; Step 2.1.3: The deformable convolution module utilizes equation (4) to... Perform spatial adaptive alignment processing to obtain the i-th aligned cigarette box defect feature map. ; (4) In equation (4), Indicates two-dimensional coordinate position. Indicates the index of the sampling point. Indicates the first The offset to be learned for each sampling point express The corresponding number The weight of each sampling point A set representing the sampling point indices; express Medium two-dimensional coordinate position Defect characteristic value at the location, express Medium two-dimensional coordinate position Local eigenvalues ​​at; Step 2.1.3: Use equations (5) and (6) to... Spatial self-attention modeling is performed to obtain the i-th attention-enhanced cigarette box defect feature. ; (5) (6) In equations (5) and (6), This represents the i-th query matrix. Represents the i-th key matrix. Represents the i-th value matrix; These represent the linear mapping weights of the query, key, and value, respectively. Matrix transpose This represents the feature dimension corresponding to the attention scaling factor. This represents the distribution function that normalizes similarity to weights. This represents the attention weight matrix of the i-th element; Step 2.1.4: Use equation (7) to... Perform residual normalization processing and output the i-th multi-scale enhanced cigarette box defect feature. : (7) In equation (7), This indicates a normalization operation. This indicates a residual connection.

[0010] Furthermore, step 2.2 includes the following steps: Step 2.2.1: From Two scale features are selected as the i-th shallow layer features. With the i-th deep feature ,in, This indicates the number of channels corresponding to the shallow features at the selected scale. This indicates the number of channels corresponding to the deep features at the selected scale. Indicates the scaling ratio, and ; Using equations (8) and (9) and Scale alignment and channel unification are performed to obtain the i-th aligned shallow feature. Deep features aligned with the i-th feature ,in, This represents the number of channels for the scale-aligned feature. (8) (9) In equations (8) and (9), Up(·) represents an upsampling operation using interpolation or deconvolution. , These are the two parameters of the channel mapping convolution kernel; The SiLU activation function; This represents the convolution operation; Step 2.2.2: Use equations (10) and (11) to... Perform channel attention modeling to generate the i-th shallow channel attention weight. : (10) (11) In equations (10) and (11), GAP represents the global average pooling operation. , There are two weight parameters; Represents the ReLU activation function; This represents the Sigmoid activation function; This represents the description vector of the i-th shallow channel; Step 2.2.3: Follow the process in Step 2.2.2. The processing yields the attention weights for the i-th deep channel. ; Step 2.2.4: Use equation (12) to respectively and By performing channel-by-channel weighted fusion, the shallow fusion feature of the i-th weighted layer is obtained. and the i-th weighted deep fusion feature : (12) In equation (12), ⊙ represents element-wise multiplication; Step 2.2.5: Use equation (13) to... and Channel compression and feature fusion are performed to obtain the i-th cigarette box defect fusion feature that simultaneously retains shallow detail information and deep semantic information. ,in, Number of channels for integrating defect features of cigarette boxes: (13) In equation (13), This indicates a splicing operation. This represents another convolution kernel parameter.

[0011] Furthermore, step 2.3 includes the following steps: Step 2.3.1: For Performing a Discrete Fourier Transform, the resulting frequency domain features are divided into the i-th low-frequency sub-band features containing global structural information according to the frequency range. The i-th mid-frequency sub-band feature containing regional texture information The i-th high-frequency sub-band feature containing edge and minute defect information ; Step 2.3.2: For Perform strong downsampling to obtain the low-frequency domain features after the i-th downsampling. ; right Perform appropriate downsampling to obtain the mid-frequency domain features after the i-th downsampling. ; right We obtain the high-frequency domain features after the i-th downsampling by using weak downsampling or keeping the resolution constant. ; Step 2.3.3: Use equation (14) to... , and Frequency domain reconstruction is performed to restore the spatial domain and obtain the reconstructed features of the i-th cigarette box defect. : (14) In equation (14) This represents the inverse discrete Fourier transform operation; Indicates a splicing operation; Step 2.3.4: Use equation (15) to... Channel fusion and compression are performed to obtain the i-th downsampling optimized feature. ,in, and This represents the spatial dimensions after downsampling. The number of channels represents the downsampling optimized feature: (15) In equation (15): To fuse convolution kernel parameters; This is the SiLU activation function.

[0012] Furthermore, step 2.4 includes the following steps: Step 2.4.1: Use equation (16) to... Perform convolution processing to obtain the i-th detection feature. : (16) In equation (16): W_det is the convolution kernel parameter of the detection head; The SiLU activation function; Step 2.4.2: Classification branching using equation (17) For each candidate location, the defect category is predicted to obtain the probability distribution of the i-th category. : (17) In equation (17): The convolution kernel parameters for the classification branch; Step 2.4.3: Regression branch using equation (18) The defect bounding box parameters at each candidate location are predicted to obtain the predicted defect bounding box of the i-th location, which contains information about the defect location and size. : (18) In equation (18): The convolution kernel parameters for the regression branch; Step 2.4.4: According to and Decode and filter defects at each candidate location, and output... Defect detection results ;in: for The bounding box parameters of the m-th defect include the center position, width, and height; for The predicted category of the m-th defect; for The confidence score of the m-th defect; for The number of defects detected.

[0013] The present invention provides an electronic device, including a memory and a processor, characterized in that the memory is used to store a program that supports the processor in executing the cigarette box micro-defect detection method based on the CDM-YOLOv8 network, and the processor is configured to execute the program stored in the memory.

[0014] The present invention discloses a computer-readable storage medium storing a computer program, characterized in that the computer program, when executed by a processor, performs the steps of the method for detecting minute defects in cigarette boxes based on a CDM-YOLOv8 network.

[0015] Compared with the prior art, the beneficial effects of the present invention are as follows: 1. This invention introduces multi-branch feature extraction and deformable convolution enhancement processing in the feature extraction stage, so that the convolution sampling position can adaptively fit the geometric shape of the small defects in the cigarette box, enhance the feature response capability to slender, curved and irregular defects, thereby reducing the interference of complex background texture on defect detection and improving the detection rate of small defects.

[0016] 2. This invention dynamically weights and fuses shallow detail features and deep semantic features, ensuring that defect edge information is fully preserved while suppressing background redundancy information, so that multi-scale features maintain consistent semantic expression during the fusion process, thereby improving the stability and robustness of defect recognition in complex printing backgrounds.

[0017] 3. In the network downsampling stage, the present invention performs frequency domain banding processing on the fused features and adopts differentiated downsampling strategies for different frequency bands. While reducing feature resolution and computational load, it effectively preserves high-frequency information such as defect edges and textures, and avoids the removal of minor defects during the downsampling process, thereby significantly reducing the false negative rate and improving the defect localization accuracy.

[0018] 4. This invention optimizes the feature extraction and downsampling process while ensuring detection accuracy, enabling the detection method to achieve stable output while meeting the real-time requirements of industrial production lines. It provides a reliable technical means for online inspection of cigarette box appearance quality, reduces manual re-inspection costs, and improves production efficiency and product consistency. Attached Figure Description

[0019] Figure 1 This is a flowchart of the method of the present invention. Detailed Implementation

[0020] In this embodiment, a method for detecting minute defects in cigarette boxes based on a CDM-YOLOv8 network is described, such as... Figure 1 As shown, it includes the following steps: Step 1: Collect images of the cigarette box surface from the industrial production line, perform preprocessing and annotation, and form a sample set containing image and defect annotation pairs. This dataset is used for subsequent training and validation of CDM-YOLOv8 to determine the localization and classification parameters of minor defects in cigarette boxes. This represents the i-th cigarette box surface sample after preprocessing. express The actual annotation information, among which, , , These represent the length, height, and number of channels of the sample on the surface of the cigarette box, respectively. ; This represents the total number of samples on the surface of the cigarette box; Step 1.1: Use the raw cigarette box image stream acquired by the industrial camera and perform preprocessing such as size unification and normalization to obtain a preprocessed set of cigarette box surface samples. ; Step 1.2: Labeling The defect box and category are obtained. Authentic labeling information ,in, express The size of the bounding box containing the j-th defect, and , express The center of the bounding box containing the j-th defect. , They represent The width and height of the bounding box containing the j-th defect; express The true category of the j-th defect, and , This represents the total number of defect categories. express The number of defects in; Step 2: Construct a cigarette box defect detection network based on the CDM-YOLOv8 network, including: a feature extraction enhancement module (CT-MBDFE) for obtaining stronger defect texture / edge representations; a dynamic multi-scale fusion module (DFIU) for adaptive weighted fusion of features at different scales; a frequency domain downsampling optimization module (MultiBandReduce) for preserving high-frequency details during downsampling; and a YOLOv8 detection head for outputting defect boxes and class scores, thereby improving the detection accuracy and robustness of minor defects in cigarette boxes. This network... The process is performed, and the corresponding defect detection results are obtained. : Step 2.1: Feature Extraction Enhancement Module (CT-MBDFE) for... Channel transformation, multi-branch convolution feature extraction, deformable convolution enhancement, and spatial attention modeling are performed to enhance the surface defect-related features of the cigarette box, resulting in the i-th multi-scale enhanced cigarette box defect feature. ,in, express The Middle Enhanced cigarette box defect characteristics at various scales; Indicates the number of scales; Step 2.1.1: Use equation (1) to... Channel transformation is performed to map the input to a channel space suitable for subsequent multi-branch extraction, thereby enhancing the weak defect response and obtaining the i-th basic feature of the cigarette box. This provides a unified channel representation for subsequent multi-branch feature extraction, whereby... This represents the number of channels in the feature map after channel transformation. The channels of the input image are recombined through 1×1 convolution, so that the original RGB image is mapped to the preset feature channel space, thereby enhancing the response intensity of small defects in the feature map and suppressing interference information in the background area.

[0021] (1) In equation (1), The kernel parameters (channel recombination / alignment) are represented as 1×1 convolutions. This is the bias for the convolution operation. For convolution operations, Indicates the SiLU activation function; Step 2.1.2: The multi-branch structure includes multiple parallel convolutional branches. Different branches use convolutional kernels with different receptive field sizes or orientations to extract defect textures and edge information at different scales and in different directions, thereby utilizing equations (2) and (3) to... Multi-branch directional feature extraction is performed to enhance multi-scale / multi-directional texture, and the fused feature of the i-th multi-scale / multi-directional cigarette box defect texture and edge information is obtained. ; (2) (3) In equations (2) and (3), Indicates the first The receptive field size or orientation of the convolutional kernel used in each convolutional branch (different receptive fields / or orientations can be used). This indicates that the feature maps output by each branch are concatenated along the channel dimension to aggregate features from multiple branches. This represents the kernel parameters of a 1×1 convolution; 1×1 convolution is used to achieve channel number compression and multi-branch feature fusion.

[0022] Step 2.1.3: Since cigarette box defects typically exhibit elongated, curved, or blurred edges, directly performing spatial attention modeling on a regular sampling grid can easily lead to interference from the background region in the attention weight distribution, thereby weakening the response intensity of the defect region. Therefore, in the method of this invention, a deformable convolution module is used to... Spatial adaptive alignment is performed to make the features fit the irregular defect shape better, and then the i-th aligned cigarette box defect feature map is obtained using equation (4). ; (4) In equation (4), This represents the two-dimensional coordinate position of the output feature, indicating "the current output point to be calculated". This represents the index of the sampling point, used to traverse the sampling positions within the kernel. Indicates the first The learning offset of each sampling point is used to deviate the sampling point from the regular grid to fit the defect shape. express The corresponding number The weight of each sampling point The set representing the sampling point index (e.g.) Grid index); express Medium two-dimensional coordinate position Defect characteristic value at the location, express Medium two-dimensional coordinate position The local feature values ​​at the location; the deformable convolution module can adaptively adjust the sampling position according to the geometry of the defect, improving the ability to locate irregular and small defects.

[0023] Step 2.1.3: Use equations (5) and (6) to... Spatial self-attention modeling is performed to concentrate attention weights on the defect region, improving the overall response consistency of elongated or scattered defects, thereby reducing the probability of missing small defects, and obtaining the i-th attention-enhanced cigarette box defect feature. By using spatial self-attention to model long-distance dependencies, attention can be avoided from learning noise correlations on misaligned features, thereby enhancing the overall expressive power of slender or scattered defects.

[0024] (5) (6) In equations (5) and (6), Let be the i-th query matrix, representing the demand for other spatial location information based on the current location features. , Let be the i-th key matrix, representing the matching index of each spatial location feature. represents the i-th value matrix; represents the actual aggregateable feature content of each spatial location. By constructing query features, key features, and value features, the correlation between features at each location is calculated in the spatial dimension, and the features are weighted and fused according to the correlation weight, thereby enhancing the association between the defective region and its context. They respectively represent the use of Convolution implements a linear mapping weight between query, key, and value. When calculating attention weights, the feature map is unfolded in the spatial dimension and matrix operations are performed so that features at each spatial location can participate in global relevance modeling. Matrix transpose This is the transpose of the key matrix, used in conjunction with the query matrix. Perform inner product calculations to obtain the similarity between spatial locations; This represents the feature dimension (usually the channel dimension of each attention head) corresponding to the attention scaling factor, used to normalize the inner product result to stabilize training. This represents the distribution function of similarity normalized to weights, and ; Let be the i-th attention weight matrix, representing the correlation between positions; this self-attention processing can capture long-distance spatial dependencies, enabling scattered or elongated defects to form an overall response, enhancing the overall expressive ability of long strip-shaped and discretely distributed defects, avoiding missed detections caused by relying solely on local features, and improving detection robustness.

[0025] Step 2.1.4: Use equation (7) to... Perform residual normalization processing and output the i-th stable multi-scale enhanced cigarette box defect feature. : (7) In equation (7), This indicates a normalization operation. Residual connections are used to represent the connection. While preserving the original feature information, the residual structure can avoid the gradient vanishing problem during the training process of deep networks, improve the stability of feature representation, further enhance defect-related features, and improve the overall detection accuracy.

[0026] Step 2.2: The Dynamic Multi-Scale Feature Fusion Module (DFIU) from A set of shallow features and a set of deep features are selected. Through channel weight calculation and feature alignment, the shallow and deep features are dynamically weighted and fused to obtain the i-th cigarette box defect fusion feature. If more than two features are fused simultaneously, although the amount of information increases, the computational load will increase significantly and redundant channel responses will be introduced, which is detrimental to real-time industrial detection. Therefore, this embodiment uses dynamic weighted fusion of shallow and deep features to achieve a balance between detection accuracy and computational efficiency.

[0027] Step 2.2.1: From Two scale features are selected as the i-th shallow layer features. With the i-th deep feature ,in, This indicates the number of channels corresponding to the shallow features at the selected scale. This indicates the number of channels corresponding to the deep features at the selected scale. Indicates the scaling ratio, and Shallow features contain rich spatial detail information and can describe the edges of minute defects, while the deepest features contain stable semantic information and can suppress background noise. The two have the strongest complementarity.

[0028] To achieve scale alignment and channel uniformity, equations (8) and (9) are used to... and Scale alignment and channel unification are performed to obtain the i-th aligned shallow feature. Deep features aligned with the i-th feature ,in, This represents the number of channels for the scale-aligned feature. (8) (9) In equations (8) and (9), Up(·) represents upsampling the feature map to H×W using interpolation or deconvolution. , These are the channel mappings and kernel parameters for a 1×1 convolution; The SiLU activation function; This represents the convolution operation; this step can eliminate scale differences and channel differences, enabling features of different scales to be fused in a unified feature space.

[0029] Step 2.2.2: Use equations (10) and (11) to... Perform channel attention modeling to generate the i-th shallow channel attention weight. This is used to characterize the importance of each channel for defect detection: (10) (11) In equations (10) and (11), GAP represents the global average pooling operation. , There are two weight parameters; Represents the ReLU activation function; This represents the Sigmoid activation function; This represents the description vector of the i-th shallow channel; this step, by adaptively highlighting the defect-related channel, can suppress the background noise channel and improve the discriminativeness of the feature representation.

[0030] Step 2.2.3: Follow the process in Step 2.2.2. The processing yields the attention weights for the i-th deep channel. ; Step 2.2.4: Use equation (12) to respectively and By performing channel-by-channel weighted fusion, the shallow fusion feature of the i-th weighted layer is obtained. and the i-th weighted deep fusion feature : (12) In equation (12), ⊙ represents the element-wise multiplication of the channel weights with the feature map after the channel weights are broadcast in the spatial dimension.

[0031] Step 2.2.5: Use equation (13) to... and Channel compression and feature fusion are performed to obtain the i-th cigarette box defect fusion feature that simultaneously retains shallow detail information and deep semantic information. ,in, The number of channels used to fuse the defect features of cigarette boxes is used to control the computational complexity of subsequent modules. (13) In equation (13), This indicates a splicing operation. This represents the convolution kernel parameters; this step preserves both shallow detail information and deep semantic information during the fusion process, improving the detectability of minute defects in complex backgrounds.

[0032] Step 2.3: Existing downsampling methods, when reducing feature resolution, cannot distinguish between high-frequency information related to defects and high-frequency information related to background noise, easily leading to the weakening or loss of defect features during the downsampling stage. However, in industrial cigarette box inspection scenarios, the main features of minute defects are concentrated in edge and fine texture areas, and their feature information is mainly distributed in high-frequency components. Therefore, to address the above problem, this invention sets the frequency domain downsampling optimization module (MultiBandReduce) in the downsampling stage of the network, performing frequency domain banding processing before or simultaneously with feature resolution reduction to avoid the erasure of minute defects during the downsampling process. This frequency domain downsampling optimization module MultiBandReduce... Frequency domain transformation is performed and the data is divided into different frequency bands. Differential downsampling processing is applied to the features of different frequency bands to preserve high-frequency information such as defect edges and textures while reducing feature resolution, thus obtaining the i-th downsampled optimized feature. ; Step 2.3.1: For A Discrete Fourier Transform is performed to transform the frequency domain from the spatial domain to the frequency domain, in order to distinguish different frequency components. The resulting frequency domain features are then divided into the i-th low-frequency sub-band features containing global structural information according to the frequency range. The i-th mid-frequency sub-band feature containing regional texture information The i-th high-frequency sub-band feature containing edge and minute defect information This allows for the decoupling of features by frequency components, providing a basis for differentiated downsampling.

[0033] Step 2.3.2: For A strong downsampling step with a large step size is performed to reduce the computational load and obtain the low-frequency domain features after the i-th downsampling. ; right Perform appropriate downsampling to obtain the mid-frequency domain features after the i-th downsampling. ; right Weak downsampling or maintaining the same resolution is employed to preserve key information such as defect edges and crack textures, thereby preventing the disappearance of minute defects during the downsampling stage and obtaining the high-frequency domain features after the i-th downsampling. By employing the aforementioned differentiated downsampling strategy, the feature map retains sufficient high-frequency detail information of defects to the maximum extent while reducing resolution, thereby significantly reducing the false negative rate of small defects at the same downsampling rate.

[0034] Step 2.3.3: Use equation (14) to... , and Frequency domain reconstruction is performed to restore the spatial domain and obtain the reconstructed features of the i-th cigarette box defect. : (14) In equation (14) This represents the inverse discrete Fourier transform operation; Indicates a splicing operation; Step 2.3.4: Use equation (15) to... Channel fusion and compression are performed to obtain the i-th downsampling optimized feature. ,in, and This represents the spatial dimensions after downsampling. The number of channels represents the downsampling optimized feature: (15) In equation (15): To fuse convolution kernel parameters; The SiLU activation function is used. This step preserves key high-frequency information about minute defects while ensuring computational efficiency, providing high-quality input features for the detection head.

[0035] Step 2.4: The YOLOv8 detection head adopts a decoupled structure. Modeling the location and category information of defects on the surface of cigarette boxes is performed to improve the positioning accuracy and classification stability, and to generate defect location and category prediction results. Step 2.4.1: Use equation (16) to... Convolution processing is performed, and the features are further mapped through convolutional layers to obtain the i-th detection feature. (16) In equation (16): W_det is the convolution kernel parameter of the detection head; (·) is the SiLU activation function.

[0036] Step 2.4.2: Classification branching using equation (17) For each candidate location, the defect category is predicted to obtain the probability distribution of the i-th category. This is to improve the ability to distinguish different types of defects (such as scratches, dents, and damage).

[0037] (17) In equation (17): These are the convolution kernel parameters for the classification branch.

[0038] Step 2.4.3: Regression branch using equation (18) The defect bounding box parameters at each candidate location are predicted to obtain the predicted defect bounding box of the i-th location, which contains information about the defect location and size. The bounding box parameters include center coordinates and width and height parameters: (18) In equation (18): The parameters are the convolution kernel parameters for the regression branch; this step can improve the positioning accuracy of small defects and reduce missed detection and offset errors.

[0039] Step 2.4.4: According to and Decode and filter defects at each candidate location, and output... Defect detection results ;in: for The bounding box parameters of the m-th defect include the center position, width, and height; for The predicted category of the m-th defect; for The confidence score of the m-th defect; for The number of defects detected; Step 3: Based on and Constructing the total loss function of the cigarette box defect detection network The loss function is used to measure the difference between the defect detection results and the actual annotations, and includes: classification loss and regression loss. The classification loss is used to constrain the consistency between the defect category prediction results and the actual categories, and the regression loss is used to constrain the localization deviation between the defect bounding box prediction results and the true bounding box. The total loss function is constructed by weighting and summing the various losses to reflect the comprehensive error of the model in the defect identification and localization task.

[0040] Step 4: Iteratively train the cigarette box defect detection network using the stochastic gradient descent (SGD) optimizer and calculate the total loss function. The convolution kernel parameters and bias parameters in the network are updated in reverse until the total loss function is reached. The process continues until convergence, resulting in a trained cigarette box defect detection model. This model is then deployed on industrial production lines to locate and classify defects in collected cigarette box surface images, enabling automated detection of minute defects on the cigarette box surface.

[0041] In summary, the method of this invention enhances the feature representation of the input image with CT-MBDFE, then achieves dynamic multi-scale fusion with DFIU, and retains high-frequency details during the downsampling stage using MultiBandReduce. Finally, the defect box and category score are output by the detection head to form the localization and classification results of the minor defects in the cigarette box.

Claims

1. A method for detecting minute defects in cigarette boxes based on a CDM-YOLOv8 network, characterized in that, Includes the following steps: Step 1: Collect images of the cigarette box surface from the industrial production line, perform preprocessing and annotation, and form a sample set containing image and defect annotation pairs. ;in, This represents the i-th cigarette box surface sample after preprocessing. express The actual annotation information, among which, , , These represent the length, height, and number of channels of the sample on the surface of the cigarette box, respectively. ; This represents the total number of samples on the surface of the cigarette box; Step 2: Construct a cigarette box defect detection network based on the CDM-YOLOv8 network, including: a feature extraction enhancement module, a dynamic multi-scale fusion module, a frequency domain downsampling optimization module, and a YOLOv8 detection head, and then... The process is performed, and the corresponding defect detection results are obtained. ; Step 3: Based on and Constructing the total loss function of the cigarette box defect detection network ; Step 4: Iteratively train the cigarette box defect detection network using the SGD optimizer and calculate the total loss function. Adjust the network parameters until the total loss function is achieved. The process continues until convergence, thus obtaining a trained cigarette box defect detection model, which is used to locate and classify defects in cigarette box surface images.

2. The method for detecting minute defects in cigarette boxes based on a CDM-YOLOv8 network according to claim 1, characterized in that, Step 1 includes the following steps: Step 1.1: Use an industrial camera to capture the raw cigarette box image stream and preprocess it to obtain a preprocessed set of cigarette box surface samples. ; Step 1.2: Labeling The defect box and category are obtained. Authentic labeling information ,in, express The size of the bounding box containing the j-th defect, and , express The center of the bounding box containing the j-th defect. , They represent The width and height of the bounding box containing the j-th defect; express The true category of the j-th defect, and , This represents the total number of defect categories. express The number of defects in the sample.

3. The method for detecting minute defects in cigarette boxes based on a CDM-YOLOv8 network according to claim 2, characterized in that, Step 2 includes the following steps: Step 2.1: The feature extraction enhancement module... The process is performed to obtain the i-th multi-scale enhanced cigarette box defect feature. ,in, express The Middle Enhanced cigarette box defect characteristics at various scales; Indicates the number of scales; Step 2.2: The dynamic multi-scale feature fusion module... Dynamic weighted fusion is performed to obtain the fusion feature of the i-th cigarette box defect. ; Step 2.3: Frequency domain downsampling optimization module Frequency domain transformation and downsampling are performed to obtain the i-th downsampling optimized feature. ; Step 2.4: The YOLOv8 detection head adopts a decoupled structure for... Model the location and category information of defects on the cigarette box surface, and generate defect location and category prediction results. .

4. The method for detecting minute defects in cigarette boxes based on a CDM-YOLOv8 network according to claim 3, characterized in that, Includes the following steps: Step 2.1.1: Use equation (1) to... Perform channel transformation to obtain the basic features of the i-th cigarette box. ,in, This indicates the number of channels in the feature map after channel transformation; (1) In equation (1), The convolution kernel parameters are represented as 1×1 convolutions. This is the bias for the convolution operation. For convolution operations, Indicates the SiLU activation function; Step 2.1.2: Use equations (2) and (3) to... Multi-branch directional feature extraction is performed to obtain the fused feature of the i-th multi-scale / multi-directional cigarette box defect texture and edge information. ; (2) (3) In equations (2) and (3), Indicates the first The receptive field size or orientation of the convolutional kernel used in each convolutional branch, This indicates a splicing operation based on the channel dimension. Represented as convolution kernel parameters; Step 2.1.3: The deformable convolution module utilizes equation (4) to... Perform spatial adaptive alignment processing to obtain the i-th aligned cigarette box defect feature map. ; (4) In equation (4), Indicates two-dimensional coordinate position. Indicates the index of the sampling point. Indicates the first The offset to be learned for each sampling point express The corresponding number The weight of each sampling point A set representing the sampling point indices; express Medium two-dimensional coordinate position Defect characteristic value at the location, express Medium two-dimensional coordinate position Local eigenvalues ​​at; Step 2.1.3: Use equations (5) and (6) to... Spatial self-attention modeling is performed to obtain the i-th attention-enhanced cigarette box defect feature. ; (5) (6) In equations (5) and (6), This represents the i-th query matrix. Represents the i-th key matrix. Represents the i-th value matrix; These represent the linear mapping weights of the query, key, and value, respectively. Matrix transpose This represents the feature dimension corresponding to the attention scaling factor. This represents the distribution function that normalizes similarity to weights. This represents the attention weight matrix of the i-th element; Step 2.1.4: Use equation (7) to... Perform residual normalization processing and output the i-th multi-scale enhanced cigarette box defect feature. : (7) In equation (7), This indicates a normalization operation. This indicates a residual connection.

5. The method for detecting minute defects in cigarette boxes based on a CDM-YOLOv8 network according to claim 4, characterized in that, Step 2.2 includes the following steps: Step 2.2.1: From Two scale features are selected as the i-th shallow layer features. With the i-th deep feature ,in, This indicates the number of channels corresponding to the shallow features at the selected scale. This indicates the number of channels corresponding to the deep features at the selected scale. Indicates the scaling ratio, and ; Using equations (8) and (9) and Scale alignment and channel unification are performed to obtain the i-th aligned shallow feature. Deep features aligned with the i-th feature ,in, This represents the number of channels for the scale-aligned feature. (8) (9) In equations (8) and (9), Up(·) represents an upsampling operation using interpolation or deconvolution. , These are the two parameters of the channel mapping convolution kernel; The SiLU activation function; This represents the convolution operation; Step 2.2.2: Use equations (10) and (11) to... Perform channel attention modeling to generate the i-th shallow channel attention weight. : (10) (11) In equations (10) and (11), GAP represents the global average pooling operation. , There are two weight parameters; Represents the ReLU activation function; This represents the Sigmoid activation function; This represents the description vector of the i-th shallow channel; Step 2.2.3: Follow the process in Step 2.2.

2. The processing yields the attention weights for the i-th deep channel. ; Step 2.2.4: Use equation (12) to respectively and By performing channel-by-channel weighted fusion, the shallow fusion feature of the i-th weighted layer is obtained. and the i-th weighted deep fusion feature : (12) In equation (12), ⊙ denotes element-wise multiplication; Step 2.2.5: Use equation (13) to... and Channel compression and feature fusion are performed to obtain the i-th cigarette box defect fusion feature that simultaneously retains shallow detail information and deep semantic information. ,in, Number of channels for integrating defect features of cigarette boxes: (13) In equation (13), This indicates a splicing operation. This represents another convolution kernel parameter.

6. The method for detecting minute defects in cigarette boxes based on a CDM-YOLOv8 network according to claim 5, characterized in that, Step 2.3 includes the following steps: Step 2.3.1: For Performing a Discrete Fourier Transform, the resulting frequency domain features are divided into the i-th low-frequency sub-band features containing global structural information according to the frequency range. The i-th mid-frequency sub-band feature containing regional texture information The i-th high-frequency sub-band feature containing edge and minute defect information ; Step 2.3.2: For Perform strong downsampling to obtain the low-frequency domain features after the i-th downsampling. ; right Perform appropriate downsampling to obtain the mid-frequency domain features after the i-th downsampling. ; right We obtain the high-frequency domain features after the i-th downsampling by using weak downsampling or keeping the resolution constant. ; Step 2.3.3: Use equation (14) to... , and Frequency domain reconstruction is performed to restore the spatial domain and obtain the reconstructed features of the i-th cigarette box defect. : (14) In equation (14) This represents the inverse discrete Fourier transform operation; Indicates a splicing operation; Step 2.3.4: Use equation (15) to... Channel fusion and compression are performed to obtain the i-th downsampling optimized feature. ,in, and The length and width after downsampling. The number of channels represents the downsampling optimized feature: (15) In equation (15): To fuse convolution kernel parameters; This is the SiLU activation function.

7. The method for detecting minute defects in cigarette boxes based on a CDM-YOLOv8 network according to claim 6, characterized in that, Step 2.4 includes the following steps: Step 2.4.1: Use equation (16) to... Perform convolution processing to obtain the i-th detection feature. : (16) In equation (16): W_det is the convolution kernel parameter of the detection head; The SiLU activation function; Step 2.4.2: Classification branching using equation (17) For each candidate location, the defect category is predicted to obtain the probability distribution of the i-th category. : (17) In equation (17): The convolution kernel parameters for the classification branch; Step 2.4.3: Regression branch using equation (18) The defect bounding box parameters at each candidate location are predicted to obtain the predicted defect bounding box of the i-th location, which contains information about the defect location and size. : (18) In equation (18): The convolution kernel parameters for the regression branch; Step 2.4.4: According to and Decode and filter defects at each candidate location, and output... Defect detection results ;in: for The bounding box parameters of the m-th defect include the center position, width, and height; for The predicted category of the m-th defect; for The confidence score of the m-th defect; for The number of defects detected.

8. An electronic device, comprising a memory and a processor, characterized in that, The memory is used to store a program that supports the processor in executing the cigarette box micro-defect detection method based on the CDM-YOLOv8 network according to any one of claims 1-7, and the processor is configured to execute the program stored in the memory.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is run by the processor, it performs the steps of the cigarette box micro-defect detection method based on the CDM-YOLOv8 network as described in any one of claims 1-7.