Industrial product surface defect detection system based on segmentation all-in-one model
The SAM2 model, improved by lightweight dual adapters and multi-scale feature fusion technology, solves the problem of limited computing resources in industrial surface defect detection and achieves efficient and accurate defect detection results.
Patent Information
- Application Number
- CN202510781507.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-12
- Publication Date
- 2025-09-26
AI Technical Summary
Existing technologies in industrial surface defect detection have problems such as insufficient single-modal feature discrimination, inefficient cross-scale defect modeling, and limited computing power of edge devices. In particular, large models are difficult to deploy on resource-constrained industrial equipment.
A lightweight dual-adapter architecture based on the Segmentation Everything Model (SAM2) is adopted, combined with the Scale-Aware Feature Attention Perceptron (SFAP) and the Adaptive Feature Enhancement Module (AFEM). By freezing the backbone network and fine-tuning only 1.8% of the parameters, efficient adaptation is achieved. Multi-scale feature fusion and cross-layer attention mechanism are introduced to optimize feature representation and boundary detection.
It significantly improves the stability and accuracy of the model in industrial defect detection, reduces computational costs, improves robustness to small defects and complex backgrounds, and achieves efficient industrial surface defect detection.
Smart Images

Figure CN120707491A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of detection technology, and in particular relates to a system and method for detecting surface defects of industrial products based on a segmentation model. Background Art
[0002] Industrial surface defect detection is crucial for ensuring product quality and safety in the manufacturing and transportation industries. In critical sectors like aerospace and precision engineering, even minor defects like scratches, cracks, or rust can lead to catastrophic failures. Traditional manual inspection, which relies heavily on experience, is labor-intensive and error-prone, and cannot meet the stringent requirements of modern automated production lines for high-precision, real-time quality control.
[0003] The rapid development of deep learning has driven significant progress in the field of surface defect detection. Convolutional neural network (CNN)-based architectures (such as EDRNet[2]) and defect detection models using Res2Net / ResNet backbones have achieved robust performance through multi-scale feature learning. However, in actual industrial applications, three key challenges remain: insufficient discriminability of single-modal features, inefficient cross-scale defect modeling, and limited computing power of edge devices. Although traditional CNNs expand the receptive field through hierarchical convolution, their fixed kernel design makes it difficult to achieve a balance between capturing submillimeter defect details and understanding global structures. At the same time, large models (with more than 200 million parameters) trained for accuracy are difficult to deploy on resource-constrained industrial edge devices (e.g., power <10W, computing power <50G FLOPs).
[0004] Recent advances in visual foundational models (VFMs) offer new perspectives for addressing these challenges. The general-purpose segmentation model SAM2 demonstrates strong zero-shot segmentation capabilities thanks to its large-scale pre-training (11 million images) and cue-driven flexibility. However, its direct application in industrial defect detection is limited by two key bottlenecks: parameter redundancy (214 million base parameters lead to high fine-tuning costs) and task-specific adaptation gaps (no categorical output features and limited ability to perceive multi-scale defect features in the absence of human cues).
[0005] Surface defect detection (SDD) plays a key role in industrial quality control. Existing methods can be categorized into contact-based methods (e.g., mechanical probes) and non-contact methods (e.g., image processing and ultrasonic sensing). Early studies, such as those by Mandriota et al., employed Gabor filters for defect characterization.
[0006] The innovation of deep learning has given rise to revolutionary architectures, starting from the CNN framework proposed by Faghih-Roohi et al. (such as MINet[9]) and developing to more complex designs such as EDRNet[2], which improves accuracy through an encoder-decoder residual structure. Multimodal solutions including SAINet and modules such as CAAF / MFIB have effectively addressed specific challenges in areas such as railway defect detection. In addition, significant progress has been made in the field of disguised object detection (COD), such as FSPNet improving the performance of visual Transformer by enhancing local feature modeling, and UEDG combining uncertainty reasoning with edge estimation to improve detection accuracy. However, these advances still face deployment bottlenecks, especially the limitations of computational complexity and the need for multi-sensor synchronization.
[0007] Recent advances in visual foundation models (VFMs), such as SAM2, have demonstrated the potential of large-scale pre-trained networks. However, their application in surface defect detection (SDD) is limited by parameter redundancy (214 million parameters) and insufficient adaptability to multi-scale defect features. Lightweight models based on techniques such as GhostNet feature compression and cross-layer attention have been developed to improve small defect detection using monomodal RGB input.
[0008] However, existing methods still face challenges: traditional single-modal RGB input methods have difficulty distinguishing defect features, the huge differences in defect sizes require the model to have multi-scale modeling capabilities, and the limited computing power of industrial equipment requires a lightweight and high-precision detection model.
[0009] The Segment Everything Model (SAM) is an important basic model in the field of computer vision, demonstrating excellent zero-shot learning and generalization capabilities in image segmentation tasks.
[0010] SAM consists of a visual Transformer-based image encoder, a lightweight mask decoder, and a flexible hint encoder. The image encoder comes in three versions: ViT-Base, ViT-Huge, and ViT-Large. After pre-training with the MAE method, it can process high-resolution images and learn rich visual features. The hint encoder supports multiple input forms and embeds hint information through position encoding and CLIP technology to provide flexible guidance for segmentation tasks. The mask decoder outputs three masks of different ranges for each input image, which improves the reliability of the segmentation results. SAM has a wide range of application scenarios. In medical image analysis, it assists in disease diagnosis and treatment planning. In the field of remote sensing, it supports tasks such as land cover classification and provides support for urban planning and resource management. In motion segmentation scenarios, it is used in intelligent monitoring and autonomous driving. It also provides new ideas for fields such as camouflaged target detection.
[0011] However, SAM has limitations in complex low-level structure segmentation tasks. For example, it is difficult to accurately distinguish between foreground and background in camouflaged target detection, and it performs poorly in dealing with the complex structures of human tissues and organs and the differences between images of different modalities in medical image segmentation. To address these problems, researchers have proposed a variety of improvement methods, such as improving performance by adding high-quality output tokens and training on fine-grained masks, or optimizing efficiency to adapt to actual scenarios and mobile devices. The subsequently developed SAM2 has an optimized network architecture and is trained on a larger visual corpus, with theoretically stronger performance. However, its performance still needs to be improved in specific downstream tasks such as medical image segmentation, camouflaged target detection, and shadow detection. Therefore, the researchers proposed a method similar to SAM2-Adapter, which combines task-specific knowledge with model-general knowledge through a multi-adapter configuration, achieving new optimal results in multiple challenging segmentation tasks, highlighting the value of targeted improvements to the basic model.
[0012] To address these gaps, this application proposes SDDNet, an industrial surface defect detection network adapted to SAM2 through lightweight dual adapters and multi-scale feature enhancement technology, effectively addressing the unique challenges of single-modal industrial inspection. The core contributions are as follows:
[0013] A novel dual-adapter architecture (Prompt+Bottleneck) was introduced for the first time. By freezing the backbone network and fine-tuning only 1.8% of the parameters (3.89 million / 214 million), SAM2 was efficiently adapted to industrial defect detection tasks. This strategy shortened training time by 82% and improved model stability (mean absolute error (MAE) was reduced by 10.23% compared to the baseline), effectively addressing the parameter redundancy issue of SAM2. In the SD-Saliency-900 benchmark, this lightweight design achieved optimal performance with a MAE of 0.0270, providing a new paradigm for deploying visual foundation models in resource-constrained industrial scenarios.
[0014] We propose a scale-aware feature attention perceptron (SFAP), which introduces an attention-guided hierarchical fusion mechanism to address the scale variation problem in unimodal RGB input. By fusing Transformer-based multi-scale aggregation, coordinate attention (CoordAtt) and global attention (GlobalAtt), SFAP improves the S-measure (S m ) indicator increased by 2.8%, significantly enhancing the model’s ability to handle low-contrast defect detection challenges.
[0015] An efficient decoder using partial convolution and cross-layer feature compensation is developed, which reduces the computational cost by 34% while retaining 95.2% of the details of sub-millimeter defects. Compared with the traditional UNet decoder, the adaptive feature enhancement module (AFEM) makes the weighted F-value (F w ) is improved by 2.1%, effectively solving the boundary ambiguity problem in defect segmentation. This design strikes a balance between lightweight computation and high-precision boundary detection, which is critical for industrial quality control applications.
[0016] The SDDNet proposed in this paper innovatively improves upon SAM2 by designing a scale-aware feature attention perceptron (SFAP) to optimize defect perception for pure RGB inputs, building a cross-layer feature compensation mechanism, and employing an adaptive feature enhancement module (AFEM) to improve boundary localization accuracy. By embedding dual adapters, the model enables efficient parameter fine-tuning, providing an efficient and adaptable solution for industrial surface defect detection. Summary of the Invention
[0017] In response to the above technical problems existing in the prior art, the present invention proposes an industrial product surface defect detection system and method based on a segmentation model, which has a reasonable design, overcomes the shortcomings of the prior art, and has good results.
[0018] In order to achieve the above object, the present invention adopts the following technical solutions:
[0019] A surface defect detection system for industrial products based on a segmentation-everything model includes an adaptive encoder, a scale-aware feature attention sensor, and a decoder; wherein,
[0020] An adaptive encoder, integrated with a dual adapter module, configured to perform multi-scale feature extraction;
[0021] A scale-aware feature attention sensor is configured to fuse multi-scale features with a hybrid attention mechanism and enhance feature representation through an adaptive feature enhancer, ensuring that even subtle defects can be effectively presented;
[0022] The decoder, using an adaptive feature enhancement module, is configured to gradually restore the spatial resolution and fuse semantic information at different levels.
[0023] Preferably, the adaptor encoder comprises a prompt adapter and a bottleneck adapter; wherein,
[0024] The prompt adapter is configured to dynamically generate task-specific prompt vectors and integrate them with the original input features through point-by-point addition. The mechanism of the prompt adapter is shown in formula (2):
[0025]
[0026] Among them, W down 、W up is a learnable linear projection matrix, b down 、b up is the bias term, X represents the original input feature, X prompted is the output feature of the prompt adapter, '+' indicates element-wise addition, P is the task-specific prompt vector dynamically generated by the prompt adapter, GELU (Gaussian Error Linear Unit) is an activation function that adaptively activates neurons based on the input data distribution, introducing nonlinear characteristics;
[0027] The bottleneck adapter is configured to enhance feature adaptation capabilities; specifically:
[0028] Project the input features into a low-dimensional bottleneck space, apply GELU nonlinear activation and dropout layers for regularization, and reconstruct the original feature dimensions; integrate learnable scaling factors and layer normalization to improve model stability and feature expression capabilities;
[0029] The mathematical expression of the bottleneck adapter is shown in formula (3):
[0030]
[0031] Among them, W diwn 、W up is a learnable linear projection matrix, b down 、b up is the bias term, X bottleneck Represents the output features of the bottleneck adapter, Z is the intermediate feature representation in the bottleneck adapter calculation process; Dropout is a regularization technique that sets the neuron output to zero with a certain probability during training to prevent overfitting.
[0032] Preferably, the scale-aware feature attention sensor includes a receptive field module, an adaptive feature enhancer, an attention mechanism and a multi-scale attention module; wherein,
[0033] Coordinate attention and global attention modules; among them,
[0034] A receptive field module configured to enhance feature extraction capability by utilizing multi-branch convolutions with different receptive fields;
[0035] An adaptive feature enhancer configured to optimize feature representation using the Transformer mechanism and cross-scale feature fusion;
[0036] The attention mechanism is configured to enhance local details and global dependencies, optimize features, and avoid missing potential defects;
[0037] The multi-scale attention module is configured to dynamically aggregate features from different levels. The module integrates a multi-head self-attention mechanism to capture local fine-grained details and global contextual dependencies.
[0038] Preferably, the receptive field module adopts a four-branch convolution structure with different expansion rates, and each branch uses a convolution kernel with a different expansion rate, and the expansion rate is r = 1, 3, 5, and 7; the convolution kernel with an expansion rate of r = 1 is 1×1, the convolution kernel with an expansion rate of r = 3 is 3×3, the convolution kernel with an expansion rate of r = 5 is 5×5, and the convolution kernel with an expansion rate of r = 7 is 7×7, extracting multi-scale context information from local to global; after splicing the features of each branch, the channel dimension is compressed by 1×1 convolution, and the residual connection is used to enhance the feature expression capability; its mathematical expression is shown in formula (4):
[0039]
[0040] Among them, x1, x2, x3, x4 are the outputs of the four branches, Conv1 represents a 1×1 convolution operation, and f represents the original input feature; Concat refers to splicing the outputs of the four branches into x in a specific dimension. cat , ReLU is the activation function f(x) = max(0,x), which is used to introduce nonlinearity and alleviate the disappearance of gradient, x out It is the final output feature of the receptive field module.
[0041] Preferably, the adaptive feature enhancer uses the Transformer mechanism and cross-scale feature fusion to optimize feature representation; specifically, the multi-scale features are first projected into a 256-dimensional space through the projection function Proj(·); then they are optimized through multiple layers of Transformer modules, and finally mapped back to the original channel dimension through the output convolution layer OutConv(·); and then a reshaping operation Reshape(·) is applied to adjust the final features back to their original shape, as shown in formula (5):
[0042]
[0043] The output consists of enhanced multi-scale features composition.
[0044] Preferably, the attention mechanism integrates coordinate attention and global attention to enhance local details and global dependencies;
[0045] Coordinate attention: This mechanism separates the spatial dimensions including horizontal and vertical directions and generates a direction-sensitive attention map through global pooling, as shown in formula (6):
[0046]
[0047] Among them, Pool h and Pool w Represents horizontal and vertical pooling operations, respectively, a h and a w represents the attention weight of direction perception, Represents element-by-element multiplication; x i is the input feature map, Conv h and Conv w are the convolution operations in the horizontal and vertical directions respectively, σ represents the activation function, x ca is the weighted feature map of the final output;
[0048] Global attention: This mechanism calculates long-range dependencies between spatial regions and enhances feature interactions across the entire image. Global attention calculates attention weights through a structured multi-head self-attention mechanism.
[0049] The details are as follows:
[0050] The input features are first transformed through a convolution operation (Conv1) to obtain intermediate representations; subsequently, these intermediate representations are projected into queries (Q), keys (K), and values (V), as shown in formula (7):
[0051] [Q,K,V]=Conv1(X) (7);
[0052] The calculation method of multi-head scaling dot product attention is shown in formula (8):
[0053]
[0054] Among them, Q represents the query vector (Query), K represents the key vector (Key), V represents the value vector (Value), d k Indicates the dimension of the key vector; Softmax is an activation function used to convert the calculation results into probability distribution. Multiple attention heads (head1,…,head n ) are concatenated and then a learnable projection matrix w is used proj Linearly project back to the original feature space, as shown in formula (9):
[0055] X attn =Concat(head1,…,head n )w proj . (9);
[0056] Among them, X attnIt represents the output features after multi-head scaled dot product attention calculation and projection. Concat represents the splicing operation, which splices the outputs of multiple attention heads according to a specific dimension.
[0057] Preferably, the multi-scale attention module adopts a feature pyramid structure in which multi-resolution features are integrated; specifically, as follows:
[0058] First, the input features are processed by the receptive field module to enhance the multi-scale feature extraction capability. Then, the features are processed differently according to their scale: the first three features are processed by the coordinate attention mechanism, while the fourth feature is processed by the global attention mechanism.
[0059] The mathematical expression of the multi-scale attention module is shown in formula (10):
[0060]
[0061] Among them, x i It is the feature after the receptive field module RFB operation, F1, F2, and F3 are the results of applying the coordinate attention mechanism CoordAtt to the first three features, and F4 is the fourth feature processed by the global attention mechanism GlobalAtt.
[0062] Preferably, the decoder includes a partial convolution module and a perception calibration module; wherein,
[0063] Partial convolution is configured to extract features during upsampling and dynamically fill invalid areas to make the upsampled features more stable;
[0064] The perception calibration module is configured to further adjust the feature distribution to enhance the model's perception ability of the target area.
[0065] The internal calculation mathematical expression of the adaptive feature enhancement module is shown in formula (12):
[0066] F′ i =PCB(Concat(F i ,Up(F i+1 ))) (12);
[0067] Among them, F i Represents the features of the current level, F′ i represents the upsampled features, Concat(·) represents the feature concatenation operation, Up(·) represents the bilinear interpolation upsampling operation, and PCB(·) represents the calibration of the fused feature distribution;
[0068] Through the hierarchical feature fusion of the adaptive feature enhancement module, the decoder not only retains low-level detail information, but also utilizes high-level features to enhance the understanding of the context.
[0069] In addition, the present invention also provides a method for detecting surface defects of industrial products based on a segmentation model. The method adopts the above-mentioned system for detecting surface defects of industrial products based on a segmentation model, and specifically includes the following steps:
[0070] Step 1: Extract multi-scale features by adapting the encoder and optimize the feature representation using its dual adapter;
[0071] Step 2: Scale-aware feature attention perceptron is used to fuse multi-scale features and combine coordinate attention with global attention to enhance defect sensitivity.
[0072] Step 3: Use the decoder to gradually restore the resolution and optimize the boundary segmentation accuracy through cross-layer feature compensation;
[0073] Step 4: Generate the final defect mask based on the multi-scale supervision strategy and train the model through the comprehensive loss function.
[0074] Preferably, in step 4, the specific implementation of the multi-scale supervision strategy is as follows:
[0075] Step 4.1: Generate the final segmentation mask S1 through the main prediction branch: After the adaptive feature enhancement module restores the highest resolution features layer by layer, the main prediction result S is generated, which is also the final output segmentation mask. Its calculation mathematical expression is shown in formula (13):
[0076] S1 = σ(Conv1(F4)) (13);
[0077] Where F4 represents the highest resolution feature obtained after processing by the adaptive feature enhancement module, σ(·) represents the sigmoid activation function, which is used to convert the convolution output into a probability value between 0 and 1, reflecting the probability that the pixel belongs to the target category, and Conv1(·) represents the 1×1 convolution layer used to generate the final segmentation result. The feature is transformed through the convolution operation to obtain the segmentation mask.
[0078] Step 4.2: Generate side outputs S2 and S3 at the intermediate level through auxiliary prediction branches and fuse them through progressive upsampling: During the decoding process, auxiliary prediction branches are introduced at multiple levels to generate corresponding segmentation results S2 and S3 at scales F2′ and F3′ respectively. The calculation formula is shown in formula (14):
[0079]
[0080] Among them, F2′ and F3′ respectively represent the feature scales of different intermediate levels in the decoding process, which are the input features of the auxiliary prediction branch; Conv1(·) represents a 1×1 convolution operation, which is used to transform the input features and extract relevant information to generate preliminary segmentation results; Up(·) represents an upsampling operation, which increases the resolution of the feature map after convolution to a suitable size; σ(·) represents a sigmoid activation function, which converts the upsampled result into a probability value between 0 and 1, representing the probability that the pixel belongs to the target category, thereby obtaining the final side segmentation outputs S2 and S3.
[0081] The beneficial technical effects brought about by the present invention are:
[0082] This paper successfully applies the Segment Everything Model (SAM) to industrial defect detection tasks through a dual-adapter strategy. A scale-aware feature attention perceptron (SFAP) is designed to enhance the sensitivity of defect detection by fusing Transformer-based multi-scale features with a hybrid attention mechanism. An efficient decoder containing adaptive feature enhancement modules (AFEMs) is constructed, which optimizes boundary detection capabilities through local convolution and cross-layer compensation, significantly surpassing traditional defect detection methods and improving the model's robustness to small defects and complex backgrounds. Experimental results show that SDDNet outperforms the comparison model on the SD-Saliency-900 dataset, and the dual adapters only fine-tune 1.8% of the SAM model's parameters, achieving optimal key indicators. This research provides an efficient and accurate solution for industrial defect detection and has important engineering application value.
[0083] A novel dual-adapter architecture (Prompt+Bottleneck) was introduced, which achieved efficient adaptation of SAM2 to industrial defect detection tasks by freezing the backbone network and fine-tuning only 1.8% of the parameters. This strategy shortened the training time by 82% and improved the model stability (mean absolute error (MAE) was reduced by 10.23% compared with the baseline), effectively solving the parameter redundancy problem of SAM2. In the SD-Saliency-900 benchmark test, this lightweight design achieved optimal performance with a MAE index of 0.0270, providing a new paradigm for deploying visual base models in resource-constrained industrial scenarios.
[0084] We propose a scale-aware feature attention perceptron (SFAP), which introduces an attention-guided hierarchical fusion mechanism to address the scale variation problem in unimodal RGB input. By fusing Transformer-based multi-scale aggregation, coordinate attention (CoordAtt) and global attention (GlobalAtt), SFAP improves the S-measure (S m) indicator increased by 2.8%, significantly enhancing the model’s ability to handle low-contrast defect detection challenges.
[0085] An efficient decoder using partial convolution and cross-layer feature compensation is developed, which reduces the computational cost by 34% while retaining 95.2% of the details of sub-millimeter defects. Compared with the traditional UNet decoder, the adaptive feature enhancement module (AFEM) makes the weighted F-value (F w ) is improved by 2.1%, effectively solving the boundary ambiguity problem in defect segmentation. This design strikes a balance between lightweight computation and high-precision boundary detection, which is critical for industrial quality control applications.
[0086] For surface defect detection, the proposed SDDNet innovatively improves upon SAM2, designing a scale-aware feature attention perceptron (SFAP) to optimize defect detection for pure RGB inputs. It also incorporates a cross-layer feature compensation mechanism and employs an adaptive feature enhancement module (AFEM) to improve boundary localization accuracy. By embedding dual adapters, the model enables efficient parameter fine-tuning, providing a highly efficient and adaptable solution for industrial surface defect detection.
[0087] Segmenting everything: The adapter proposed in this paper differs significantly from the improved method in terms of structure and functional characteristics. The first adapter adopts a relatively simple architecture, where prompt tokens generated by the sequential PromptLearn module are concatenated with the input features before being processed by the original network module.
[0088] The second adapter adopts a more complex design, integrating multiple initialization strategies and layer normalization techniques, with a carefully optimized dimensionality reduction-expansion process at its core. This process integrates three key components: (1) a nonlinear activation function for enhanced feature transformation, (2) a learnable scaling factor to support dynamic feature amplitude adjustment, and (3) an adaptive dropout rate for robust regularization. These adapters are seamlessly embedded in the hierarchical encoder block structure and work in conjunction with two core components: the scale-aware feature attention perceptron (SFAP) for refined feature extraction and the multi-scale attention block (MAB) for cross-scale context modeling. When dealing with complex low-level structure segmentation tasks, compared with traditional methods that simply focus on overall model performance improvement or architecture optimization, this invention shows unique advantages, especially in enhancing task-specific performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0089] Figure 1 This is the overall architecture diagram of SDDNet;
[0090] Figure 2It is the structural diagram of the encoder block and adapter;
[0091] Figure 3 This is the specific structure diagram of the scale-aware feature attention perceptron (SFAP);
[0092] Figure 4 This is the structural diagram of receptive field block (RFB). DETAILED DESCRIPTION
[0093] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments:
[0094] The SDDNet architecture proposed in this paper stands out for its simple design and high performance. Figure 1 As shown in Figure 2, the architecture consists of three core components: an encoder, a scale-aware feature attention perceptron (SFAP), and a decoder. It follows an "extract-enhance-fusion" workflow to achieve high-precision surface defect detection. For the input image, the encoder, based on the SAM2 model and optimized by an adapter, first extracts initial features, laying a solid foundation for subsequent processing. The SFAP module then enhances the feature representation using the adaptive feature enhancer (AFI), ensuring that even subtle defects are effectively rendered. The coordinate attention (CoordAtt) and global attention (GlobalAtt) modules optimize features by focusing on local and global spatial dependencies, avoiding missed detection of potential defects. The receptive field block (RFB) module further enriches multi-scale feature information, ensuring effective identification of defects of varying sizes. Finally, the decoder, equipped with an adaptive feature enhancement module (AFEM), integrates multi-scale features through a carefully designed upsampling fusion operation, outputting an accurate segmentation result that outlines the surface defect. The close collaboration between these components ensures the efficiency and robustness of SDDNet for surface defect detection.
[0095] SAM-based adaptive encoder
[0096] To effectively leverage the powerful visual representation capabilities of the Segment Everything Model v2 (SAM2) for industrial surface defect detection, we propose an adaptable encoder based on the SAM2 layered visual Transformer. Unlike traditional full-parameter fine-tuning methods, our solution integrates dual adapter modules within the SAM2 encoder, significantly enhancing feature extraction capabilities and computational efficiency.
[0097] like Figure 2 As shown, each hierarchical block (encoder block) of the SAM2 encoder is enhanced with two different adapter modules:
[0098] Multi-scale feature extraction encoder block: SAM2 encoder uses Hiera Blocks for multi-scale feature extraction, which effectively copes with the multi-scale variations of defects in industrial scenarios. Its hierarchical feature extraction process can be defined as:
[0099]
[0100] Among them, X i represents the features of the i-th level, T i represents the Transformer block, which can capture global context information more effectively.
[0101] Prompt Adapter: This adapter uses a simplified prompt learning architecture consisting of sequential linear transformations interspersed with GELU activation functions to dynamically generate task-specific prompt vectors. These prompt vectors are integrated with the original input features through point-wise addition to effectively highlight features related to subtle defects.
[0102] Formally, the adapter mechanism can be expressed as:
[0103]
[0104] Among them, W down 、W up is a learnable linear projection matrix, b down 、b up is the bias term, X represents the original input feature, X prompted is the output feature of the prompt adapter, '+' indicates element-by-element addition, P is the task-specific prompt vector dynamically generated by the prompt adapter, and GELU, or Gaussian Error Linear Unit, is an activation function that adaptively activates neurons based on the input data distribution, introducing nonlinear characteristics.
[0105] Bottleneck Adapter: To further enhance feature adaptation, we designed a bottleneck adapter that projects input features into a low-dimensional bottleneck space, applies GELU nonlinear activation and dropout layers for regularization, and then reconstructs the original feature dimensions. This adapter also incorporates learnable scaling factors and layer normalization to improve model stability and feature representation.
[0106] This can be formalized as follows:
[0107]
[0108] Among them, W down 、Wup is a learnable linear projection matrix, b down 、b up is the bias term, X bottleneck Represents the output features of the bottleneck adapter, and Z is the intermediate feature representation in the bottleneck adapter calculation process; Dropout is a regularization technique that sets the neuron output to zero with a certain probability during training to prevent overfitting; GELU, or Gaussian Error Linear Unit, is an activation function that adaptively activates neurons based on the input data distribution, introducing nonlinear characteristics.
[0109] By freezing the parameters of the original SAM2 backbone network and fine-tuning only the introduced dual adapters, we significantly reduced the number of trainable parameters to just 1.8%, effectively avoiding catastrophic forgetting and reducing computational cost by approximately 82%. This adapted encoder efficiently transfers the general representation capabilities of SAM2 to the specific scenario of industrial defect detection, generating highly discriminative features for accurate mask decoding.
[0110] Scale-Aware Feature Attention Perceptron (SFAP)
[0111] Scale-aware feature attention perceptron (SFAP) is a core component for high-precision industrial surface defect detection. Figure 3 As shown in Figure 2, SFAP integrates multi-scale feature enhancement and attention mechanisms to strengthen feature representation. By leveraging receptive field structure, adaptive feature optimization, and multi-scale attention, it effectively improves the model's ability to capture defects of different scales and complex morphologies.
[0112] The following is a detailed breakdown of the module and the derivation of the formula.
[0113] Receptive Field Module (RFB Module): An improved receptive field module (RFB) is introduced in industrial surface defect detection to effectively capture defect features of different scales. Figure 4 As shown in Figure 3, this module enhances feature extraction by leveraging multi-branch convolutions with different receptive fields (RFs). Inspired by the relationship between receptive field size and eccentricity in the human visual system, it improves feature discriminability by modeling multi-scale contextual information. Unlike the three-branch structure commonly used in traditional receptive field modules (RFBs), our proposed design adopts a four-branch convolutional structure with different dilation rates (r = 1, 3, 5, 7), which enables it to cover a wider range of receptive fields and better adapt to defects of different sizes.
[0114] Structurally, we employ four branches, each using convolution kernels with different dilation rates: 1×1 (dilation rate r=1), 3×3 (dilation rate r=3), 5×5 (dilation rate r=5), and 7×7 (dilation rate r=7). This extracts multi-scale contextual information from local to global perspectives. After concatenating the features from each branch, a 1×1 convolution is used to compress the channel dimension, and residual connections are used to enhance feature representation. The mathematical expression is as follows:
[0115]
[0116] Among them, x1, x2, x3, x4 are the outputs of the four branches, Conv1 represents a 1×1 convolution operation, and f represents the original input feature; Concat refers to splicing the outputs of the four branches into x in a specific dimension. cat , ReLU is the activation function f(x) = max(0,x), which is used to introduce nonlinearity and alleviate the disappearance of gradient, x out It is the final output feature of the receptive field module.
[0117] Adaptive Feature Enhancer (AFI): Figure 3 As shown in Figure 1, the Adaptive Feature Enhancer (AFI) utilizes the Transformer mechanism and cross-scale feature fusion to optimize feature representation. First, multi-scale features are projected into a 256-dimensional space using a projection function (Proj(·)). Then, they are optimized through multiple layers of Transformer modules. Finally, they are mapped back to the original channel dimension through the output convolutional layer (OutConv(·)). A reshape operation (Reshape(·)) is then applied to resize the final features back to their original shape.
[0118] It can be expressed as:
[0119]
[0120] The output consists of enhanced multi-scale features These features will be further processed in subsequent steps.
[0121] Attention mechanism: such as Figure 3 As shown in Figure 3, the attention mechanism integrates coordinate attention (CoordAtt) and global attention (GlobalAtt) to enhance local details and global dependencies.
[0122] CoordAtt: This mechanism separates the spatial dimensions (horizontal and vertical directions) and generates a direction-sensitive attention map through global pooling. Its formula is as follows:
[0123]
[0124] Among them, Pool h and Pool w Represents horizontal and vertical pooling operations, respectively, a h and a w represents the attention weight of direction perception, Represents element-by-element multiplication; x i is the input feature map, Conv h and Conv w are the convolution operations in the horizontal and vertical directions respectively, σ represents the activation function, x ca is the weighted feature map of the final output.
[0125] Global Attention (GlobalAtt): This mechanism computes long-range dependencies between spatial regions, thereby enhancing feature interactions across the entire image. Global Attention (GlobalAtt) computes attention weights via a structured multi-head self-attention (MHSA) mechanism.
[0126] Specifically, the input features are first transformed through a convolution operation (Conv1) to obtain intermediate representations. Subsequently, these intermediate representations are projected into queries (Q), keys (K), and values (V):
[0127] [Q,K,V]=Conv1(X). (7)
[0128] Then, the multi-head scaled dot-product attention is calculated as follows:
[0129]
[0130] Among them, Q represents the query vector (Query), K represents the key vector (Key), V represents the value vector (Value), d k Indicates the dimension of the key vector; Softmax is an activation function used to convert the calculation results into probability distribution. Multiple attention heads (head1,…,head n ) are concatenated and then a learnable projection matrix W is used proj Linearly project back to the original feature space, as shown in formula (9):
[0131] X attn =Concar(head1,…,head n )W proj . (9);
[0132] Among them, X attn It represents the output features after multi-head scaled dot product attention calculation and projection. Concat represents the splicing operation, which splices the outputs of multiple attention heads according to a specific dimension.
[0133] Through this structured attention mechanism, global contextual information across multiple scales can be effectively captured, significantly enhancing the representation ability of multi-scale features.
[0134] Multi-scale Attention Module (MAB): Figure 3 As shown in Figure 3, the Multi-Scale Attention Module (MAB) dynamically aggregates features from different layers, significantly improving the model's robustness to defect scale variations. This module integrates the Multi-Head Self-Attention Mechanism (MHSA) to capture local fine-grained details and global contextual dependencies.
[0135] The Multi-scale Attention Module (MAB) adopts a feature pyramid structure in which multi-resolution features are integrated. Figure 3 As shown in the figure, the input features are first processed by the Receptive Field Module (RFB) to enhance multi-scale feature extraction. After this, the features are processed differently depending on their scale: the first three features are processed by the CoordAtt mechanism, while the fourth feature is processed by the GlobalAtt mechanism. This selective processing ensures that both local and global dependencies are effectively captured.
[0136] The mathematical expression of the multi-scale attention module (MAB) is as follows:
[0137]
[0138] Among them, x i These are the features after the Receptive Field Module (RFB) operation. F1, F2, and F3 are the results of applying the CoordAtt mechanism to the first three features. The GlobalAtt mechanism processes the fourth feature F4.
[0139] Decoder and loss calculation
[0140] In high-precision industrial surface defect detection, precise object segmentation is crucial for subsequent decision making. To fully leverage the multi-scale features extracted by the encoder, an efficient adaptive feature enhancement module (AFEM) was designed as a decoder. Its core goal is to gradually restore spatial resolution and fuse semantic information at different levels. Furthermore, to further optimize the model's predictive capabilities, a comprehensive loss function was designed to improve segmentation accuracy and enhance the model's generalization capabilities.
[0141] Decoder based on Adaptive Feature Enhancement Module (AFEM): In industrial surface defect detection tasks, the AFEM decoder plays a key role due to its unique hierarchical feature fusion method. Figure 1As shown in the figure, the AFEM module is applied to each stage of the decoder. Through multiple AFEM modules, high-level features are gradually transferred to low-level features, achieving a deep fusion of deep semantic information and shallow detail information, which is completely different from the traditional U-net structure. During operation, the AFEM module first upsamples the low-resolution features of the upper decoder, and then fuses them with the high-resolution features of the corresponding layer of the encoder through skip connections, restoring the output resolution in an orderly layer-by-layer manner. In addition, the AFEM decoder significantly improves the accuracy of the segmentation results with the help of the optimized features extracted by the scale-aware feature attention perceptron (SFAP). In addition, the partial convolution (Partial Conv) and perception calibration module (PCB) introduced by the AFEM module can efficiently integrate multi-level information, balance performance and computational cost, and provide strong support for the accurate detection of industrial surface defects.
[0142] To efficiently reconstruct high-resolution defect masks in industrial surface defect detection, the AFEM decoder employs a multi-scale feature aggregation mechanism. The hierarchical feature maps extracted by the encoder are progressively upsampled and fused using a multi-scale upsampling module (AFEM). Compared to traditional bilinear interpolation upsampling, AFEM more adaptively fuses feature information from different layers, preserving both high-level semantic information and fine-grained local details.
[0143] Specifically, AFEM employs a strategy based on feature fusion and feature calibration to enhance boundary information in defect areas. Each AFEM module consists of a partial convolution (Partial Conv) and a perception calibration module (PCB). During operation, the partial convolution not only extracts features during upsampling but also dynamically fills in invalid areas, making the upsampled features more stable. The perception calibration module further adjusts the feature distribution to enhance the model's perception of the target area.
[0144] The decoder's processing of feature maps can be formally expressed as follows:
[0145]
[0146] Among them, AFEM represents the adaptive feature enhancement module, W head represents a 1×1 convolution operation, and σ is the Sigmoid activation function.
[0147] The internal calculation method of the Adaptive Feature Enhancement Module (AFEM) can be expressed as:
[0148] F′ i =PCB(Concat(F i ,Up(F i+1))), (12);
[0149] Among them, F′ i represents the upsampled features, Concat(·) represents the feature concatenation operation, Up(·) represents the bilinear interpolation upsampling operation, and PCB(·) is responsible for calibrating the distribution of the fused features.
[0150] Through hierarchical feature fusion in the Adaptive Feature Enhancement Module (AFEM), this decoder not only preserves low-level details but also utilizes high-level features to enhance context understanding.
[0151] Multi-scale segmentation prediction: To enhance the adaptability of prediction results in multi-scale scenarios, a multi-scale supervision strategy is adopted. This strategy generates prediction results at different levels and fuses these results through progressive upsampling. The specific implementation is as follows:
[0152] Main prediction branch (final output): After the adaptive feature enhancement module (AFEM) restores the highest resolution features layer by layer, the main prediction result S is generated. This is also the segmentation mask output by the network, and its calculation formula is as follows:
[0153] S1=σ(Conv1(F4)), (13)
[0154] Among them, F4 represents the highest resolution feature obtained after processing by the adaptive feature enhancement module, σ(·) represents the sigmoid activation function, which is used to convert the convolution output into a probability value between 0 and 1, reflecting the probability that the pixel belongs to the target category, and Conv1(·) represents the 1×1 convolution layer used to generate the final segmentation result. The feature is transformed through the convolution operation to obtain the segmentation mask.
[0155] Auxiliary prediction branch (side output): During the decoding process, in order to achieve intermediate supervision, we introduced auxiliary prediction branches (side output) at multiple levels. The corresponding segmentation results S2 and S3 are generated at scales F2′ and F3′ respectively. The calculation formula is as follows:
[0156]
[0157] Loss calculation: Weighted intersection-over-union (IoU) loss and binary cross entropy (BCE) loss are used as training objectives.
[0158] Loss Function The expression is as follows:
[0159]
[0160] in, and They represent weighted intersection-over-union (IoU) loss and weighted binary cross entropy (BCE) loss, respectively.
[0161] In addition, deep supervision is applied to all intermediate segmentation outputs S i Specifically, for the SDDNet architecture, the total loss Defined as:
[0162]
[0163] Among them, GT represents the true label, S i Represents the segmentation prediction results under different supervision levels. This formula plays a vital role in guiding the model training process.
[0164] experiment
[0165] Experimental setup
[0166] Dataset: To verify the effectiveness of SDDNet, an experimental evaluation was conducted on the SD-Saliency-900 dataset related to steel. Following the experimental settings of EDRNet, the dataset was divided into a training set (540 images) and a test set (360 images).
[0167] Evaluation indicators: A variety of evaluation indicators are used, including S-measure (S m ), maximum F-measure (F max ), maximum E-measure(E max ), weighted F-measure (F w ) and mean absolute error (MAE). In addition, the computational efficiency of the model is evaluated in terms of parameter size (Params) and floating-point operations (FLOPs).
[0168] Implementation details: During both training and testing, input images are uniformly resized to 352×352 pixels. To enhance the generalization ability of the model and mitigate overfitting, a multi-dimensional data augmentation strategy is employed, including random horizontal and vertical flipping, random rotation within 30 degrees, and dynamic boundary cropping. The pre-trained Hiera-L variant of SAM2 is used as the backbone network for feature extraction. During training, the Adam optimizer is used to update the model parameters, with an initial learning rate of 1×10 -3 , with a batch size of 8. The proposed model is implemented using the PyTorch framework and trained for 400 epochs. All experiments are performed on a single NVIDIA GTX A6000 GPU.
[0169] Comparison with SOTA methods
[0170] To fully validate the effectiveness of the proposed SDDNet model and considering the current lack of benchmark methods in the field of surface defect detection, a cross-domain comparative evaluation framework was introduced, integrating 10 mainstream algorithms for salient object detection and camouflaged object detection. To ensure the reliability and fairness of the comparison results, all predictions from these baseline methods were obtained by strictly adhering to their original experimental settings, reproducing and retraining them based on their publicly available source code. Table 1 shows a quantitative evaluation of 10 state-of-the-art (SOTA) models. Bold and italic underlined characters indicate the best and second-best results, respectively.
[0171] Table 1
[0172]
[0173] 1) Quantitative Evaluation: Table 1 shows the quantitative performance comparison of the proposed SDDNet model with 10 state-of-the-art (SOTA) methods on the SD-Saliency-900 dataset. The experimental results clearly show that SDDNet achieves superior performance on multiple evaluation metrics. Specifically, compared with the second best performing method, SDDNet reduces the mean absolute error (MAE) by 5.3% and increases the maximum F-index (F max ), the maximum E index (E max ), S index (S m ) and weighted F index (F w ) are improved by 1.2%, 0.9%, 1.3% and 1.7%. These improvements verify the effectiveness and robustness of the proposed model in surface defect detection research.
[0174] 2) Qualitative evaluation: Visualization results of SDDNet on the SD-SALIENCY-900 dataset. Specifically, three challenging scenarios are highlighted: low-contrast defects (rows 1 to 2, inclusions, with embedded foreign matter), irregular defect edges (rows 3 to 4, patches, with local abnormal features), and dense defect distributions (rows 5 to 6, scratches, showing linear damage). Qualitative analysis shows that traditional non-generative methods produce blurred contours, severe under-segmentation, and poor detail retention. In contrast, SDDNet effectively solves the over-segmentation problem through multi-scale feature enhancement, attention mechanism, and efficient decoder design. This enables it to accurately detect subtle features while maintaining structural integrity. These results verify the superiority of this method in complex industrial inspection scenarios.
[0175] Ablation studies
[0176] Table 2 shows the ablation experiment results of each module. Bold fonts indicate the best results.
[0177] Table 2
[0178]
[0179] (1) Effectiveness of components: In order to evaluate the contribution of each component to the SDDNet model, ablation experiments were conducted on the SD-Significance-900 dataset. The baseline model consists of a Hiera-L backbone network and a basic convolutional layer, and is gradually optimized by gradually adding components such as dual adapters, multi-scale feature enhancement, attention perception (SFAP), and adaptive feature enhancement (AFEM) modules. The experimental results in Table 2 show that with the addition of each module, the model performance gradually improves. Specifically, the complete SDDNet model outperforms the baseline model in several key indicators: the mean absolute error (MAE) is reduced by 21.1%, the maximum F index (F max ) increased by 4.3%, and the maximum E index (E max ) increased by 2.2%, S index (S m ) rose by 3.3%, and the weighted F index (F w ) increased by 5.4%. These results confirm the effectiveness of the individual modules and their synergistic effect on the backbone network, demonstrating the advantages of this model design in surface defect detection tasks.
[0180] (2) Effectiveness of the backbone network: Through the ablation study of different backbone networks in SDDNet, Table 1 reveals significant differences in model efficiency and performance. When using the Hiera-L backbone network, the model of this application achieves the best balance, with 219.32 million parameters (219.32M Params) and 147.77 billion floating-point operations (147.77GFLOPs). At the same time, it performs well in various indicators: the mean absolute error MAE is 0.0270, the maximum F index F max The maximum E index is 0.8720. max is 0.9592, S index S m is 0.8807, and the weighted F index F w Compared with other configurations, the Hiera-L version has a m The performance is 2.13% higher than that of the backbone network based on Res2Net (49.86 million parameters / 18.86 billion floating point operations, i.e. 49.86M Params / 18.86G FLOPs). w The index is 3.59% higher; mThe performance is 1.21% higher than the backbone network based on PVT-B2 (parameters 28.59 million / floating point operations 16.7 billion times, i.e. 28.59M Params / 16.7GFLOPs). w The performance of the Hiera-L network was 1.89% higher than that of the MINet network. This demonstrates that despite the high computational cost of the Hiera-L backbone network, it has an excellent ability to extract discriminative features. Furthermore, replacing the backbone network with the MI-based backbone network reduced the number of model parameters to 3.89M. Although slightly larger than the number of parameters of MINet, the performance is still better than MINet.
[0181] SDDNet has achieved the best performance on the SD-Saliency-900 dataset, with a mean absolute error (MAE) of 0.0270 and an S index (S m ) is 0.8807, surpassing 10 current state-of-the-art methods, which proves its superiority in industrial surface defect detection. The hierarchical design that integrates attention perception (SFAP) and adaptive feature enhancement (AFEM) modules effectively solves the problems of multi-scale perception and boundary ambiguity, and the accuracy of defect localization is significantly improved compared with the traditional UNet decoder. By embedding the dual adapter in the SAM2 backbone network, the dual adapter of SDDNet only fine-tunes 1.8% of the parameters of SAM2, which greatly reduces the training time. The model can be deployed on edge devices while maintaining the weighted F index (F w ) is 0.8482, validating its practicality in resource-constrained industrial scenarios. The synergistic effect between hierarchical feature compensation and the attention mechanism demonstrates the critical importance of explicit multi-scale modeling for defect detection. Surprisingly, the inclusion of bottleneck adapters demonstrates a significant contribution to model stability, suggesting a parameter-efficient strategy with high value for money (VFM).
[0182] Of course, the above description is not a limitation of the present invention, and the present invention is not limited to the above examples. Changes, modifications, additions or substitutions made by technicians in this technical field within the essential scope of the present invention should also fall within the scope of protection of the present invention.
Claims
1. An industrial product surface defect detection system based on a segmentation model, characterized in that: It includes an adaptive encoder, a scale-aware feature attention sensor, and a decoder; wherein, An adaptive encoder, integrated with a dual adapter module, configured to perform multi-scale feature extraction; A scale-aware feature attention sensor is configured to fuse multi-scale features with a hybrid attention mechanism and enhance feature representation through an adaptive feature enhancer, ensuring that even subtle defects can be effectively presented; The decoder, using an adaptive feature enhancement module, is configured to gradually restore the spatial resolution and fuse semantic information at different levels.
2. The industrial product surface defect detection system based on the segmentation model according to claim 1 is characterized in that: Adaptive encoder, including prompt adapter and bottleneck adapter; wherein, The prompt adapter is configured to dynamically generate task-specific prompt vectors and integrate them with the original input features through point-by-point addition. The mechanism of the prompt adapter is shown in formula (2): Among them, W down 、W up is a learnable linear projection matrix, b down 、b up is the bias term, X represents the original input feature, X prompted is the output feature of the prompt adapter, P is the task-specific prompt vector dynamically generated by the prompt adapter, and GELU, or Gaussian Error Linear Unit, is an activation function that adaptively activates neurons based on the input data distribution, introducing nonlinear characteristics; The bottleneck adapter is configured to enhance feature adaptation capabilities; specifically: Project the input features into a low-dimensional bottleneck space, apply GELU nonlinear activation and dropout layers for regularization, and reconstruct the original feature dimensions; integrate learnable scaling factors and layer normalization to improve model stability and feature expression capabilities; The mathematical expression of the bottleneck adapter is shown in formula (3): Among them, W down 、W up is a learnable linear projection matrix, b down 、b up is the bias term, X represents the original input feature, X prompted is the output feature of the prompt adapter, and P is the task-specific prompt vector dynamically generated by the prompt adapter.
3. The industrial product surface defect detection system based on the segmentation model according to claim 1 is characterized in that: Scale-aware feature attention sensor, including receptive field module, adaptive feature enhancer, attention mechanism and multi-scale attention module; among them, Coordinate attention and global attention modules; among them, A receptive field module configured to enhance feature extraction capability by utilizing multi-branch convolutions with different receptive fields; An adaptive feature enhancer configured to optimize feature representation using the Transformer mechanism and cross-scale feature fusion; The attention mechanism is configured to enhance local details and global dependencies, optimize features, and avoid missing potential defects; The multi-scale attention module is configured to dynamically aggregate features from different levels. The module integrates a multi-head self-attention mechanism to capture local fine-grained details and global contextual dependencies.
4. The industrial product surface defect detection system based on the segmentation model according to claim 3 is characterized in that: The receptive field module adopts a four-branch convolution structure with different expansion rates. Each branch uses a convolution kernel with a different expansion rate, and the expansion rate is r = 1, 3, 5, and 7. The convolution kernel with expansion rate r = 1 is 1×1, the convolution kernel with expansion rate r = 3 is 3×3, the convolution kernel with expansion rate r = 5 is 5×5, and the convolution kernel with expansion rate r = 7 is 7×7. It extracts multi-scale context information from local to global. After splicing the features of each branch, the channel dimension is compressed by 1×1 convolution, and the residual connection is used to enhance the feature expression ability. Its mathematical expression is shown in formula (4): Among them, x1, x2, x3, x4 are the outputs of the four branches, Conv1 represents a 1×1 convolution operation, and f represents the original input feature; Concat refers to splicing the outputs of the four branches into x in a specific dimension. cat , ReLU is the activation function f(x) = max(0,x), which is used to introduce nonlinearity and alleviate the disappearance of gradient, x out It is the final output feature of the receptive field module.
5. The industrial product surface defect detection system based on the segmentation model according to claim 3 is characterized in that: The adaptive feature enhancer uses the Transformer mechanism and cross-scale feature fusion to optimize feature representation. Specifically, the multi-scale features are first projected into a 256-dimensional space through the projection function Proj(·). Then, they are optimized through multiple layers of Transformer modules and finally mapped back to the original channel dimension through the output convolution layer OutConv(·). A reshaping operation Reshape(·) is then applied to adjust the final features back to their original shape, as shown in formula (5): The output is composed of enhanced multi-scale features composition.
6. The industrial product surface defect detection system based on the segmentation model according to claim 3 is characterized in that: The attention mechanism integrates coordinate attention and global attention to enhance local details and global dependencies; Coordinate attention: This mechanism separates the spatial dimensions including horizontal and vertical directions and generates a direction-sensitive attention map through global pooling, as shown in formula (6): Among them, Pool h and Pool w Represents horizontal and vertical pooling operations, respectively, a h and a w represents the attention weight of direction perception, Represents element-by-element multiplication; x i is the input feature map, Conv h and Conv w are the convolution operations in the horizontal and vertical directions respectively, σ represents the activation function, x ca is the weighted feature map of the final output; Global attention: This mechanism calculates long-range dependencies between spatial regions and enhances feature interactions across the entire image. Global attention calculates attention weights through a structured multi-head self-attention mechanism. The details are as follows: The input features are first transformed through a convolution operation to obtain an intermediate representation: [Q,K,V]=Conv1(X) (7); The calculation method of multi-head scaling dot product attention is shown in formula (8): Among them, Conv1 represents the convolution operation, Q represents the query vector, K represents the key vector, V represents the value vector, and d k Represents the dimension of the key vector; Softmax is the activation function used to convert the calculation result into a probability distribution; the outputs of multiple attention heads are connected and then a learnable projection matrix W is used proj Linearly project back to the original feature space, as shown in formula (9): X attn =Concat(head1,…,head n )W proj (9); Among them, X attn Represents the output features after multi-head scaling dot product attention calculation and projection; head1,…,head n Represents multiple attention heads; Concat represents a concatenation operation, which concatenates the outputs of multiple attention heads according to a specific dimension.
7. The industrial product surface defect detection system based on the segmentation model according to claim 3 is characterized in that: The multi-scale attention module adopts a feature pyramid structure in which multi-resolution features are integrated; specifically: First, the input features are processed by the receptive field module to enhance the multi-scale feature extraction capability. Then, the features are processed differently according to their scale: the first three features are processed by the coordinate attention mechanism, while the fourth feature is processed by the global attention mechanism. The mathematical expression of the multi-scale attention module is shown in formula (10): Among them, x i It is the feature after the receptive field module RFB operation, F1, F2, and F3 are the results of applying the coordinate attention mechanism CoordAtt to the first three features, and F4 is the fourth feature processed by the global attention mechanism GlobalAtt.
8. The industrial product surface defect detection system based on the segmentation model according to claim 1 is characterized in that: The decoder includes a partial convolution module and a perceptual calibration module; wherein, Partial convolution is configured to extract features during upsampling and dynamically fill invalid areas to make the upsampled features more stable; The perception calibration module is configured to further adjust the feature distribution to enhance the model's perception ability of the target area. The internal calculation mathematical expression of the adaptive feature enhancement module is shown in formula (12): F′ i =PCB(Concat(F i ,Up(F i+1 ))) (12); Among them, F i Represents the features of the current level, F′ i represents the upsampled features, Concat(·) represents the feature concatenation operation, Up(·) represents the bilinear interpolation upsampling operation, and PCB(·) represents the calibration of the fused feature distribution; Through the hierarchical feature fusion of the adaptive feature enhancement module, the decoder not only retains low-level detail information, but also utilizes high-level features to enhance the understanding of the context.
9. A method for detecting surface defects of industrial products based on a segmentation model, characterized in that: The industrial product surface defect detection system based on the segmentation model as claimed in claim 1 specifically includes the following steps: Step 1: Extract multi-scale features by adapting the encoder and optimize the feature representation using its dual adapter; Step 2: Scale-aware feature attention perceptron is used to fuse multi-scale features and combine coordinate attention with global attention to enhance defect sensitivity. Step 3: Use the decoder to gradually restore the resolution and optimize the boundary segmentation accuracy through cross-layer feature compensation; Step 4: Generate the final defect mask based on the multi-scale supervision strategy and train the model through the comprehensive loss function.
10. The industrial product surface defect detection method based on the segmentation model according to claim 9 is characterized in that: In step 4, the specific implementation of the multi-scale supervision strategy is as follows: Step 4.1: Generate the final segmentation mask S1 through the main prediction branch: After the adaptive feature enhancement module restores the highest resolution features layer by layer, the main prediction result S is generated, which is also the final output segmentation mask. Its calculation mathematical expression is shown in formula (13): S1 = σ(Conv1(F4)) (13); Where F4 represents the highest resolution feature obtained after processing by the adaptive feature enhancement module, σ(·) represents the sigmoid activation function, which is used to convert the convolution output into a probability value between 0 and 1, reflecting the probability that the pixel belongs to the target category, and Conv1(·) represents the 1×1 convolution layer used to generate the final segmentation result. The feature is transformed through the convolution operation to obtain the segmentation mask. Step 4.2: Generate side outputs S2 and S3 at the intermediate level through auxiliary prediction branches and fuse them through progressive upsampling: During the decoding process, auxiliary prediction branches are introduced at multiple levels to generate corresponding segmentation results S2 and S3 at scales F2′ and F3′ respectively. The calculation formula is shown in formula (14): Among them, F2′ and F3′ represent the feature scales of different intermediate levels in the decoding process, which are the input features of the auxiliary prediction branch.
Citation Information
Cited By
Pipeline defect magnetic flux leakage detection method and device based on multi-scale data driving deep learning
CN120992737A
Visual defect detection method based on multi-level Transform
CN121329967A