Cigarette appearance defect detection method based on MSA-Det algorithm and related device

By combining the MSA-Det algorithm with a feature pyramid network and a convolution-attention fusion module, the problems of multi-scale perception, computational efficiency, and anti-interference in cigarette appearance defect detection are solved, achieving high-precision and high-efficiency defect detection.

CN121504852APending Publication Date: 2026-02-10HEBEI BAISHA TOBACCO
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511654719.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-12
Publication Date
2026-02-10

AI Technical Summary

Technical Problem

Existing FCOS-based methods for detecting cigarette appearance defects have shortcomings in multi-scale perception, computational efficiency, anti-interference ability, feature representation, and sample balance, making it difficult to meet the high-precision and high-efficiency requirements of cigarette production quality control.

Method used

We employ a multi-scale attention sparse detector, MSA-Det, combined with a feature pyramid network (FPN) and a convolutional-attention fusion module (CAIM). We use adaptive pixel-level masking units and HS-ESC modules for feature enhancement and sparse computation, design a multivariate perceptual focusing loss function, and optimize the model training process.

Benefits of technology

It achieves precise location, multi-scale adaptation, and efficient detection of cigarette appearance defects, improving detection accuracy and efficiency, and adapting to complex production environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121504852A_ABST
    Figure CN121504852A_ABST
Patent Text Reader

Abstract

The invention discloses a cigarette appearance defect detection method based on an MSA-Det algorithm and a related device. The method comprises the following steps: acquiring a cigarette appearance image sample collected from a cigarette production line and preprocessing the sample, constructing an MSA-Det infrastructure, accessing a multi-scale feature map output based on FPN to a convolution-attention fusion CAIM module for feature enhancement processing, generating a dynamic calculation mask, and performing HS-ESC multi-scale perception calculation, so as to obtain a CAIM model; and designing a multivariate perceptual focusing loss function, performing model training and deployment, deploying the trained defect detection model on a cigarette production line, detecting the cigarette appearance image collected in real time, and outputting the detected defect type. Therefore, accurate positioning, multi-scale adaptation and efficient detection of the cigarette appearance defects are realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the interdisciplinary field of cigarette quality inspection and computer vision, specifically to the technical fields of MSA-Det algorithm and image processing, and particularly to a method and related apparatus for detecting cigarette appearance defects based on the MSA-Det algorithm. Background Technology

[0002] In the field of cigarette production quality control, appearance defect detection is a crucial step in ensuring product quality. It requires the accurate identification of various defects on the cigarette surface, such as missing filters, poor rolling, stains, thin scratches, and blocky damage. Computer vision object detection technology, with its high efficiency and objectivity, has become the core technological support for cigarette appearance defect detection. FCOS (Fully Convolutional One-Stage Object Detector), a classic single-stage object detection algorithm, with its fully convolutional structure and end-to-end training characteristics, demonstrates good adaptability in general object detection scenarios and has been tested for application in cigarette appearance defect detection tasks.

[0003] However, cigarette appearance defect detection has significant unique characteristics: defect types are diverse (including elongated, blocky, and other shapes), scale varies greatly (from tiny scratches to obvious damage), the defect area occupies a very small portion of the image, and it is easily affected by complex backgrounds in the production environment. Existing FCOS-based detection methods, when adapted to this specific scenario, reveal a series of technical shortcomings, making it difficult to meet the dual requirements of cigarette production for detection accuracy and efficiency. These specific shortcomings are as follows: 1. Limitations of multi-scale defect perception and insufficient detection uniformity. While the FCOS algorithm incorporates a Feature Pyramid Network (FPN) for multi-scale feature extraction, this structure lacks sufficient support for the scale continuity of cigarette appearance defects. Cigarette defects encompass a wide scale range, from micrometer-level elongated scratches to millimeter-level blocky damage. Existing FPN structures struggle to simultaneously optimize feature responses for defects at different scales—insufficiently capturing the fine component features of elongated defects and incompletely extracting the overall contour features of blocky defects. This results in an imbalance in detection performance between the two types of defects, with either a high false negative rate for elongated defects or insufficient localization accuracy for blocky defects.

[0004] 2. Insufficient optimization of computational efficiency; redundant computation consumes excessive resources. FCOS employs a dense detection paradigm, requiring defect confidence and coordinate regression calculations for every pixel location on the feature map. In cigarette appearance defect detection, the defective region occupies a very small proportion of the image (usually less than 1%), with the vast majority of pixels being defect-free background. This "full-location calculation" mode generates a large amount of redundant computation, leading not only to low utilization of computing resources but also significantly increasing inference time, making it difficult to adapt to the high-speed detection requirements of cigarette production lines (typically requiring single-frame detection time to be less than milliseconds).

[0005] 3. Lack of spatial attention mechanisms and weak resistance to interference. Existing FCOS detection methods lack an effective spatial attention mechanism, failing to adaptively focus on potential defect areas in cigarette images based on image content. In cigarette production images, background textures (such as cigarette packaging patterns and shadows of production equipment) are easily confused with defect features. Without spatial attention guidance, the model will pay equal attention to background and defect areas, resulting in weak resistance to interference from complex backgrounds. This leads to a large number of false positives (misclassifying background textures as defects) and false negatives (defect features are not identified due to background interference).

[0006] 4. Limited feature representation ability and insufficient defect discrimination. When performing multi-level feature fusion, FCOS's feature pyramid structure only integrates features through simple upsampling, downsampling, and concatenation, lacking an effective contextual information enhancement mechanism. Discriminative features of cigarette defects (such as the edge texture of scratches and the shape contour of damage) often require combining local details with global contextual information for accurate extraction. However, existing feature fusion methods cannot fully exploit the correlation information between features at different levels, resulting in insufficient discriminative feature representation capabilities for cigarette defects and difficulty in distinguishing defects with similar textures from the background.

[0007] 5. Imbalance between positive and negative samples leads to poor model training performance. FCOS treats all pixel locations on the feature map as candidate samples and distinguishes between positive and negative samples using a preset threshold. However, in cigarette defect detection scenarios, the defective region accounts for a very small proportion, resulting in a significant disparity between the number of positive and negative samples (typically exceeding 1:1000). This leads to a severe imbalance between positive and negative samples during model training. During training, the overwhelmingly high proportion of negative samples dominates the optimization direction of the loss function, causing the model to overfit the background features and fail to fully learn the key features of the defects. Ultimately, this results in poor model generalization ability, making it difficult to guarantee accuracy and stability in actual detection.

[0008] In summary, existing FCOS-based detection methods suffer from various technical shortcomings when addressing the specific needs of cigarette appearance defect detection, including limitations in multi-scale sensing, computational efficiency, anti-interference capabilities, feature representation, and sample balance. These shortcomings prevent them from meeting the high-precision and high-efficiency requirements of cigarette production quality control. Therefore, it is necessary to make targeted improvements to existing FCOS detection methods to enhance their adaptability and detection performance in cigarette appearance defect detection scenarios. Summary of the Invention

[0009] This application provides a method and related device for detecting cigarette appearance defects based on the MSA-Det algorithm. By using multi-scale feature fusion, multi-dimensional attention enhancement, dynamic sparse masking, and adaptive loss function design, it achieves accurate localization, multi-scale adaptation, and efficient detection of cigarette appearance defects, solving the problems of missed detection of subtle defects, poor multi-scale adaptation, and low computational efficiency in existing technologies.

[0010] The technical solution is as follows: Firstly, a method for detecting cigarette appearance defects based on the MSA-Det algorithm is provided, including: Acquire cigarette appearance image samples collected from the cigarette production line and preprocess them, wherein each image sample carries the defect category of the cigarette appearance; The multi-scale attention sparse detector MSA-Det is used as the backbone feature extraction network, and a multi-scale feature pyramid is constructed by combining it with the feature pyramid network FPN to build the MSA-Det infrastructure. The convolutional-attention fusion (CAIM) module is connected after the multi-scale feature map output by the FPN. The features are enhanced through its internal convolutional layers and residual multidimensional collaborative attention mechanism (RMCAM), and feature calibration and contextual information fusion are performed in the three dimensions of channel, height and width. By using adaptive pixel-level masking units, point convolution is used to process the enhanced feature map to generate a soft feature mask. Then, the Gumbel-Softmax reparameterization technique is used to perform differentiable binarization processing, and a binary mask matrix that accurately identifies the defect region is dynamically generated. Based on the generated binary mask matrix, the HS-ESC module is used in the sparse detection head to perform multi-scale feature extraction through parallel heterogeneous convolutional structures, and sparse computation is performed by combining feature concatenation and convolutional fusion. The training gradient gain is dynamically adjusted based on the quality assessment mechanism of cigarette appearance image samples. The learning signal is enhanced for high-quality samples and the interference gradient is suppressed for low-quality samples. Precision P, recall R, and mean precision mAP are used as evaluation indicators for model training to obtain the defect detection model. The trained defect detection model is deployed on the cigarette production line to detect defects in real-time captured images of cigarette appearance and output the detected defect types.

[0011] In one possible implementation, a multi-scale attention sparse detector (MSA-Det) is used as the backbone feature extraction network, and a multi-scale feature pyramid is constructed by combining it with a feature pyramid network (FPN) to build the MSA-Det infrastructure. Specifically, this includes: The fully convolutional single-stage object detector FCOS is used as the backbone network structure. It extracts feature representations at different levels through multiple convolutional stages, and each stage achieves feature map downsampling through stride convolution. A multi-scale FPN consisting of a top-down path and lateral connections is constructed. The top-down path transmits deep semantic features to shallow layers through upsampling, and the lateral connections align feature dimensions through 1×1 convolutions, generating a five-level feature pyramid with rich semantic information. The MSA-Det infrastructure is constructed by integrating the backbone network structure, multi-scale FPN, CAIM feature enhancement processing structure, HS-ESC multi-scale sensing structure, and sparse analysis structure.

[0012] In one possible implementation, a convolutional-attention fusion (CAIM) module is connected after the multi-scale feature map output by the FPN. This module enhances the features through its internal convolutional layers and residual multidimensional collaborative attention mechanism (RMCAM), performing feature calibration and contextual information fusion in three dimensions: channel, height, and width. Specifically, this includes: Feature preprocessing and spatial alignment are performed on the multi-scale feature maps output by FPN: Where: Xi represents the i-th level feature map output by FPN, i is the scale index, and W... 1×1 Represents the point convolution weights, where Pi is the standardized feature map after channel alignment; Construct a channel attention mechanism to compute attention weights in parallel across the three dimensions of channel, height, and width: Where GAP is global pooling, W C W represents the weights of the fully connected layer, σ is the Sigmoid function; h For height-oriented attention weights, W w GPOOL is the attention weight in the width direction. h and GPOOL w These represent global pooling in the height and width directions, respectively; The channel and spatial attention features are concatenated and fused using convolution: Here, ⊙ represents element-wise multiplication, Concat represents channel-level fusion, and Q... i enhance This represents the i-th level enhanced feature map; Activate and output the i-th level enhanced feature map: Where SiLU is the sigmoid linear unit activation function, Q... i enhance Let F'i be the enhanced feature map of the i-th level input, and F'i be the enhanced feature map of the final output.

[0013] In one possible implementation, based on the generated binary mask matrix, an HS-ESC module is used in the sparse detection head to perform multi-scale feature extraction through a parallel heterogeneous convolutional structure. Sparse computation is then performed by combining feature concatenation and convolutional fusion. Specifically, this includes: For the i-th level feature map, a dual-branch parallel convolution is designed to extract different receptive field features: Where Xi represents the i-th level input feature map, and W 3×3 and W 5×5 Let F represent the weight matrices of the 3×3 and 5×5 convolution kernels, respectively. i 3×3 Focusing on local detail extraction, F i 5×5 Focus on global context capture; Channel concatenation and dimensionality compression are performed on the i-th level bi-branch features to achieve multi-scale information fusion: Where Concat is for concatenating channels, F i fused This represents the multi-scale feature map after the i-th level fusion. Based on the generated i-th level binary mask, the fused features are sparsified: Among them, M i Matches the size of the i-th level feature map only if M i When the value is 1, the corresponding positional features are preserved; The global augmented features output by the CAIM module are used to normalize the sparsified features, resulting in the augmented sparse features F. i enhance The process is represented as follows: Among them, F i ' represents the i-th level of globally enhanced contextual feature output by the CAIM module, μ(F') i ) and σ(F' i ) Calculate their mean and standard deviation respectively, where γ and β are the learnable scaling and translation parameters of the i-th level; Residual connection feature optimization is performed by fusing the i-th level enhanced sparse feature with the global feature: Where ReLU is the linear rectified activation function; The optimized feature F i out The data is fed into two separate convolutional layers for the classification and regression branches, respectively, to generate prediction results of this size: classification confidence P. i cls and bounding box coordinate offset P i reg : Among them, W cls and W reg The convolution weights for the classification and regression branches are P, respectively. i cls ∈RB×K×H i ×W i P i reg ∈RB×4×H i ×W i K is the number of defect categories; Quantize the sparse features of the i-th level mask and analyze the relationship between scale and sparsity: Among them, M i Let L be the L0 norm, B be the batch size, and H be the number of digits. i W i Let be the size of the i-th level feature map.

[0014] In one possible implementation, the training gradient gain is dynamically adjusted based on a quality assessment mechanism of cigarette appearance image samples. This enhances the learning signal for high-quality samples and suppresses interfering gradients for low-quality samples. Specifically, this includes: Based on regional overlap, center position deviation, and shape consistency, a multivariate perceptual regression loss is constructed. By integrating classification, regression, normalization, and masking losses, and configuring balancing parameters based on the characteristics of cigarette defect detection tasks, multi-task collaborative gradient analysis is performed. Among them, L i cls Based on classification output P i cls Cross-entropy loss; L i bxywh It is multi-sensory regression loss; L i norm This represents the feature normalization loss; L i mask This represents the binary mask M. i Binary cross-entropy loss with respect to the true defect mask; λ bxywh The α and β represent the equilibrium parameters, respectively, and the β represents the learning parameters. An adaptive training optimization mechanism determines the total loss function.

[0015] In one possible implementation, cigarette appearance image samples collected from the cigarette production line are acquired and preprocessed, specifically including: Industrial cameras were used to collect data from the cigarette production line, and the defects were classified into five categories based on their characteristics: missing filter tip, poor rolling, defective cigarette rod, defective filter tip, and other defects. The image data is enhanced by using random brightness adjustment, contrast transformation and multi-scale scaling to expand the dataset, label the location and category of defects, and divide it into training set, validation set and test set.

[0016] Secondly, a cigarette appearance defect detection device based on the MSA-Det algorithm is provided, comprising: The acquisition module is used to acquire and preprocess cigarette appearance image samples collected from the cigarette production line, wherein each image sample carries the defect category of the cigarette appearance. The module is used to construct a multi-scale feature pyramid by using the multi-scale attention sparse detector MSA-Det as the backbone feature extraction network and combining it with the feature pyramid network FPN to build the MSA-Det infrastructure. The enhancement module is used to connect the convolutional-attention fusion CAIM module after the multi-scale feature map output by the FPN. It enhances the features through its internal convolutional layers and residual multidimensional collaborative attention mechanism RMCAM, and performs feature calibration and context information fusion in the three dimensions of channel, height and width. The generation module is used to process the enhanced feature map through point convolution using adaptive pixel-level mask units to generate a soft feature mask, and uses Gumbel-Softmax reparameterization technology to perform differentiable binarization processing to dynamically generate a binary mask matrix that accurately identifies the defect region. The sparse module is used to perform multi-scale feature extraction in the sparse detection head based on the generated binary mask matrix, using the HS-ESC module and parallel heterogeneous convolutional structure, and combining feature concatenation and convolutional fusion for sparse computation. The training module is used to dynamically adjust the training gradient gain based on the quality assessment mechanism of cigarette appearance image samples, enhance the learning signal for high-quality samples, and suppress interference gradients for low-quality samples. Precision P, recall R, and mean precision mAP are used as evaluation indicators to train the model and obtain the defect detection model. The detection module is used to deploy the trained defect detection model on the cigarette production line, detect the appearance images of cigarettes collected in real time, and output the detected defect types.

[0017] Thirdly, an electronic device is provided, comprising: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the methods described above and any possible implementations.

[0018] Fourthly, a computer-readable storage medium is provided, wherein at least one instruction is stored therein, the at least one instruction being loaded and executed by a processor to implement the aspects described above and any possible implementation thereof.

[0019] Fifthly, a computer program product is provided, comprising a computer program that, when executed by a processor, implements the aspects and any possible implementations described above.

[0020] The beneficial effects of the technical solution provided in this application include at least the following: As can be seen from the above technical solutions, the embodiments of this application... This process involves acquiring and preprocessing cigarette appearance images collected from the cigarette production line. Simultaneously, an MSA-Det architecture is constructed, and multi-scale feature maps output from the FPN are integrated into a convolutional-attention fusion (CAIM) module for feature enhancement, generating dynamically calculated masks, and performing HS-ESC multi-scale perceptual computation. A multivariate perceptual focusing loss function is designed, and the model is trained and deployed. The trained defect detection model is then deployed on the cigarette production line to detect defects in real-time collected cigarette appearance images, outputting the detected defect types. This achieves accurate localization, multi-scale adaptation, and efficient detection of cigarette appearance defects.

[0021] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this application, nor is it intended to limit the scope of this application. Other features of this application will become readily apparent from the following description. Attached Figure Description

[0022] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0023] Figure 1 This is a schematic diagram illustrating the steps of a cigarette appearance defect detection method based on the MSA-Det algorithm provided in an embodiment of this application.

[0024] Figure 2 This is a schematic diagram of cigarette appearance defect classification images provided in another embodiment of this application.

[0025] Figure 3 This is an MSA-Det architecture diagram provided in one embodiment of this application.

[0026] Figure 4 This is a schematic diagram of an image obtained after using an image enhancement strategy according to an embodiment of this application.

[0027] Figure 5 This is a comparison chart of loss function results provided in one embodiment of this application.

[0028] Figure 6 This is a bar chart showing the test set comparison detection results provided in another embodiment of this application.

[0029] Figure 7 This application provides PR curves for different defects using the FCOS algorithm and the MSA-Det algorithm, respectively, according to one embodiment.

[0030] Figure 8 This is a structural block diagram of a cigarette appearance defect detection device based on the MSA-Det algorithm provided in another embodiment of this application.

[0031] Figure 9 This is a block diagram of an electronic device used to implement the cigarette appearance defect detection method based on the MSA-Det algorithm in the embodiments of this application. Detailed Implementation

[0032] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of this application, including various details to aid understanding. These embodiments should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this application. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0033] Obviously, the described embodiments are only some, not all, of the embodiments in this application. All other embodiments obtained by those skilled in the art based on the embodiments in this application without inventive effort are within the scope of protection of this application.

[0034] It should be noted that the terminal devices involved in the embodiments of this application may include, but are not limited to, smart devices such as mobile phones, personal digital assistants (PDAs), wireless handheld devices, and tablet computers; the display devices may include, but are not limited to, personal computers, televisions, and other devices with display functions.

[0035] Furthermore, the term "and / or" 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.

[0036] To address the issues of missed detection of subtle defects, poor multi-scale adaptation, and low computational efficiency in existing cigarette appearance image detection schemes, this application proposes a cigarette appearance defect detection scheme based on the MSA-Det algorithm. The main inventive concept involves: acquiring and preprocessing cigarette appearance image samples collected from the cigarette production line; constructing an MSA-Det infrastructure; using multi-scale feature maps output by FPN and then connecting them to a convolutional-attention fusion (CAIM) module for feature enhancement processing to generate a dynamically calculated mask; performing HS-ESC multi-scale perceptual computation; designing a multivariate perceptual focusing loss function; training and deploying the model; and deploying the trained defect detection model on the cigarette production line to detect real-time acquired cigarette appearance images and outputting the detected defect types. This achieves accurate localization, multi-scale adaptation, and efficient detection of cigarette appearance defects.

[0037] Figure 1 The diagram shown is a step-by-step illustration of a cigarette appearance defect detection method based on the MSA-Det algorithm provided in an embodiment of this application.

[0038] The method for detecting appearance defects in cigarettes may specifically include the following steps: Step 102: Obtain cigarette appearance image samples collected from the cigarette production line and perform preprocessing, wherein each image sample carries the defect category of the cigarette appearance.

[0039] Optionally, in this application, when acquiring and preprocessing cigarette appearance image samples collected from the cigarette production line, an industrial camera can be used to collect data from the cigarette production line, and the defects can be classified into five categories based on their characteristics: missing filter tip, poor rolling, defective cigarette stick, defective filter tip, and other defects; refer to Figure 2 The image shown is a schematic diagram of cigarette appearance defect classification images. The image data was enhanced by using random brightness adjustment, contrast transformation, and multi-scale scaling to expand the dataset. Defect locations and categories were labeled, and the dataset was divided into training, validation, and test sets.

[0040] In specific processing, the location and category of defects can be marked according to the PASCAL VOC2007 standard, an XML tag file can be generated, and the training set, validation set and test set can be divided in an 8:1:1 ratio.

[0041] Step 104: Use the multi-scale attention sparse detector MSA-Det as the backbone feature extraction network, and combine it with the feature pyramid network FPN to construct a multi-scale feature pyramid in order to build the MSA-Det infrastructure.

[0042] Optionally, when using the multi-scale attention sparse detector MSA-Det as the backbone feature extraction network and combining it with a feature pyramid network FPN to construct a multi-scale feature pyramid to build the MSA-Det infrastructure, this application can specifically use a fully convolutional single-stage object detector FCOS as the backbone network structure. It extracts feature representations at different levels through multiple convolutional stages, with each stage using stride convolution to downsample the feature map. A multi-scale FPN consisting of a top-down path and lateral connections is constructed. The top-down path upsamples deep semantic features to shallow layers, and the lateral connections align feature dimensions through 1×1 convolutions, generating a five-level feature pyramid with rich semantic information. The backbone network structure, multi-scale FPN, CAIM feature enhancement processing structure, HS-ESC multi-scale perception structure, and sparse analysis structure are integrated to construct the MSA-Det infrastructure. Thus, multi-level feature fusion is achieved through top-down and lateral connections, providing basic feature representations for subsequent detection tasks. Figure 3 The diagram shown is an MSA-Det architecture diagram of this application, which mainly includes: backbone network, FPN structure, CAIM structure and multiple detection heads.

[0043] Specifically, step 104 can be achieved through the following steps: - Constructing the backbone feature extraction network. The original backbone network structure of FCOS is adopted, which possesses powerful multi-scale feature extraction capabilities and efficient computational performance. The network extracts feature representations at different levels through multiple convolutional stages. Each stage uses stride convolution to downsample the feature map, gradually expanding the receptive field and enriching semantic information, providing multi-level feature inputs for subsequent feature pyramid construction.

[0044] - Construct a Feature Pyramid Network. A multi-scale feature fusion is achieved using an FPN structure, which mainly consists of a top-down path and lateral connections. The top-down path upsamples deep semantic features to shallow layers, while the lateral connections align feature dimensions through 1×1 convolutions, ultimately generating a five-level feature pyramid {P3, P4, P5, P6, P7} with rich semantic information.

[0045] - Construct the overall MSA-Det architecture. Deeply integrate the FCOS basic framework with the CAIM structure and detection head, etc. Its data processing flow is: backbone feature extraction network → feature pyramid network → CAIM feature enhancement module → subsequent detection head. This architecture maintains the advantages of FCOS's anchor-free detection while improving detection performance through feature enhancement and sparse computation mechanisms.

[0046] Step 106: After the multi-scale feature map output by the FPN, the convolutional-attention fusion CAIM module is connected. The features are enhanced through its internal convolutional layers and residual multidimensional collaborative attention mechanism RMCAM, and feature calibration and context information fusion are performed in the three dimensions of channel, height and width.

[0047] Optionally, this application connects a convolutional-attention fusion (CAIM) module after the multi-scale feature map output by the FPN. The CAIM module enhances the features through its internal convolutional layers and residual multidimensional collaborative attention mechanism (RMCAM). Specifically, when performing feature calibration and contextual information fusion in the three dimensions of channel, height, and width, it may include the following: - Feature preprocessing and spatial alignment. In the CAIM module, to facilitate the subsequent calculation of attention weights, the multi-scale feature maps output by FPN first need to be unified and standardized in terms of channel dimensions: Where: Xi represents the i-th level feature map output by FPN, i is the scale index, and W... 1×1 Pi represents the point convolution weights, where Pi is the standardized feature map after channel alignment to ensure consistency. - Construct a channel attention mechanism. This module computes attention weights in parallel across three dimensions: channel, height, and width. The channel attention operation maps input features to the attention space and uses global pooling and fully connected layers to obtain the channel weight representation. Where GAP is global pooling, W C W represents the weights of the fully connected layer, σ is the Sigmoid function; h For height-oriented attention weights, W w GPOOL is the attention weight in the width direction. h and GPOOL w These represent global pooling in the height and width directions, respectively. After global pooling, these are used to locate key regions. - Multidimensional attention fusion. The next step is to perform multidimensional attention fusion, which involves feature concatenation and convolution to fuse channel and spatial attention: Here, ⊙ represents element-wise multiplication, Concat represents channel-level fusion, and Q... i enhance This represents the i-th level enhanced feature map; - Feature reconstruction and output. Activation and output of the i-th level enhanced feature map: Where SiLU is the sigmoid linear unit activation function, Q... i enhance Let F'i be the enhanced feature map of the i-th level input, and F'i be the enhanced feature map of the final output.

[0048] like Figure 4 The image shown is the result of image enhancement strategies. Specifically, techniques such as brightness adjustment, mirror flip, and image rotation are employed. The comparison between the results and the original image demonstrates that the enhanced image significantly improves the model's ability to represent subtle defects on the cigarette surface.

[0049] Step 108: Using adaptive pixel-level mask units, point convolution is used to process the enhanced feature map to generate a soft feature mask. Then, the Gumbel-Softmax reparameterization technique is used for differentiable binarization to dynamically generate a binary mask matrix that accurately identifies the defect region.

[0050] By using adaptive pixel-level masking units, point convolution (1×1 convolution) is used to process the enhanced feature map to generate a soft feature mask. Then, the Gumbel-Softmax reparameterization technique is used for differentiable binarization to dynamically generate a binary mask matrix that accurately identifies the defect region, thereby achieving precise localization of the defect region and allocation of computational resources.

[0051] Step 110: Based on the generated binary mask matrix, the HS-ESC module is used in the sparse detection head to perform multi-scale feature extraction through parallel heterogeneous convolutional structures, and sparse computation is performed by combining feature concatenation and convolutional fusion.

[0052] In this application, based on the generated binary mask, the HS-ESC module is used in the sparse detection head to perform multi-scale feature extraction through 3×3 and 5×5 parallel heterogeneous convolutional structures. Combined with feature concatenation and 1×1 convolution fusion, the model's ability to perceive defects at different scales is enhanced while maintaining sparse computational efficiency.

[0053] Optionally, based on the generated binary mask matrix, the HS-ESC module is used in the sparse detection head to perform multi-scale feature extraction through parallel heterogeneous convolutional structures. When combining feature concatenation and convolutional fusion for sparse computation, the specific features may include the following: - Heterogeneous multi-scale convolutional structure design. For the i-th level feature map, a dual-branch parallel convolution is designed to extract different receptive field features: Where Xi represents the i-th level input feature map, and W 3×3 and W 5×5 Let F represent the weight matrices of the 3×3 and 5×5 convolution kernels, respectively. i 3×3 Focusing on local detail extraction, F i 5×5 Focus on global context capture; - Multi-scale feature fusion and compression. Channel concatenation and dimensionality compression are performed on the i-th level bi-branch features to achieve multi-scale information fusion: Where Concat is for concatenating channels, F i fused The i-th level fused multi-scale feature map is used to avoid channel expansion. - Mask-guided sparse computation mechanism. Based on the generated i-th level binary mask, the fused features are sparsified: Among them, M i Matches the size of the i-th level feature map only if M i When the value is 1, the corresponding positional features are preserved; F is preserved. i fused By identifying features at corresponding locations, targeted calculations of defect areas can be performed, significantly reducing background clutter.

[0054] Contextual Feature Enhancement and Normalization. Since the above sparsity operation discards most of the contextual information of the background region, to compensate for this loss, the global enhanced features output by the CAIM module are used to normalize the sparsified features, resulting in the enhanced sparse feature F. i enhance The process is represented as follows: Among them, F i ' represents the i-th level of globally enhanced contextual feature output by the CAIM module, μ(F') i ) and σ(F' i The mean and standard deviation are calculated respectively, and γ and β are the learningable scaling and translation parameters of the i-th level, respectively; to achieve calibration of global information and local sparse features.

[0055] - Residual connection feature optimization. Residual connection feature optimization is performed by fusing the i-th level enhanced sparse feature with the global feature: Where ReLU is the linear rectified activation function; The detection head output is generated. The optimized feature F is then used. i out The data is fed into two separate convolutional layers for the classification and regression branches, respectively, to generate prediction results of this size: classification confidence P. i cls and bounding box coordinate offset P i reg : Among them, W cls and W reg The convolution weights for the classification and regression branches are P, respectively. i cls ∈RB×K×H i ×W i P i reg ∈RB×4×H i ×W i K is the number of defect categories; output the confidence score and bounding box coordinate offset of the i-th category respectively.

[0056] Mask sparsity analysis. Quantify the sparsity characteristics of the i-th level mask and analyze the relationship between scale and sparsity: Among them, M i Let L be the L0 norm, B be the batch size, and H be the number of digits. i W i Let be the size of the i-th level feature map; experiments show that in cigarette defect detection, ki < 0.3 and k3 > k4 > ... > k7 (large-scale feature maps have sparser defects).

[0057] Step 112: Based on the quality assessment mechanism of cigarette appearance image samples, dynamically adjust the training gradient gain, enhance the learning signal for high-quality samples, and suppress interference gradients for low-quality samples; and use precision P, recall R, and mean precision mAP as evaluation indicators to train the model and obtain the defect detection model.

[0058] In this application, a multivariate perceptual focusing loss function is used to dynamically adjust the training gradient gain based on a sample quality assessment mechanism. The learning signal is enhanced for high-quality samples, while interference gradients are suppressed for low-quality samples. A non-monotonic focusing mechanism balances the training contributions of samples of varying difficulty, improving the model's generalization ability and convergence stability in complex scenarios. Then, the model is trained and deployed. A deep learning environment is built using Python 3.10, PyTorch 2.0.1, and CUDA 11.7, with computation accelerated using an NVIDIA RTX 4080 GPU. Precision (P), recall (R), and mean AP (mAP) are used as evaluation metrics.

[0059] Optionally, when dynamically adjusting the training gradient gain based on the quality assessment mechanism of cigarette appearance image samples, enhancing the learning signal for high-quality samples, and suppressing interfering gradients for low-quality samples, the specific adjustments may include: - Construction of Multivariate Perception Regression Loss. Combining the bounding box coordinate offset Pireg output by the detection head, a bounding box regression loss integrating 'region overlap + center position deviation + shape consistency' is constructed to address the multi-shape and multi-scale characteristics of cigarette defects (scratches, stains, missing filters, etc.), adapting to defect localization requirements in industrial scenarios. (This is repeated in the original text.) Where (i=3,4,5,6,7, corresponding to the feature pyramid P3-P7 multi-scale levels); ui is defined as the alternation ratio between the predicted bounding box and the ground truth bounding box, quantifying the degree of spatial overlap between the two, and is the core optimization for the matching accuracy of defective regions; the predicted bounding box is... i=(x i ,y i W i H i The true bounding box is... i,tr=(x i ,tr,yi,tr, W i ,tr, H i ,tr); D( i, i, tr) represents the Euclidean distance from the center point; L i,diag represent i and The length of the diagonal of the minimum bounding rectangle, i, tr, is defined as Ri, which is a consistency measure of the bounding box length ratio, adapting to different defects in cigarettes. This regression loss will serve as a core component of the multi-task collaborative optimization loss, providing gradient basis for optimizing the accuracy of the bounding box coordinates.

[0060] - Multi-task collaborative loss optimization. Integrating classification, regression, normalization, and masking losses, and configuring balancing parameters based on the characteristics of the cigarette defect detection task, multi-task collaborative gradients are achieved, avoiding training dominated by a single task. Among them, L i cls Based on classification output P i cls The cross-entropy loss is used to optimize the classification confidence of five types of defects; L i bxywh It uses multi-sensory regression loss to optimize bounding box coordinate accuracy and adapt to different positioning requirements; L i norm This represents the feature normalization loss, which supervises the update of learnable parameters γ and β to ensure the enhancement of feature F. i enhance The distribution is stable; L i mask This represents the binary cross-entropy loss based on the generated binary mask Mi and the real defect mask, ensuring accurate localization of the defect region and reducing background interference; λ bxywh =1.5 represents the balancing parameter, emphasizing the weight of the regression task. α=0.3, β=0.2, ensuring a balanced gradient contribution across multiple tasks.

[0061] - Adaptive training optimization mechanism. Combining mask sparsity ki and multi-scale feature semantic characteristics, an adaptive mechanism is designed to improve convergence stability and detection accuracy: the gradient is dynamically adjusted based on ki, and when ki < 0.1 (high sparse level P5-P7, overall defect of the cigarette stick), L is amplified. i bxywh Weight 1.2x to enhance positioning; ki>0.2 (P3-P4 low sparse layer, high background ratio) reduce L i mask Weights are set to 0.8 times to suppress interference; multi-scale weights are configured. i P3-P4 (w=0.3, focusing on small defect location, L) i bxywh (40% of the total score), P5-P7 (w=0.2, focusing on semantic discrimination, L...) i cls (40% of the total) Total loss: Gradient pruning (norm ≤ 5.0), dynamic learning rate (cosine annealing, initial 1e-3, minimum 1e-5, learning rate decreases more slowly in high-sparse layers), and loss normalization (by H) are employed. i W i (Balance scale contribution) ensures training stability. (Refer to...) Figure 5 This is a comparison chart of the loss function results.

[0062] Step 114: Deploy the trained defect detection model on the cigarette production line to detect the real-time collected cigarette appearance images and output the detected defect types.

[0063] The proposed MSA-Det architecture algorithm was applied to the production line of the cigarette packaging workshop for real-time monitoring of cigarette quality. This method can adapt to various complex environments and has high detection accuracy for different cigarette defects. It has strong generalization ability, good stability, and can achieve simultaneous detection and accurate positioning of multiple defects.

[0064] Reference Figure 6 A bar chart comparing the detection results on the test set shows that the MSA-Det architecture algorithm clearly outperforms the others in terms of precision, recall, and average precision. Meanwhile, Figure 7 The left figure also shows the PR curves of the FCOS algorithm for different defects; and the right figure shows the PR curves of the MSA-Det algorithm for different defects; the comparison shows that the MSA-Det algorithm is more accurate in detecting the five defect types.

[0065] Therefore, by using the above technical solution, this application can achieve at least the following technical effects: An MSA-Det architecture integrating CAIM feature enhancement and HS-ESC multi-scale perception was constructed. The residual multidimensional collaborative attention mechanism of the CAIM module is used to perform feature calibration and context fusion in the three dimensions of channel, height and width. Combined with the 3×3 and 5×5 parallel heterogeneous convolution structure of the HS-ESC module, multi-scale feature extraction is performed, which significantly improves the model's feature representation ability and detection accuracy for subtle defects on the cigarette surface (such as missing filter tip and poor rolling). At the same time, computational efficiency is maintained through feature splicing and 1×1 convolution fusion.

[0066] Adaptive pixel-level masking units and a sparse detection mechanism are adopted. Soft feature masks are generated through point convolution and differentiable binarization is performed using Gumbel-Softmax reparameterization technology. A binary mask matrix that accurately identifies defect areas is dynamically generated, enabling precise localization of defect areas and targeted allocation of computational resources. This effectively solves the problem of excessive redundant computation in the detection of minor defects in cigarettes using traditional dense detection paradigms and significantly reduces computational resource consumption.

[0067] A multi-sensory focusing loss function and a multi-task collaborative optimization mechanism are proposed. By constructing a multi-sensory regression loss that integrates region overlap, center position deviation and shape consistency, and combining gradient adjustment of mask sparsity perception and multi-scale loss weight allocation, the training contribution of samples with different difficulty is dynamically balanced. This effectively solves the problem of severe imbalance between positive and negative samples in cigarette defect detection and improves the convergence stability and generalization ability of the model in complex production line environments.

[0068] By coordinating and optimizing the overall MSA-Det architecture, a balance between accuracy and efficiency is achieved. While maintaining the advantages of FCOS's anchorless detection, the deep integration of feature enhancement, sparse computation, and dynamic focusing mechanisms significantly improves the detection performance of multi-scale cigarette defects while reducing computational complexity, thus meeting the dual requirements of high accuracy and high speed for real-time monitoring on the production line.

[0069] Compared with current mainstream detection algorithms such as YOLOv5s, Faster R-CNN, and SSD, the method of this invention has achieved significant improvements in all evaluation indicators in the task of detecting cigarette appearance defects. It shows obvious advantages in detection precision (P), recall (R), and average precision (mAP). At the same time, it greatly reduces the computational overhead through sparse computing mechanism, providing a better technical solution for quality inspection in cigarette production lines.

[0070] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.

[0071] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0072] Figure 8 This paper illustrates a structural block diagram of a cigarette appearance defect detection device based on the MSA-Det algorithm according to an embodiment of this application. Figure 4As shown. The cigarette appearance defect detection device 800 based on the MSA-Det algorithm in this embodiment may include an acquisition module 801, a construction module 802, an enhancement module 803, a generation module 804, a sparsity module 805, a training module 806, and a detection module 807. The system comprises the following modules: an acquisition module 801, which acquires and preprocesses cigarette appearance image samples collected from the cigarette production line, wherein each image sample carries the defect category of the cigarette appearance; a construction module 802, which uses a multi-scale attention sparse detector (MSA-Det) as the backbone feature extraction network and combines it with a feature pyramid network (FPN) to construct a multi-scale feature pyramid to build the MSA-Det infrastructure; an enhancement module 803, which connects a convolutional-attention fusion (CAIM) module after the multi-scale feature map output by the FPN, and enhances the features through its internal convolutional layers and residual multidimensional collaborative attention mechanism (RMCAM), performing feature calibration and context information fusion in the three dimensions of channel, height, and width; and a generation module 804, which uses an adaptive pixel-level mask unit to process the enhanced feature map using point convolution to generate a soft feature mask. The model employs Gumbel-Softmax reparameterization technology for differentiable binarization, dynamically generating a binary mask matrix that accurately identifies defect regions. A sparse module 805, based on the generated binary mask matrix, uses an HS-ESC module in the sparse detection head to extract features at multiple scales through a parallel heterogeneous convolutional structure, combining feature concatenation and convolutional fusion for sparse computation. A training module 806 dynamically adjusts the training gradient gain based on the quality assessment mechanism of cigarette appearance image samples, enhancing the learning signal for high-quality samples and suppressing interference gradients for low-quality samples. Precision (P), recall (R), and mean precision (mAP) are used as evaluation metrics for model training to obtain the defect detection model. A detection module 807 deploys the trained defect detection model on the cigarette production line to detect real-time acquired cigarette appearance images and outputs the detected defect types.

[0073] It should be noted that some or all of the cigarette appearance defect detection device based on the MSA-Det algorithm in this embodiment can be an application located on a local terminal, or it can be a plugin or software development kit (SDK) or other functional unit set in the application located on the local terminal, or it can be a processing engine located on the network side server, or it can be a distributed system located on the network side.

[0074] It is understood that the application can be a native program installed on the local terminal, or it can be a web application of a browser on the local terminal. This embodiment does not limit this.

[0075] Optionally, in one possible implementation of this embodiment, when the construction module 802 uses the multi-scale attention sparse detector MSA-Det as the backbone feature extraction network and combines it with the feature pyramid network FPN to construct a multi-scale feature pyramid to build the MSA-Det infrastructure, it specifically uses the fully convolutional single-stage object detector FCOS as the backbone network structure, extracts feature representations at different levels through multiple convolutional stages, and each stage achieves feature map downsampling through stride convolution; constructs a multi-scale FPN composed of top-down paths and lateral connections, where the top-down paths pass deep semantic features to shallow layers through upsampling, and the lateral connections achieve feature dimension alignment through 1×1 convolution, generating a five-level feature pyramid with rich semantic information; and integrates the backbone network structure, multi-scale FPN, CAIM feature enhancement processing structure, HS-ESC multi-scale perception structure, and sparse analysis structure to construct the MSA-Det infrastructure.

[0076] Optionally, in one possible implementation of this embodiment, the enhancement module 803 connects to the convolutional-attention fusion (CAIM) module after the multi-scale feature map output by the FPN. The CAIM module enhances the features through its internal convolutional layers and residual multidimensional collaborative attention mechanism (RMCAM). Specifically, when performing feature calibration and contextual information fusion in the three dimensions of channel, height, and width, it is used to perform feature preprocessing and spatial alignment on the multi-scale feature map output by the FPN. Where: Xi represents the i-th level feature map output by FPN, i is the scale index, and W... 1×1 Let Pi represent the point convolution weights, and Pi be the normalized feature map after channel alignment. A channel attention mechanism is constructed, which computes the attention weights for the three dimensions of channel, height, and width in parallel. Where GAP is global pooling, W C W represents the weights of the fully connected layer, σ is the Sigmoid function; h For height-oriented attention weights, W w GPOOL is the attention weight in the width direction. h and GPOOL w These represent global pooling in the height and width directions, respectively; channel and spatial attention are then combined through feature concatenation and convolution. Here, ⊙ represents element-wise multiplication, Concat represents channel-level fusion, and Q...i enhance Let i be the enhanced feature map of level i; activate and output the enhanced feature map of level i: Where SiLU is the sigmoid linear unit activation function, Q... i enhance Let F'i be the enhanced feature map of the i-th level input, and F'i be the enhanced feature map of the final output.

[0077] Optionally, in one possible implementation of this embodiment, when the sparse module 805 uses the HS-ESC module in the sparse detection head based on the generated binary mask matrix, performs multi-scale feature extraction through a parallel heterogeneous convolutional structure, and combines feature concatenation and convolutional fusion for sparse computation, it specifically designs a dual-branch parallel convolution to extract different receptive field features for the i-th level feature map: Where Xi represents the i-th level input feature map, and W 3×3 and W 5×5 Let F represent the weight matrices of the 3×3 and 5×5 convolution kernels, respectively. i 3×3 Focusing on local detail extraction, F i 5×5 Emphasis is placed on global context capture; channel concatenation and dimensionality compression are performed on the i-th level bi-branch features to achieve multi-scale information fusion. Where Concat is for concatenating channels, F i fused The multi-scale feature map is formed after fusion at level i; based on the binary mask generated in stage S4, the fused features are sparsified. Among them, M i Matches the size of the i-th level feature map only if M i When the value is 1, the corresponding positional features are preserved; the global enhancement features output by the CAIM module are used to normalize the sparsified features, resulting in the enhanced sparse features F. i enhance The process is represented as follows: Among them, F i ' represents the i-th level of globally enhanced contextual feature output by the CAIM module, μ(F') i ) and σ(F' iCalculate their mean and standard deviation respectively, where γ and β are the learnable scaling and translation parameters of the i-th level, respectively; optimize the residual connection features by fusing the i-th level enhanced sparse features and global features: Where ReLU is a linear rectified activation function; the optimized feature F i out The data is fed into two separate convolutional layers for the classification and regression branches, respectively, to generate prediction results of this size: classification confidence P. i cls and bounding box coordinate offset P i reg : Among them, W cls and W reg The convolution weights for the classification and regression branches are P, respectively. i cls ∈RB×K×H i ×W i P i reg ∈RB×4×H i ×W i K represents the number of defect categories; the sparse features of the i-th level mask are quantified, and the relationship between scale and sparsity is analyzed and determined: Among them, M i Let L be the L0 norm, B be the batch size, and H be the number of digits. i W i Let be the size of the i-th level feature map.

[0078] Optionally, in one possible implementation of this embodiment, the training module 806 dynamically adjusts the training gradient gain based on the quality assessment mechanism of cigarette appearance image samples, enhancing the learning signal for high-quality samples and suppressing interference gradients for low-quality samples. Specifically, it constructs a multi-sensory regression loss based on region overlap, center position deviation, and shape consistency; integrates classification, regression, normalization, and masking losses, and configures balance parameters according to the characteristics of the cigarette defect detection task to perform multi-task collaborative gradient: Among them, L i cls Based on classification output P i cls Cross-entropy loss; L i bxywh It is multi-sensory regression loss; L inorm This represents the feature normalization loss; L i mask This represents the binary mask M. i Binary cross-entropy loss with respect to the true defect mask; λ bxywh The α and β represent the balancing parameters, respectively, and the adaptive training optimization mechanism determines the total loss function.

[0079] Optionally, in one possible implementation of this embodiment, when the acquisition module 801 acquires and preprocesses cigarette appearance image samples collected from the cigarette production line, it specifically uses an industrial camera to collect data from the cigarette production line, classifies defects into five categories based on defect characteristics: missing filter tip, poor rolling joint, cigarette stick defect, filter tip defect, and other defects; enhances the image data by using random brightness adjustment, contrast transformation, and multi-scale scaling to expand the dataset, labels the defect location and category, and divides the dataset into training set, validation set, and test set.

[0080] In this embodiment, cigarette appearance image samples collected from the cigarette production line can be acquired and preprocessed. Simultaneously, an MSA-Det infrastructure is constructed, and the multi-scale feature map output by FPN is then connected to the convolutional-attention fusion CAIM module for feature enhancement processing, generating a dynamically calculated mask, and performing HS-ESC multi-scale perceptual computation. A multivariate perceptual focusing loss function is designed, the model is trained and deployed, and the trained defect detection model is deployed on the cigarette production line to detect real-time acquired cigarette appearance images, outputting the detected defect types. Thus, accurate localization, multi-scale adaptation, and efficient detection of cigarette appearance defects are achieved.

[0081] One embodiment of this application provides a computer-readable storage medium storing at least one instruction, which is loaded and executed by a processor to implement the cigarette appearance defect detection method based on the MSA-Det algorithm as described above.

[0082] One embodiment of this application provides an electronic device, which includes a processor and a memory. The memory stores at least one instruction, which is loaded and executed by the processor to implement the cigarette appearance defect detection method based on the MSA-Det algorithm as described above.

[0083] The collection, storage, use, processing, transmission, provision, and disclosure of user personal information involved in the technical solution of this application all comply with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0084] Figure 9A schematic block diagram of an example electronic device 900 that can be used to implement embodiments of this application is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the application described and / or claimed herein.

[0085] like Figure 9 As shown, the electronic device 900 includes a computing unit 901, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 902 or a computer program loaded from a storage unit 908 into a random access memory (RAM) 903. The RAM 903 may also store various programs and data required for the operation of the electronic device 900. The computing unit 901, ROM 902, and RAM 903 are interconnected via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.

[0086] Multiple components in electronic device 900 are connected to I / O interface 905, including: input unit 906, such as keyboard, mouse, etc.; output unit 907, such as various types of displays, speakers, etc.; storage unit 908, such as disk, optical disk, etc.; and communication unit 909, such as network card, modem, wireless transceiver, etc. Communication unit 909 allows electronic device 900 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0087] The computing unit 901 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 901 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 901 performs the various methods and processes described above, such as the blind zone detection method. For example, in some embodiments, the blind zone detection method can be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 908. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 900 via ROM 902 and / or communication unit 909. When the computer program is loaded into RAM 903 and executed by the computing unit 901, one or more steps of the blind zone detection method described above can be performed. Alternatively, in other embodiments, the computing unit 901 can be configured to perform the blind zone detection method by any other suitable means (e.g., by means of firmware).

[0088] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations may include: implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transferring data and instructions to the storage system, at least one input device, and at least one output device.

[0089] The program code used to implement the methods of this application may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that when executed by the processor or controller, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0090] In the context of this application, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0091] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0092] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.

[0093] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.

[0094] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this application can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this application can be achieved, and this is not limited herein.

[0095] The specific embodiments described above do not constitute a limitation on the scope of protection of this application. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this application should be included within the scope of protection of this application.

Claims

1. A method for detecting cigarette appearance defects based on the MSA-Det algorithm, characterized in that, include: Acquire cigarette appearance image samples collected from the cigarette production line and preprocess them, wherein each image sample carries the defect category of the cigarette appearance; The multi-scale attention sparse detector MSA-Det is used as the backbone feature extraction network, and a multi-scale feature pyramid is constructed by combining it with the feature pyramid network FPN to build the MSA-Det infrastructure. The convolutional-attention fusion (CAIM) module is connected after the multi-scale feature map output by the FPN. The features are enhanced through its internal convolutional layers and residual multidimensional collaborative attention mechanism (RMCAM), and feature calibration and contextual information fusion are performed in the three dimensions of channel, height and width. By using adaptive pixel-level masking units, point convolution is used to process the enhanced feature map to generate a soft feature mask. Then, the Gumbel-Softmax reparameterization technique is used to perform differentiable binarization processing, and a binary mask matrix that accurately identifies the defect region is dynamically generated. Based on the generated binary mask matrix, a heterogeneous scaling-enhanced sparse convolution HS-ESC module is used in the sparse detection head to perform multi-scale feature extraction through parallel heterogeneous convolution structure, and sparse computation is performed by combining feature concatenation and convolution fusion. The training gradient gain is dynamically adjusted based on the quality assessment mechanism of cigarette appearance image samples. The learning signal is enhanced for high-quality samples and the interference gradient is suppressed for low-quality samples. Precision P, recall R, and mean precision mAP are used as evaluation indicators for model training to obtain the defect detection model. The trained defect detection model is deployed on the cigarette production line to detect defects in real-time captured images of cigarette appearance and output the detected defect types.

2. The method as described in claim 1, characterized in that, A multi-scale attention sparse detector (MSA-Det) is used as the backbone feature extraction network, and a multi-scale feature pyramid is constructed by combining it with a feature pyramid network (FPN) to build the MSA-Det infrastructure. Specifically, this includes: The fully convolutional single-stage object detector FCOS is used as the backbone network structure. It extracts feature representations at different levels through multiple convolutional stages, and each stage achieves feature map downsampling through stride convolution. A multi-scale FPN consisting of a top-down path and lateral connections is constructed. The top-down path transmits deep semantic features to shallow layers through upsampling, and the lateral connections align feature dimensions through 1×1 convolutions, generating a five-level feature pyramid with rich semantic information. The MSA-Det infrastructure is constructed by integrating the backbone network structure, multi-scale FPN, CAIM feature enhancement processing structure, HS-ESC multi-scale sensing structure, and sparse analysis structure.

3. The method as described in claim 2, characterized in that, The convolutional-attention fusion (CAIM) module is then applied after the multi-scale feature map output by the FPN. This module enhances the features through its internal convolutional layers and residual multidimensional collaborative attention mechanism (RMCAM), performing feature calibration and contextual information fusion in three dimensions: channel, height, and width. Specifically, this includes: Feature preprocessing and spatial alignment are performed on the multi-scale feature maps output by FPN: Where: Xi represents the i-th level feature map output by FPN, i is the scale index, and W... 1×1 Represents the point convolution weights, where Pi is the standardized feature map after channel alignment; Construct a channel attention mechanism to compute attention weights in parallel across the three dimensions of channel, height, and width: Where GAP is global pooling, W C W represents the weights of the fully connected layer, σ is the Sigmoid function; h For height-oriented attention weights, W w GPOOL is the attention weight in the width direction. h and GPOOL w These represent global pooling in the height and width directions, respectively; The channel and spatial attention features are concatenated and fused using convolution: Here, ⊙ represents element-wise multiplication, Concat represents channel-level fusion, and Q... i enhance This represents the i-th level enhanced feature map; Activate and output the i-th level enhanced feature map: Where SiLU is the sigmoid linear unit activation function, Q... i enhance Let F'i be the enhanced feature map of the i-th level input, and F'i be the enhanced feature map of the final output.

4. The method as described in claim 3, characterized in that, Based on the generated binary mask matrix, the HS-ESC module is used in the sparse detection head to perform multi-scale feature extraction through parallel heterogeneous convolutional structures. Sparse computation is then performed by combining feature concatenation and convolutional fusion. Specifically, this includes: For the i-th level feature map, a dual-branch parallel convolution is designed to extract different receptive field features: Where Xi represents the i-th level input feature map, and W 3×3 and W 5×5 Let F represent the weight matrices of the 3×3 and 5×5 convolution kernels, respectively. i 3×3 Focusing on local detail extraction, F i 5×5 Focus on global context capture; Channel concatenation and dimensionality compression are performed on the i-th level bi-branch features to achieve multi-scale information fusion: Where Concat is for concatenating channels, F i fused This represents the multi-scale feature map after the i-th level fusion. Based on the i-th level binary mask generated in stage S4, the fused features are sparsified: Among them, M i Matches the size of the i-th level feature map only if M i When the value is 1, the corresponding positional features are preserved; The global augmented features output by the CAIM module are used to normalize the sparsified features, resulting in the augmented sparse features F. i enhance The process is represented as follows: Among them, F i ' represents the i-th level of globally enhanced contextual feature output by the CAIM module, μ(F') i ) and σ(F' i ) Calculate their mean and standard deviation respectively, where γ and β are the learnable scaling and translation parameters of the i-th level; Residual connection feature optimization is performed by fusing the i-th level enhanced sparse feature with the global feature: Where ReLU is the linear rectified activation function; The optimized feature F i out The data is fed into two separate convolutional layers for the classification and regression branches, respectively, to generate prediction results of this size: classification confidence P. i cls and bounding box coordinate offset P i reg : Among them, W cls and W reg The convolution weights for the classification and regression branches are P, respectively. i cls ∈RB×K×H i ×W i P i reg ∈RB×4×H i ×W i K is the number of defect categories; Quantize the sparse features of the i-th level mask and analyze the relationship between scale and sparsity: Among them, M i Let L be the L0 norm, B be the batch size, and H be the number of digits. i W i Let be the size of the i-th level feature map.

5. The method as described in claim 3, characterized in that, The training gradient gain is dynamically adjusted based on the quality assessment mechanism of cigarette appearance image samples. This enhances the learning signal for high-quality samples and suppresses interfering gradients for low-quality samples. Specifically, this includes: Based on regional overlap, center position deviation, and shape consistency, a multivariate perceptual regression loss is constructed. By integrating classification, regression, normalization, and masking losses, and configuring balancing parameters based on the characteristics of cigarette defect detection tasks, multi-task collaborative gradient analysis is performed. Among them, L i cls Based on classification output P i cls Cross-entropy loss; L i bxywh It is multi-sensory regression loss; L i norm This represents the feature normalization loss; L i mask This represents the binary mask M. i Binary cross-entropy loss with respect to the true defect mask; λ bxywh The α and β represent the equilibrium parameters, respectively, and the β represents the learning parameters. An adaptive training optimization mechanism determines the total loss function.

6. The method according to any one of claims 1-5, characterized in that, Acquire cigarette appearance image samples collected from the cigarette production line and perform preprocessing, specifically including: Industrial cameras were used to collect data from the cigarette production line, and the defects were classified into five categories based on their characteristics: missing filter tip, poor rolling, defective cigarette rod, defective filter tip, and other defects. The image data is enhanced by using random brightness adjustment, contrast transformation and multi-scale scaling to expand the dataset, label the location and category of defects, and divide it into training set, validation set and test set.

7. A cigarette appearance defect detection device based on the MSA-Det algorithm, characterized in that, include: The acquisition module is used to acquire and preprocess cigarette appearance image samples collected from the cigarette production line, wherein each image sample carries the defect category of the cigarette appearance. The module is used to construct a multi-scale feature pyramid by using the multi-scale attention sparse detector MSA-Det as the backbone feature extraction network and combining it with the feature pyramid network FPN to build the MSA-Det infrastructure. The enhancement module is used to connect the convolutional-attention fusion CAIM module after the multi-scale feature map output by the FPN. It enhances the features through its internal convolutional layers and residual multidimensional collaborative attention mechanism RMCAM, and performs feature calibration and context information fusion in the three dimensions of channel, height and width. The generation module is used to process the enhanced feature map through point convolution using adaptive pixel-level mask units to generate a soft feature mask, and uses Gumbel-Softmax reparameterization technology to perform differentiable binarization processing to dynamically generate a binary mask matrix that accurately identifies the defect region. The sparse module is used to perform multi-scale feature extraction in the sparse detection head based on the generated binary mask matrix, using the HS-ESC module and parallel heterogeneous convolutional structure, and combining feature concatenation and convolutional fusion for sparse computation. The training module is used to dynamically adjust the training gradient gain based on the quality assessment mechanism of cigarette appearance image samples, enhance the learning signal for high-quality samples, and suppress interference gradients for low-quality samples. Precision P, recall R, and mean precision mAP are used as evaluation indicators to train the model and obtain the defect detection model. The detection module is used to deploy the trained defect detection model on the cigarette production line, detect the appearance images of cigarettes collected in real time, and output the detected defect types.

8. An electronic device, comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1-6.

9. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-6.

10. A computer program product comprising a computer program that, when executed by a processor, implements the method according to any one of claims 1-6.