Real-time industrial defect detection method and system based on multi-scale attention and progressive feature global shuffling
By employing a multi-scale attention and progressive feature global shuffling method, the industrial defect detection model is optimized, resolving the contradiction between high precision, high speed, and low computational overhead. This enables efficient industrial defect detection, applicable to real-time inspection of products such as metals, electronic components, and sheet metal.
Patent Information
- Application Number
- CN202511558842.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-29
- Publication Date
- 2026-02-24
AI Technical Summary
Existing deep learning-based industrial defect detection methods struggle to simultaneously meet the demands for high accuracy, high speed, and low computational overhead in complex industrial scenarios.
A real-time industrial defect detection method is proposed, which adopts multi-scale attention and progressive feature global shuffling. This method constructs a low-level visual feature extraction module driven by a multi-scale attention mechanism, a pyramid multi-scale progressive mid-level feature fusion network, and an adaptive spatial feature fusion mechanism. The model is trained by combining an improved loss function, and the backbone network, neck network, and detection head are optimized to improve feature representation ability and detection efficiency.
It achieves high-precision (mAP of 91.0%-92.3%) and high real-time performance (over 121.5 FPS) industrial defect detection, reduces computational overhead, and is suitable for real-time detection of products such as metals, electronic components, and sheet metal.
Smart Images

Figure CN121564388A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of industrial defect detection technology, specifically relating to an industrial defect detection method and system that combines high precision, high real-time performance and low computational overhead with multi-scale attention and progressive feature global shuffling. Background Technology
[0002] Industrial surface defect detection plays a crucial role in industrial production, but it is also an extremely challenging task. With the ever-increasing demand for various metal materials in the automotive, aerospace, and shipbuilding industries, metals often develop various surface defects such as inclusions, pits, and scratches during processing due to various reasons. These defects not only reduce the quality, mechanical properties, and corrosion resistance of materials, but also adversely affect the performance of the final product. Therefore, timely detection and classification of defects during the manufacturing process are essential.
[0003] Currently, with the continuous development of deep neural networks and deep learning technologies, automated defect detection methods have become mainstream. YOLO (You Only Look Once, Real-time Object Detection) algorithm, as a real-time object detection technology based on convolutional neural networks, differs from traditional two-stage detection methods (such as the R-CNN series) by simultaneously achieving object localization and classification within a single network, thus demonstrating high detection efficiency in real-time applications. Although YOLOv8, as a single-stage model, boasts a fast detection speed due to its lower parameter count and computational complexity, it sacrifices some accuracy to a certain extent, making it difficult to simultaneously meet the demands of high accuracy, high speed, and low computational overhead. Summary of the Invention
[0004] The technical problem to be solved by this invention is that existing deep learning-based industrial defect detection methods are difficult to simultaneously meet the requirements of high precision, high speed and low computational overhead in complex industrial scenarios. This invention provides an efficient real-time industrial defect detection method and system that can be widely applied to the detection of surface defects (such as inclusions, patches, dents, holes, scratches, etc.) in industrial products such as metals, electronic components, and sheet metal.
[0005] To solve the technical problem proposed in this invention, the present invention adopts the following technical solution:
[0006] First, this invention provides a real-time industrial defect detection method based on multi-scale attention and progressive feature global shuffling, specifically including the following steps:
[0007] S1. Data Preprocessing and Dataset Construction. Industrial image data containing various surface defect types are collected. The images are preprocessed, including uniform size cropping (e.g., 640×640) and defect classification and labeling; data augmentation is performed through random flipping, Gaussian blurring, brightness and contrast adjustment, image stitching, etc.; training and test sets are divided according to a preset ratio (e.g., 7:3) for model training and performance verification.
[0008] S2. Construct a core detection model, build a basic network framework for industrial defect detection, and systematically optimize its structure to form a highly efficient real-time detection model with multi-scale attention and global shuffling of progressive features; the structural optimization specifically includes:
[0009] S21. Optimize the backbone network by designing a feature-enhanced multi-scale structure and attention mechanism. Specifically, construct an attention mechanism-driven low-level visual feature extraction module and a multi-scale block strategy to jointly improve the backbone network's ability to represent defective features.
[0010] S22. The neck network is optimized by designing a progressive multi-scale fusion network. Specifically, a pyramid multi-scale progressive mid-layer feature fusion network is constructed, and cross-layer interaction strategies, dynamic upsampling operators, and cross-stage global interaction shuffling modules are introduced to improve feature reuse efficiency and enhance small target detection capabilities.
[0011] S23. The detection head is optimized by introducing an adaptive spatial fusion mechanism. Specifically, an adaptive spatial feature fusion mechanism is integrated to adaptively weight and fuse multi-scale features, and a decoupled head structure is adopted to simultaneously improve the accuracy of defect classification and positioning.
[0012] S3. Model Training and Validation. Based on the training set partitioned in step S1, the core detection model constructed in step S2 is trained using a gradient descent optimization method combined with an improved loss function based on geometry awareness. After each training cycle, the model is validated using a test set, and the model weights with the best performance are saved.
[0013] S4. Defect Detection and Output. The image of the industrial surface to be detected is input into the core detection model loaded with optimal weights. The model outputs the classification results of the defects and their precise location coordinates.
[0014] Furthermore, in step S21 of the present invention, the implementation process of the multi-scale block (MSB) module is as follows:
[0015] 1. Let the input feature X ∈ R H×W×C After being expanded by a 1×1 convolution, the channels are divided into n groups (n=3), where the first group (X1) retains the original information as a cross-stage connection; the remaining groups are connected through an inverted bottleneck layer (IB). k×kThe processing involves increasing the convolution kernel size k with the network layer. The output when i=1 is Y. i =X i When i>1, Y i =IB k×k (Y) i-1 +X i ); and all Y i Multi-scale feature encoding is achieved by concatenating the components after 1×1 convolution.
[0016] 2. The attention mechanism-driven underlying visual feature extraction module (GoNAM) consists of GhostConv and a NAM normalization attention module:
[0017] First, redundant features are generated using GhostConv to reduce computational cost. Then, these redundant features are input into NAM, and batch normalization (BN) is used to train a scaling factor γ to evaluate channel importance, using the formula:
[0018] ,
[0019] Global recalibration is performed on the feature channels to enhance noise suppression of key features, among which and , where are the mean and standard deviation of the mini-batch data, respectively; β is the offset parameter. =1e-5 is a numerically stable term.
[0020] In step S22, the implementation process of the pyramid multi-scale progressive mid-layer feature fusion network is as follows:
[0021] 1. Introduce a backbone network C2 layer (160×160 resolution) specifically for detecting small 4×4 pixel targets; let M... i For the input layer feature map (by C) i -C5 layer is generated through 5-i downsampling iterations), and F is generated through the feature fusion function f. i Then, after a 3×3 convolution, the middle layer feature map D is output. i ,satisfy:
[0022] ,
[0023] ,
[0024] in Bilinear interpolation is used.
[0025] 2. Embed a dynamic upsampling operator (DySample) in the fusion network: For the input feature I (size H×W×s²), a dynamic offset is generated by pixel rewashing, which adaptively adjusts the sampling position, replacing traditional upsampling to reduce computational complexity.
[0026] 3. The implementation process of the cross-stage global interaction shuffle module (VoV-GSCSP) is as follows: Combine GSConv lightweight convolution and depthwise separable convolution to construct a GS-bottleneck; achieve channel shuffle through the cross-stage gradient path, retain spatial detail features, and introduce a global information capture mechanism to expand the receptive field; divide the neck features into two paths, one path is processed by the GS-bottleneck, and the other path is shuffled through the channels and then spliced with the previous path, and the output is integrated through 1×1 convolution to achieve efficient reuse of multi-source features and global context modeling.
[0027] In step S23, the specific implementation of the adaptive spatial feature fusion (ASFF) mechanism includes:
[0028] 1. Unify the resolutions of the hierarchical features (D2, D3, D4, D5) output by the pyramid network: For the coarser levels where k > l (k is the target level index and l is the current level index), use bilinear interpolation upsampling with a scaling factor s = 2 (k-l) ; for the finer levels where k < l, use stride convolution downsampling with a scaling factor s = 2 (l-k) ;
[0029] 2. For the feature maps (X1, X2, X3, X4) with unified resolutions, compress the channels to the same dimension through 1×1 convolution, and then generate the spatial weight tensors of the features of each level through the Softmax activation function , and perform weighted fusion on the feature map X i with unified resolutions to output the fused feature Y:
[0030] ,
[0031] where L = 4 is the total number of fusion scales.
[0032] 3. Adopt a decoupled detection head, and output the defect category probability of the prediction box through "convolution layer + Sigmoid activation function" to avoid category competition; output the coordinate offset of the prediction box relative to the anchor box through the convolution layer to achieve decoupled optimization of defect classification and localization and improve the localization accuracy.
[0033] Furthermore, in step S3 of the present invention, model training, end-to-end optimization based on an improved loss function, includes:
[0034] 1. Training parameter configuration: Training epochs: 300; Initial learning rate: 0.001 (no additional scheduling is required during training to maintain a stable learning pace); Training batch size: 16; Optimizer: Stochastic gradient descent (SGD) optimizer is used to balance training stability and convergence speed.
[0035] 2. Improve the application of the Shape-IoU loss function. To address the accuracy issue in bounding box regression for irregular defects, a geometry-sensitive factor is introduced. The loss function formula is as follows:
[0036] ,
[0037] IoU calculation: (B represents the predicted bounding box, and Bgt represents the ground truth bounding box).
[0038] 3. After each training cycle, use the test set divided by S1 to verify the model performance (core metrics: mAP, FPS), save the weight file with the best performance to avoid overfitting.
[0039] Furthermore, step S4 of the present invention: defect detection, real-time inference and result output, specifically includes:
[0040] The image of the industrial surface to be detected (such as an image of a metal sheet captured by a camera on a production line) is input into the core detection model with optimal weights. The model outputs the results through the following process:
[0041] The image to be detected is preprocessed to the same size as S1 (cropped to 640×640); the preprocessed image is input into the backbone network to extract multi-scale features, which are then fused and optimized by the neck network, and finally the detection head outputs the category label of the defect (such as "scratch") and the bounding box location coordinates;
[0042] Meanwhile, this invention also proposes a real-time industrial defect detection device based on multi-scale attention and global blending of progressive features, comprising:
[0043] The data preprocessing unit is used to collect industrial image data containing various surface defect types, preprocess the images, and divide them into training and testing sets to construct a dataset.
[0044] The detection model construction unit is used to build the basic network framework for industrial defect detection. It optimizes the structure of the backbone network, neck network, and detection head of the basic network framework to form a real-time detection model with multi-scale attention and global shuffling of progressive features.
[0045] The backbone network is structurally optimized by constructing the attention mechanism-driven low-level visual feature extraction module GoNAM to enhance the extraction of key defect features and suppress background noise, and by using multi-scale block MSB to achieve hierarchical feature fusion encoding, thereby jointly improving the feature representation capability of the backbone network.
[0046] Structural optimization of the neck network is achieved by designing a progressive multi-scale fusion network;
[0047] Structural optimization of the detection head is achieved by introducing an adaptive spatial fusion mechanism;
[0048] The model training unit, based on the training set divided by the data preprocessing unit, uses gradient descent optimization method and combines geometry perception to construct a loss function to train the detection model constructed by the detection model construction unit;
[0049] The defect detection unit is used to save the weight file with the best model performance during the training process, input the image of the industrial surface to be detected into the core detection model with the best weight, and output the classification result and location coordinates of the defect.
[0050] Furthermore, the present invention proposes an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed, it implements the steps of the method of the present invention.
[0051] Finally, the present invention provides a computer-readable storage medium having a computer program stored thereon, the computer program being configured to implement the steps of the method as described in the present invention when invoked by a processor.
[0052] Compared with the prior art, the present invention has the following significant technical effects:
[0053] This invention addresses the core pain point of existing deep learning-based industrial defect detection methods in complex industrial scenarios, which struggle to simultaneously achieve high accuracy, high real-time performance, and low computational overhead. It achieves synergistic multi-dimensional technological advantages through innovative end-to-end design, specifically:
[0054] On the one hand, a high-quality dataset is constructed to cover various defects such as inclusions, patches, dents, holes, and scratches. On the other hand, data augmentation techniques such as random flipping and Gaussian blur are combined to solve the problems of imbalanced industrial sample categories and excessive background interference, thereby significantly improving the model's generalization ability.
[0055] On the other hand, the backbone network strengthens feature representation through "MSB multi-scale blocks + GoNAM attention module", while the neck network reduces computation and improves feature reuse efficiency through "pyramid multi-scale progressive fusion + cross-stage global interactive shuffling + dynamic upsampling (DySample)". The detection head optimizes localization accuracy through adaptive spatial fusion (ASFF) and decoupled structure. Combined with the improved Shape-IoU loss function with geometry awareness, the model achieves a breakthrough in performance: it ensures a high accuracy of 91.0%-92.3% mAP (especially effective in detecting small and irregular defects) and achieves a real-time inference speed of over 121.5 FPS. Moreover, the number of model parameters increases only slightly, and it can be deployed on industrial production lines without complex hardware, providing a reliable solution for industrial quality control that balances accuracy, efficiency and cost. Attached Figure Description
[0056] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0057] Figure 1 This is a schematic diagram of the defect detection method in an embodiment of the present invention.
[0058] Figure 2 This is an example image of an industrial surface defect sample from the database in an embodiment of the present invention.
[0059] Figure 3 This is a structural diagram of the MS-Block module in this invention.
[0060] Figure 4 This is a structural diagram of the Ghostconv module in this invention.
[0061] Figure 5 This is an overall structural diagram of the NAM module in this invention.
[0062] Figure 6 This invention relates to a pyramid-based multi-scale progressive mid-layer feature fusion network structure.
[0063] Figure 7 This is a schematic diagram of the DySample dynamic upsampling operator in this invention.
[0064] Figure 8 This is a structural diagram of the cross-stage global interactive shuffling module in this invention.
[0065] Figure 9 This is the specific structure of the efficient real-time industrial defect detection model based on multi-scale attention and progressive feature global shuffling in this invention. Detailed Implementation
[0066] The present invention will be further described below with reference to the accompanying drawings and specific embodiments. These drawings are only used to illustrate the basic structure of the present invention, wherein the same reference numerals denote the same parts.
[0067] like Figure 1 As shown, this embodiment provides a highly efficient real-time industrial defect detection method based on multi-scale progressive and lightweight optimization, including steps S1 to S4:
[0068] S1: Data preprocessing and dataset construction.
[0069] This step aims to build a defect dataset that is "class-balanced, accurately labeled, and adapted to industrial scenarios." The specific operations are as follows:
[0070] S11: Data Acquisition and Category Definition:
[0071] 1. Data Source: The VisA dataset contains 9,621 normal images and 1,200 anomalous images. The image resolution is uniformly 640×640 pixels, covering 12 object categories and encompassing three scene types: complex structures, single objects, and multiple objects. Anomalous types include surface defects (such as scratches, dents, discoloration, and cracks) and structural defects (such as misalignment and missing parts). Figure 2 The image shows a scratch defect.
[0072] 2. Uniform size cropping: All images (collected at 1920×1200) are cropped to 640×640 pixels (by using bilinear interpolation to fill in the edges and avoid stretching and deformation) to fit the model input size; the image pixel values are scaled from [0,255] to [0,1] to reduce numerical fluctuations during model training.
[0073] S12: Defect Annotation: Annotate the bounding box (xmin, ymin, xmax, ymax) and defect category (e.g., "scratch" or "hole") for each defect; the annotation file output is one XML file for each image, recording defect information, and finally generating a set of annotation files.
[0074] S13: Data Augmentation
[0075] 1. Geometric enhancement: random horizontal flip (probability 0.5), random vertical flip (probability 0.3), random rotation (-15°~15°, probability 0.4);
[0076] 2. Pixel enhancement: Gaussian blur (kernel size 3×3, standard deviation 0.1~0.3, probability 0.2), brightness / contrast adjustment (brightness ±20%, contrast ±15%, probability 0.5).
[0077] S14: Dataset Partitioning: Divide the augmented dataset into training, testing, and validation sets in a 7:2:1 ratio.
[0078] S2: Construct a core detection model, build a basic network framework for industrial defect detection, and systematically optimize its structure to form a highly efficient real-time detection model with multi-scale attention and global shuffling of progressive features; the structural optimization specifically includes:
[0079] S21: Optimize the backbone network by constructing an attention-driven low-level visual feature extraction module and a multi-scale block strategy to jointly improve the backbone network's ability to represent defect features. The specific operation is as follows:
[0080] 1. For example Figure 3 As shown, in the MSB module, let the input feature X ∈ R H×W×C After being expanded by a 1×1 convolution, the layers are divided into n groups (n = 3). The first group (X1) retains the original information as a cross-stage connection to avoid gradient vanishing; the remaining groups are connected through an inverted bottleneck layer (IB). k×k The processing involves increasing the kernel size k with the network layer, resulting in an output Y. i Satisfy: When i=1, Y i =X i When i>1, Y i =IB k×k (Y) i-1 +X i ); and all Y i After 1×1 convolution, the concatenation achieves multi-scale feature encoding and improves the ability to extract features of small defects;
[0081] 2. The GoNAM module consists of GhostConv (such as...) Figure 4 (as shown) and NAM (as shown) Figure 5 (As shown) The normalized attention module consists of: first, generating redundant features through GhostConv to reduce computational cost; then, inputting the redundant features into NAM; and using batch normalization (BN) to train the scaling factor γ to evaluate channel importance, using the formula:
[0082] ,
[0083] Global recalibration is performed on the feature channels to enhance noise suppression of key features, among which and , where are the mean and standard deviation of the mini-batch data, respectively; β is the offset parameter. =1e-5 is a numerically stable term.
[0084] S22: The neck network is optimized by constructing a pyramid multi-scale progressive mid-layer feature fusion network. Cross-layer interaction strategies, dynamic upsampling operators, and cross-stage global interactive shuffling modules are introduced to improve feature reuse efficiency and enhance small target detection capabilities. Specific operations are as follows:
[0085] 1. A new small target detection layer is added to the pyramid multi-scale progressive mid-layer feature fusion network: a backbone network C2 layer (160×160 resolution) is introduced specifically for detecting 4×4 pixel small targets; let M... i For the input layer feature map (by C) i -C5 layer is generated through 5-i downsampling iterations), and F is generated through the feature fusion function f. i Then, after a 3×3 convolution, the middle layer feature map D is output. i ,satisfy:
[0086] ,
[0087] ,
[0088] upSample uses bilinear interpolation, specifically as follows: Figure 6 As shown.
[0089] 2. For example Figure 7 The diagram shows the principle of the dynamic upsampling operator (DySample). The input feature I (with dimensions H×W×s²) is generated by pixel rewashing to produce a dynamic offset of sH×sW×(x,y). This adaptively adjusts the sampling position, replacing traditional upsampling to reduce computational complexity, solving the "feature blurring" problem of traditional upsampling, and adapting to the recovery of small defect features.
[0090] 3. Cross-stage global interactive shuffling module (e.g.) Figure 8 As shown, GS-bottleneck is constructed by combining lightweight GSConv convolution with depthwise separable convolution; channel shuffling is achieved through cross-stage gradient paths to preserve spatial detail features, while a global information capture mechanism is introduced to expand the receptive field; the neck features are divided into two paths, one of which is processed by GS-bottleneck, and the other path is concatenated with the first path after channel shuffling, and then integrated and output through 1×1 convolution to achieve efficient reuse of multi-source features.
[0091] S23: The detection head is optimized by integrating an adaptive spatial feature fusion mechanism, which adaptively weights and fuses multi-scale features, and adopts a decoupled head structure to simultaneously improve the accuracy of defect classification and localization. The specific operation is as follows:
[0092] 1. Unify the resolution of the hierarchical features (D2, D3, D4, D5) output by the pyramid network. The unified resolution is (160×160). Upsample D3 (80×80) by a factor of 2, D4 (40×40) by a factor of 4, and D5 (20×20) by a factor of 8, all using bilinear interpolation; for the coarser hierarchical levels where k > l, upsample using bilinear interpolation with a scaling factor s = 2 (k-l) ; for the finer hierarchical levels where k < l, downsample using stride convolution with a scaling factor s = 2 (l-k) ;
[0093] 2. For the feature maps (X1, X2, X3, X4) with unified resolution, compress the channels to the same dimension through 1×1 convolution, and then generate the spatial weight tensors of the features at each hierarchical level through the Softmax activation function , and perform weighted fusion on the feature map X with unified resolution i to output the fused feature Y:
[0094] ,
[0095] where L = 4 is the total number of fusion scales.
[0096] 3. Adopt a decoupled detection head, and output the probability of the defect category of the prediction box through "convolution layer + Sigmoid activation function" to avoid category competition; output the coordinate offset of the prediction box relative to the anchor box through the convolution layer to achieve the decoupled optimization of defect classification and localization and improve the localization accuracy.
[0097] S3: Model training and verification. This step adopts the "gradient descent + dynamic verification" strategy to ensure that the model converges to the optimal performance, with specific parameters and operations.
[0098] S31: Training epochs: 300 (the first 5 epochs are "warm-up training", and the learning rate linearly increases to the initial value); initial learning rate: 0.001 (decays every 10 epochs and finally drops to 0.00001); batch size (BatchSize): 16 (since the video memory occupancy of a single 640×640 image is about 512MB, the total video memory occupancy of 16 batches is about 8GB, adapted to RTX 4070); optimizer: stochastic gradient descent (SGD), momentum 0.9, weight decay 0.0005 (to suppress overfitting).
[0099] S32: Application of the improved Shape-IoU loss function. Adopt the shape-sensitive Shape-IoU loss, and the formula is:
[0100] ,
[0101] IoU calculation: (B represents the predicted bounding box, and Bgt represents the ground truth bounding box).
[0102] distance_shape: Shape-sensitive distance term, formula is...
[0103] ,
[0104] Where c is the length of the diagonal of the minimum enclosing rectangle, and hh and ww are the shape weights.
[0105] , ,
[0106] The scale weight term measures the shape deviation between the predicted bounding box and the ground truth bounding box, balancing the gradient contributions between targets of different scales and ensuring that the regression loss can optimize the matching degree of targets with different shapes. The formula is:
[0107] .
[0108] S33: Model Performance Verification
[0109] The weights after each training iteration were saved, and the optimal weights were used to perform detection on the test set to evaluate the model's performance. The experimental environment consisted of an NVIDIA RTX 4070 GPU, a 24-core, 32-thread Intel Core i9-13900HX CPU, and 32GB of RAM. After the module improvement, mAP increased by 3.5%, and FPS increased by 5.3%. Specific detection results are shown in Table 2.
[0110]
[0111] After each training cycle, the model performance is validated using the test set divided by S1, and the weight file with the best validation performance is saved to avoid overfitting.
[0112] S4: Defect detection, real-time inference and result output:
[0113] The image of the industrial surface to be inspected (such as an image of a metal sheet captured by a camera on a production line) is input into the core detection model with optimal weights. The model outputs the results through the following process, as shown in the flowchart. Figure 9 As shown, it specifically includes:
[0114] The image to be detected is preprocessed to the same size as S1 (cropped to 640×640); the preprocessed image is input into the backbone network to extract multi-scale features, which are then fused and optimized by the neck network, and finally the detection head outputs the category label of the defect (such as "scratch") and the bounding box location coordinates.
[0115] In summary, the efficient real-time industrial defect detection method based on multi-scale attention and progressive feature global shuffling in the above embodiments, through specific hardware configuration, reproducible parameters and industrial scenario verification, proves that the system proposed in this invention has higher detection accuracy and speed, and is expected to be applied to real-time detection in industry in the future.
[0116] Example 2: This example proposes a real-time industrial defect detection device based on multi-scale attention and progressive feature global shuffling, comprising:
[0117] The data preprocessing unit is used to collect industrial image data containing various surface defect types, preprocess the images, and divide them into training and testing sets to construct a dataset.
[0118] The detection model construction unit is used to build the basic network framework for industrial defect detection. It optimizes the structure of the backbone network, neck network, and detection head of the basic network framework to form a real-time detection model with multi-scale attention and global shuffling of progressive features.
[0119] The backbone network is structurally optimized by constructing the attention mechanism-driven low-level visual feature extraction module GoNAM to enhance the extraction of key defect features and suppress background noise, and by using multi-scale block MSB to achieve hierarchical feature fusion encoding, thereby jointly improving the feature representation capability of the backbone network.
[0120] Structural optimization of the neck network is achieved by designing a progressive multi-scale fusion network;
[0121] Structural optimization of the detection head is achieved by introducing an adaptive spatial fusion mechanism;
[0122] The model training unit, based on the training set divided by the data preprocessing unit, uses gradient descent optimization method and combines geometry perception to construct a loss function to train the detection model constructed by the detection model construction unit;
[0123] The defect detection unit is used to save the weight file with the best model performance during the training process, input the image of the industrial surface to be detected into the core detection model with the best weight, and output the classification result and location coordinates of the defect.
[0124] Example 3: This example proposes an electronic system, including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the method steps of the present invention.
[0125] Example 4: This example proposes a computer-readable storage medium storing a computer program thereon. When the computer program is executed by a processor, it implements the steps of the method described in this invention, which will not be repeated here.
[0126] It should be noted that the processing flow of embodiments 2-4 corresponds to the specific steps of the method provided in embodiment 1 of the present invention, and has the corresponding functional modules and beneficial effects of the execution method. Technical details not described in detail in this embodiment can be found in the method provided in embodiment 1 of the present invention. The program code used to implement the method of this application can be written in any combination of one or more programming languages. This program code can be provided to the processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that when the program code is executed by the processor or controller, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The program code can be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a standalone software package, or entirely on a remote machine or server.
[0127] In the description of this specification, references to terms such as "an embodiment," "example," "specific example," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0128] Based on the above-described preferred embodiments of the present invention, and through the foregoing description, those skilled in the art can make various changes and modifications without departing from the inventive concept. The technical scope of this invention is not limited to the contents of the specification, but must be determined by the scope of the claims.
Claims
1. A real-time industrial defect detection method based on multi-scale attention and progressive feature global shuffling, characterized in that, Includes the following steps: Industrial image data containing various surface defect types were collected, the images were preprocessed and divided into training and testing sets to construct a dataset; A basic network framework for industrial defect detection was constructed, and the backbone network, neck network, and detection head of the basic network framework were structurally optimized to form a real-time detection model with multi-scale attention and global shuffling of progressive features; among which... The backbone network is structurally optimized by constructing the attention mechanism-driven low-level visual feature extraction module GoNAM to enhance the extraction of key defect features and suppress background noise, and by using multi-scale block MSB to achieve hierarchical feature fusion encoding, thereby jointly improving the feature representation capability of the backbone network. The structural optimization of the neck network is achieved by designing a pyramid multi-scale progressive mid-layer feature fusion network, including cross-layer interaction strategy, dynamic upsampling strategy and progressive feature global shuffling mechanism. The structural optimization of the detection head is achieved by introducing an adaptive spatial feature fusion mechanism, including resolution unification and weighted fusion. Based on the partitioned training set, a gradient descent-based optimization method is used, combined with geometry perception to construct a loss function, and the constructed detection model is trained. During training, the optimal weight file for model performance is saved. The industrial surface image to be detected is input into the detection model with the optimal weights, and the classification results and location coordinates of the defects are output.
2. The method according to claim 1, characterized in that, The images are preprocessed, specifically including: cropping the collected industrial surface defect images to a uniform preset size, classifying the images according to defect type and completing pixel-level annotation using Pascal VOC or COCO format; and improving the diversity of the dataset and the generalization ability of the model through data augmentation techniques.
3. The method according to claim 1, characterized in that, Optimizing the backbone network structure specifically includes: The GoNAM module consists of a GhostConv convolution module and a Normalized Attention (NAM) module cascaded together. First, GhostConv performs convolution operations on the input features to generate a feature tensor containing redundant information, reducing computational cost and preserving key details. Then, this redundant feature tensor is input into NAM, where the trainable scaling factor γ of batch normalized BN is used to evaluate the importance of each channel. Finally, the feature channels are globally recalibrated using the following formula to enhance key features and suppress noise: , in and , where are the mean and standard deviation of the mini-batch data, respectively; β is the offset parameter. It is a numerically stable term; Implementation process of MSB module: Let the input feature X ∈ R H×W×C After being expanded by a 1×1 convolution, the channels are divided into n groups, where the first group (X1) retains the original information as a cross-stage connection; the remaining groups are connected through an inverted bottleneck layer (IB). k×k The processing involves increasing the convolution kernel size k with the network layer. The output when i=1 is Y. i =X i When i>1, Y i =IB k×k (Y) i-1 +X i ); and all Y i After convolution, the features are concatenated to achieve multi-scale feature encoding.
4. The method according to claim 1, characterized in that, The neck network structure is optimized by constructing a pyramid-shaped multi-scale progressive mid-layer feature fusion network, introducing cross-layer interaction strategies, dynamic upsampling strategies, and a progressive feature global shuffling mechanism. The specific implementation process includes: The implementation process of the pyramid multi-scale progressive mid-layer feature fusion network is as follows: Low-layer features of the backbone network are introduced specifically for detecting small targets; let M... i The i-th layer feature map of the input neck network is processed by the feature fusion function. Generate fusion feature F i Then, after convolution, the middle layer feature map Di is output, which satisfies: , , in Bilinear interpolation is used; A dynamic upsampling operator is embedded in the pyramid multi-scale progressive mid-layer feature fusion network: for the input feature I, a dynamic offset is generated through the pixel rewashing algorithm to adaptively adjust the sampling position; The cross-stage global interactive shuffling module is implemented as follows: GS-bottleneck is constructed by combining grouped sparse convolution and depthwise separable convolution; the feature tensor of the neck network is divided into two paths through the cross-stage gradient path: one path is input into GS-bottleneck for feature compression and enhancement, and the other path is subjected to channel shuffling operation and then concatenated with the output features of GS-bottleneck; finally, the concatenated features are integrated through convolution to achieve global interaction and efficient reuse of multi-source features, while expanding the feature receptive field through a global information capture mechanism.
5. The method according to claim 1, characterized in that, The detection head undergoes structural optimization, specifically by integrating an adaptive spatial feature fusion mechanism. This mechanism weights and fuses features of different scales output by the pyramid network, improving the detection head's efficiency in utilizing features from defects of multiple sizes. The specific implementation process includes: To unify the resolution of the hierarchical features output by the pyramid network: Let k be the hierarchical index of the target unified resolution. This is the hierarchical index of the current feature to be processed; if k > l, meaning the current feature is at a coarse level, bilinear interpolation is used for upsampling, with an upsampling scaling factor s = 2. (k-l) If k < This means that the current feature is at a fine level, and downsampling is performed using convolution with a downsampling scaling factor s=2. (l-k) ; For the feature map X after uniform resolution i The channels are compressed to the same dimension through convolution, and then the spatial weight tensors of each level of features are generated by the Softmax activation function. Perform weighted fusion and output fused feature Y: , Where L represents the total number of fusion scales; A decoupled detection head structure is adopted: the detection head is divided into a classification branch and a regression branch. The classification branch outputs the defect category probability of each predicted box through a convolutional layer and a sigmoid activation function, while the regression branch outputs the coordinate offset of the predicted box relative to the anchor box through a convolutional layer, thereby achieving decoupled optimization of defect classification and localization.
6. The method according to claim 1, characterized in that, The specific steps for training the constructed detection model include: Model training parameter configuration: The training period is set to 300, the initial learning rate is 0.001, the training batch size is set to 16, and the stochastic gradient descent optimizer is used during the training process; Loss function application: The Shape-IoU loss function is adopted, which improves the regression accuracy for irregular defective bounding boxes by introducing a bounding box geometry sensitivity factor. The formula is as follows: , Where B is the predicted bounding box and Bgt is the ground truth bounding box; Model weight saving: After each training cycle, the model performance is verified using the partitioned test set, and the model weight file with the best verification performance is saved for subsequent defect detection.
7. The method according to claim 1, characterized in that, After obtaining the detection model with the optimal weights, the core detection model with the optimal weights is deployed on embedded devices or industrial computers to achieve real-time defect detection on industrial surfaces using hardware acceleration.
8. A real-time industrial defect detection device based on multi-scale attention and progressive feature global mixing, characterized in that, include: The data preprocessing unit is used to collect industrial image data containing various surface defect types, preprocess the images, and divide them into training and testing sets to construct a dataset. The detection model construction unit is used to build the basic network framework for industrial defect detection. It optimizes the structure of the backbone network, neck network, and detection head of the basic network framework to form a real-time detection model with multi-scale attention and global shuffling of progressive features. The backbone network is structurally optimized by constructing the attention mechanism-driven low-level visual feature extraction module GoNAM to enhance the extraction of key defect features and suppress background noise, and by using multi-scale block MSB to achieve hierarchical feature fusion encoding, thereby jointly improving the feature representation capability of the backbone network. Structural optimization of the neck network is achieved by designing a progressive multi-scale fusion network; Structural optimization of the detection head is achieved by introducing an adaptive spatial fusion mechanism; The model training unit, based on the training set divided by the data preprocessing unit, uses gradient descent optimization method and combines geometry perception to construct a loss function to train the detection model constructed by the detection model construction unit; The defect detection unit is used to save the weight file with the best model performance during the training process, input the image of the industrial surface to be detected into the core detection model with the best weight, and output the classification result and location coordinates of the defect.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the computer program is executed, it implements the steps of the method as described in any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, The computer program is configured to implement the steps of the method according to any one of claims 1 to 7 when invoked by a processor.
Citation Information
Cited By
Metal part surface defect classification method based on deep learning
CN122090187A