Lightweight detection method for small defect targets in complex industrial scene
The VisDefectNet network solves the problems of insufficient accuracy and low computational efficiency in small target detection, achieving high-precision and high-efficiency detection in complex industrial scenarios. It is applicable to the detection of various industrial defects such as steel surfaces, printed circuit boards, and composite materials.
Patent Information
- Application Number
- CN202511255800.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-04
- Publication Date
- 2025-12-23
AI Technical Summary
Existing industrial defect detection methods suffer from insufficient accuracy in small target detection, limited global dependency modeling capabilities, low computational efficiency, and foreground-background imbalance, making it difficult to achieve a balance between high accuracy and high efficiency in complex industrial scenarios.
The VisDefectNet network is adopted, which combines the Spatial Shift Channel Hybrid Module (SS-CMM), the Cross-Stage Partial Connectivity Sparse Attention Module (C2PSA-Topk), the Multi-Scale Convolutional Kernel Spatial Upsampling Module (MS-KSU), and the Adaptive Threshold Focus Loss Function (ATFLoss) to enhance the representation of small defect features, suppress background interference, restore detailed edges, and balance sample training.
It significantly improves the accuracy and robustness of small defect detection, reduces model complexity and computational load, meets the real-time and low-energy consumption requirements of industrial production lines, and has cross-scenario adaptability.
Smart Images

Figure CN121190920A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of target detection technology improvement and deep learning computer vision, in particular to a lightweight detection method for small defect targets in complex industrial scenes. BACKGROUND
[0002] Industrial defect detection, as a core link in intelligent manufacturing and quality control, plays an important role in ensuring product reliability, reducing production costs and improving industrial automation level. Through detection algorithms, various defects such as cracks on steel surfaces, open circuits on printed circuit boards (PCB), solder joint defects and pores in composite materials can be accurately identified and located from complex industrial images, thereby providing effective support for defect visualization, defect level evaluation and subsequent processing.
[0003] However, most current detection models still have the following problems:
[0004] Firstly, current mainstream target detection methods such as FasterR-CNN, YOLOv8 and YOLOv11 perform well in detecting regular objects, but when faced with small defect targets in industrial scenes with small size, irregular shape and complex background, the feature expression ability is insufficient, which is prone to miss detection and false detection.
[0005] Secondly, although the convolutional neural network (CNN) model can extract image features through multiple layers of convolution, it is difficult to capture long-range dependency information due to the fixed receptive field, resulting in insufficient perception of long-range context and global structure by the model; at the same time, the feature expression ability of shallow convolution is limited, which often cannot effectively highlight the fine-grained information of small defects.
[0006] Thirdly, in order to improve the detection ability of small targets, some researches introduce attention mechanisms or Transformer structures to enhance global modeling, but such methods usually bring high computational complexity, which is difficult to meet the real-time and lightweight requirements of industrial detection.
[0007] Fourthly, existing detection loss functions rely on fixed thresholds, and in the industrial defect detection task where the proportion of foreground and background samples is severely unbalanced, the model training process is often dominated by easy-to-classify samples, which weakens the attention to difficult-to-classify small defects.
[0008] In recent years, with the development of deep learning, YOLO series detectors are widely used in industrial defect detection due to their high efficiency and end-to-end characteristics. Methods such as YOLOv5 and YOLOv7 have achieved good detection performance through multi-scale feature fusion and lightweight module optimization. However, their convolutional neural network structures are still limited by fixed receptive fields, making it difficult to balance long-range dependencies and local detail modeling. On this basis, YOLOv8 and YOLOv11 further optimize the structure and inference speed, but the detection accuracy of very small defects is still not ideal. Some studies attempt to introduce Transformers or self-attention mechanisms to enhance global modeling capabilities, but these methods usually consume high computational resources, which is not conducive to deployment in actual industrial scenarios. In summary, existing methods still struggle to achieve an ideal balance between detection accuracy, lightweight, and real-time performance.
[0009] In summary, for the problems of small target modeling deficiency, weak fine-grained feature expression ability, insufficient global dependency capture, low computational efficiency, and foreground-background imbalance in the task of industrial defect detection, it is urgent to propose a lightweight detection network that balances global modeling and local detail enhancement to meet the dual demands of high accuracy and high efficiency in industrial scenarios. SUMMARY
[0010] The purpose of the present application is to provide a lightweight detection method for small defect targets in complex industrial scenarios, aiming to overcome the problems of insufficient small target detection accuracy, limited global dependency modeling capability, high computational cost, and foreground-background imbalance in training in existing industrial defect detection methods, while maintaining low computational complexity and high real-time performance, significantly improving small defect detection accuracy and robustness.
[0011] To achieve the above-mentioned purpose, the present application provides the following technical solutions: a lightweight detection method for small defect targets in complex industrial scenarios, at least comprising the following steps:
[0012] S1: Collect and construct an image dataset containing multiple types of typical industrial defects, and preprocess the original data, which at least includes uniform size, grayscale, and normalization, group and divide according to defect type, image clarity, and scene complexity, divide into training set, validation set, and test set;
[0013] S2: Build an improved lightweight detection network VisDefectNet based on YOLOv11s, which includes a spatial shift channel mixing module, a cross-stage partial connection sparse attention module, and a multi-scale convolution kernel spatial upsampling module, namely SS-CMM module, C2PSA-Topk module, and MS-KSU module, and combines an adaptive threshold focal loss function, namely ATFLoss;
[0014] S3: Train VisDefectNet using a stochastic gradient descent optimizer (SGD) with an initial learning rate of 0.01, a momentum of 0.937, a weight decay of 0.0005, 300-500 training epochs, a batch size of 16, and the defect image training set collected and processed in S1 to obtain the trained network weights;
[0015] S4: Input the test set described in S1 into the trained VisDefectNet to output the detection frame and category of the defect target, thereby achieving efficient detection of small defects in complex backgrounds.
[0016] Further, the industrial image data collected in S1 includes at least steel surface defects, printed circuit board (PCB) defects, and composite material defects. All images are processed into PNG format with a uniform resolution, and size scaling, pixel intensity normalization, and contrast enhancement are simultaneously performed to ensure consistency and detection accuracy of different data sources.
[0017] Further, the application of VisDefectNet includes a feature extraction stage, a global context modeling stage, and a detection prediction stage.
[0018] The feature extraction stage embeds a spatial shift channel mixing module in the YOLOv11s backbone to enhance the fine-grained expression of shallow features through channel grouping and multi-directional shift operations.
[0019] The global context modeling stage uses a cross-stage partial connection sparse attention module to enhance small target features and suppress background interference by combining spatial attention mechanisms and Top-k sparse screening.
[0020] The detection prediction stage introduces a multi-scale convolution kernel spatial upsampling module in the upsampling path to realize content-aware feature reconstruction, restore the edge details of small defects, and improve positioning accuracy. Meanwhile, an adaptive threshold focal loss function is used to alleviate the imbalance between foreground and background samples during the training process, thereby improving small target detection performance and network robustness.
[0021] Further, the SS-CMM module performs parameter-free spatial-channel reorganization at the shallow layer to preserve microstructure features.
[0022] The SS-CMM module divides the input features into several subgroups along the channel dimension, performs cyclic shift operations in the up-down and left-right directions respectively, and then concatenates them in the channel dimension to achieve parameter-independent spatial-channel feature reorganization, thereby enhancing the representation ability of shallow features for local fine-grained defects.
[0023] The shift operation in the SS-CMM module adopts a fixed convolution kernel size and a cyclic shift manner, without introducing additional trainable parameters, thereby reducing model complexity and improving inference speed.
[0024] Further, the cross-stage partial connection sparse attention module is used to suppress background noise by sparse attention region.
[0025] The C2PSA-Topk module introduces a Top-k sparse attention operator based on the spatial attention mechanism of the cross-stage partial connection structure, only retains the top-k largest response values of each query in the attention matrix, to suppress background noise and enhance small target feature response.
[0026] The attention calculation method of the C2PSA-Topk module is:
[0027]
[0028] Where τ k is a Top-k selection operator; λ is a scaling factor; Q, K, and V are query, key, and value matrices of the attention mechanism.
[0029] Further, the multi-scale kernel space upsampling module restores defective details through content-aware offset prediction.
[0030] The MS-KSU module includes a multi-scale offset prediction branch and a convolution kernel space generation branch. The input features are first compressed in channels by 1x1 convolution, and then enter the offset prediction and convolution kernel generation paths respectively to realize content-based adaptive upsampling.
[0031] The multi-scale offset prediction branch includes two parallel depth separable convolution branches with convolution kernel sizes of 5x5 and 7x7 respectively, and uses dilation rates of 2 and 3 to model medium-range and long-range context features, and finally generates a position offset map.
[0032] The convolution kernel space generation branch performs nonlinear transformation and normalization operations on the input features to generate content-aware convolution kernels, and combines them with the multi-scale offset map to realize spatial position adaptive feature sampling and reconstruction.
[0033] Further, the ATFLoss gives more attention to small targets in backpropagation, balancing the training process of objects of different scales.
[0034] The ATFLoss adaptive threshold focal loss function distinguishes between easy-to-classify background samples and difficult-to-classify defect samples by using a dynamic threshold, and uses an adjustable modulation factor to enhance attention to small target difficult examples, thereby alleviating the foreground-background sample ratio imbalance problem.
[0035] The definition of the ATFLoss is:
[0036] When the prediction probability pt≤0.5,
[0037]
[0038] When the prediction probability pt>0.5,
[0039]
[0040] where λ is a loss adjustment coefficient, and pt is a class prediction probability.
[0041] Further, the application process of the SS-CMM module at least includes the following steps:
[0042] The input feature map X is divided into 4 subgroups along the channel dimension.
[0043] A cyclic shift operation is performed on each subgroup, including upshift, downshift, left shift and right shift, with a shift amplitude of s pixels, defined as:
[0044] T i (X i )=Roll(X i ,s i ,dim=d i ),s i ∈{+s,-s},d i ∈{H,W}
[0045] The shifted features are concatenated along the channel dimension to obtain the output feature:
[0046]
[0047] The concatenated features are input into the C3K2 module of YOLOv11s, combined with multi-branch convolution and residual connection mechanism, to realize local detail enhancement and global context modeling.
[0048] The SS-CMM module is a parameter-independent structure, does not contain additional trainable convolution kernels, and only relies on fixed shift operation to realize spatial dependence enhancement, thereby reducing the model parameter quantity to 8.3M and improving the inference speed to 79FPS.
[0049] Further, the application process of the C2PSA-Topk module at least includes the following steps:
[0050] The input features are compressed in channels by 1×1 convolution.
[0051] Local spatial context features are extracted by 3×3 depth separable convolution.
[0052] The features are divided into three groups Q, K and V for attention calculation.
[0053] Top-k sparsification is performed on the attention matrix:
[0054]
[0055] where t i represents the k-th largest value in the j-th row.
[0056] Sparse attention is calculated:
[0057]
[0058] The attention output is added element-wise to the original features to achieve background suppression and small target response enhancement.
[0059] Compared with traditional CBAM or SE attention modules, the C2PSA-Topk module can improve the small target detection mAP by more than 1.5% without significantly increasing the computational load.
[0060] Further, the implementation steps of the MS-KSU module at least include the following steps:
[0061] The input features are compressed in channels by 1x1 convolution;
[0062] The compressed features are input into the multi-scale offset prediction branch and the convolution kernel generation branch respectively;
[0063] The offset prediction branch includes a 3x3 depth separable convolution and two parallel dilated convolution branches, with convolution kernels of 5x5 (dilation rate 2) and 7x7 (dilation rate 3) respectively, and the output offset mapping O offset .
[0064] O offset =Conv 1×1 (SiLU(Conv 1×1 (x)+Conv 1×1 (F multi ))
[0065] The convolution kernel generation branch performs nonlinear activation and normalization on the input features to generate spatially adaptive convolution kernels.
[0066] The offset mapping and the convolution kernel jointly act on feature sampling to achieve position-sensitive adaptive up-sampling.
[0067] Compared with the nearest neighbor up-sampling and CARAFE method, the MS-KSU module has better performance in small defect edge recovery, and the model's Recall on the PCB-DET dataset is improved to 96.0%.
[0068] Compared with the prior art, the present application has the beneficial effects that:
[0069] The method introduces a spatial shift operation and a layer-by-layer interaction mechanism in the feature channel through the SS-CMM module, realizes effective information fusion across channels and spaces, thereby enhancing the connection between local texture details and global context, and significantly improving the perception ability of subtle defects in complex backgrounds; in combination with the C2PSA-Topk sparse attention mechanism, dynamic selection and weighting of important features are realized in the channel and spatial domains, which not only suppresses the interference of redundant background, but also highlights the discriminative response of small defects, effectively improving the recognition accuracy of small-scale targets and fuzzy boundary defects; at the same time, the MS-KSU module introduces a multi-scale convolution and adaptive interpolation strategy in the upsampling stage, so that the feature recovery process can take into account both global structure and fine-grained details, ensuring the continuity and integrity of the defect area boundary.
[0070] In addition, the method adopts a lightweight network design, which significantly reduces the parameter quantity and computational complexity while maintaining detection accuracy, and the inference speed is significantly improved compared with mainstream detection models, which can meet the stringent requirements of real-time performance and low energy consumption on industrial production lines; with the help of the ATFLoss dynamic sample balancing strategy, the model can automatically adjust the learning weights of foreground defects and background samples, thereby alleviating the problems of class imbalance and insufficient learning of difficult samples, so that it still maintains stable performance in large-scale, multi-class industrial defect detection tasks.
[0071] More importantly, the method has good cross-scene and cross-modal adaptability. In the multi-modal images of steel surface defects, circuit board defects and other complex industrial materials, it can maintain high detection accuracy and stability. This adaptability not only comes from the modular feature modeling and efficient long-range dependency capture mechanism, but also benefits from the network's ability to optimize in multiple scales and across categories. As a result, the method has broad application prospects in industrial quality inspection, automated production monitoring, real-time defect diagnosis and other practical application scenarios, and can not only meet the deployment needs of resource-constrained edge terminals, but also has the potential to be promoted to larger-scale industrial detection systems. BRIEF DESCRIPTION OF DRAWINGS
[0072] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor on the basis of these drawings.
[0073] Figure 1 is a schematic diagram of the overall structure of the efficient defect target detection method of the present application;
[0074] Figure 2 A structural schematic diagram of a displacement mechanism (MS-CMM) module in an embodiment of the present application;
[0075] Figure 3 A structural schematic diagram of a kernel space up-sampling module (MS-KSU) in an embodiment of the present application;
[0076] Figure 4 A structural schematic diagram of a sparse attention module (C2PSA-TopK) in an embodiment of the present application;
[0077] Figure 5 A visualization result of the method of the present application on a PCB-DET dataset;
[0078] Figure 6 A visualization result of the method of the present application on a DsPCBSD+ dataset. DETAILED DESCRIPTION
[0079] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments.
[0080] At present, most industrial defect detection models are often designed and optimized for a single scene (such as steel surface or PCB board), and lack the general adaptation ability for multiple industrial defects and complex background across scenes. The performance of the model optimized for a single scene is significantly reduced in cross-scene application, which restricts its popularization and application in actual industrial environment. There are problems such as difficulty in accurately capturing small defects, significant background interference, insufficient global dependence modeling, poor up-sampling detail recovery ability, and unbalanced foreground-background samples in the current industrial defect detection field.
[0081] The present application provides a lightweight industrial defect detection method (referred to as VisDefectNet) which fuses a spatial shift channel mixing module (SS-CMM), a cross-stage partial connection sparse attention module (C2PSA-Topk), a multi-scale convolution kernel space up-sampling module (MS-KSU) and an adaptive threshold focal loss function (ATFLoss), and has efficient global context modeling and fine local feature capturing ability to meet the demand of real-time and high precision coexistence in industrial production. The method mainly includes four modules of data acquisition and preprocessing, network model construction, model training and model performance evaluation, and the specific implementation steps are as follows:
[0082] Step S1: data set preprocessing. Three industrial defect public data sets are used in this embodiment. The NEU-DET steel surface defect data set: contains 6 categories of steel surface defects, a total of 1,800 images, each image has a resolution of 200x200, including scratch, curl, crack, spot and other defect categories. The training set has 1,500 images, and the test set has 300 images. The PCB-DET printed circuit board defect data set: contains 6 categories of defects, 1,386 images, with a resolution of 640x640, the training set has 1,100 images, and the test set has 286 images. The DsPCBSD+ defect data set: contains about 10,000 industrial images with complex textures and multiple defect categories, used to verify the generalization ability of the model. Data preprocessing includes: scaling all images to a resolution of 640x640, using histogram equalization and Gamma correction to enhance contrast, normalizing pixel intensity to [0, 1], and using random rotation, flipping, and lighting disturbance for data augmentation on the training set to improve the model's robustness to complex industrial environments.
[0083] Step S2: the VisDefectNet proposed in this embodiment is improved based on the YOLOv11s backbone network, while maintaining a lightweight structure, embedding feature enhancement modules optimized for small defects layer by layer. The overall structure of the model is shown in Figure 1 , which mainly includes: encoder (Backbone): responsible for extracting multi-scale features; feature enhancement module (SS-CMM and C2PSA-Topk): used for shallow fine-grained enhancement and global context modeling, respectively; decoder (Neck+Head): multi-scale spatial upsampling is performed through MS-KSU, and different scale features are fused through jump connection; loss function: ATFLoss is used to improve the learning ability for small defects.
[0084] Step S21: SS-CMM module design, Figure 2 The architecture of the SS-CMM module is shown. In the shallow feature extraction stage, the locality of convolution operation easily causes the loss of fine-grained spatial information, thereby weakening the sensitivity to small defects. This module realizes spatial information mixing without introducing additional parameters, and enhances the modeling ability for small defects. The input feature is divided into 4 subgroups according to the channel dimension: Each subgroup is directionally shifted:
[0085] X1: move up s pixels
[0086] X2: move up s pixels
[0087] X3: move up s pixels
[0088] X4: move up s pixels
[0089] Mathematically represented as:
[0090] T(X i )=Roll(X i ,s i ,dim=d i )
[0091] Concatenate the shifted features:
[0092] Z=Concat(T(X1),T(X2),T(X3),T(X4))
[0093] Fuse the concatenated features with the input residual:
[0094] Y=Z+X
[0095] Maintain the computational load, enhance the diversity of small target features, and improve the sensitivity of the detection model to micro defects.
[0096] Step S22: C2PSA-Topk module design. Traditional attention mechanisms are easily disturbed by redundant information in complex backgrounds, especially in industrial scenarios where background textures are similar to defect textures, leading to an increase in false detection rates. Therefore, the present application proposes a Top-k sparsification strategy based on the CSP structure and spatial attention mechanism of YOLOv11s, as shown in Figure 4 , which only retains the most significant attention responses, thereby highlighting small defect regions and suppressing irrelevant backgrounds. The input features are first processed through convolution and normalization to obtain the initial feature representation; the spatial attention matrix
[0097] A=σ(Conv 1×1 (F))
[0098] Where σ(·) is the Sigmoid function;
[0099] Sparse the attention matrix A, retaining only the top k% largest values;
[0100]
[0101] Multiply the sparse attention map with the original feature element by element:
[0102] F ' =A ' ⊙F
[0103] Finally, fuse the output through the cross-stage partial connection (CSP) and residual mechanism:
[0104] Y=Concat(F ' ,F skip )
[0105] The most significant response position is reserved, redundant background interference is suppressed, global context modeling and local feature enhancement are considered, and the separability of small defects in a complex background is significantly improved.
[0106] Step S23: Structural design of MS-KSU module (see Figure 3 Traditional upsampling methods (such as bilinear interpolation and deconvolution) are prone to chessboard artifacts when recovering spatial resolution, and cannot fully utilize multi-scale context information, resulting in blurred small defect edges and missed defects. To address this deficiency, Figure Three The MS-KSU in the application models different receptive field features in parallel through multi-scale convolution kernels, and then combines spatial upsampling and channel shuffling to achieve gradual recovery and fusion of multi-scale information. Input processing: the current stage feature map Through 2 times upsampling operation:
[0107] X up =Up(X)
[0108] Multi-scale convolution kernel branch, applying multi-scale convolution kernels (3x3, 5x5, 7x7) to the upsampling feature X up , respectively, to obtain different receptive field features:
[0109] F k =DWConv k×k (X up ), k ∈ {3, 5, 7}
[0110] Recursive residual fusion: recursively fusing each branch in a residual manner:
[0111]
[0112] Channel shuffling and point-wise convolution: to enhance the interaction between channels, a channel shuffling operation is introduced:
[0113] F'=Shuffle(F)
[0114] Then, the number of channels is restored through point-wise convolution:
[0115] Y=PWC(F ' )
[0116] Through multi-scale convolution kernels, the perception of defects of different sizes is enhanced, recursive residuals are used to avoid information redundancy and improve feature flow, and channel shuffling and point-wise convolution improve the cross-channel information fusion capability.
[0117] Step S24: ATFLoss (Adaptive Threshold Focal Loss) loss function design. The proportion of small defects and background pixels is seriously unbalanced, and the conventional cross-entropy or IoU loss is easily dominated by a large area of background, thereby ignoring small targets. Focal Loss alleviates the problem to some extent by reducing the weight of easily classified samples, but there is still a fixed threshold that is difficult to adapt to different data sets. Therefore, the present application proposes ATFLoss, which introduces a dynamic threshold adjustment mechanism to adaptively adjust the difficult example sample weight according to the prediction distribution, and strengthens the learning of small defect regions.
[0118] Basic FocalLoss expression:
[0119]
[0120] Where p is the prediction probability, and alpha is the class balance factor. t t
[0121] Through adaptive threshold adjustment: let the dynamic threshold tau be based on the prediction distribution mean mu and standard deviation sigma:
[0122] Tau = mu + lambda * sigma
[0123] Where lambda is a learnable hyperparameter. Difficult example sample reweighting: when the prediction probability p t <tau, apply a strong weight to the sample:
[0124] W i = beta * I(p t <tau) + 1
[0125] Where beta > 1, and I is the indicator function. With dynamic threshold adjustment, adapt to different distribution data sets, strengthen difficult example and small target learning, reduce the miss rate, and keep the calculation simple
[0126] Step S25: VisDefectNet network model program implementation. The present application uses Python programming language to complete the building and implementation of MS-CMM module under the PyTorch deep learning framework. PyTorch is a high-performance tensor computing library based on Python and Torch, and is widely used in deep learning tasks that require GPU and CPU collaborative computing. Compared with other frameworks such as TensorFlow and Keras, PyTorch is favored due to its dynamic computation graph and high compatibility with Python, supporting developers and researchers to debug and verify model code in real time without waiting for the complete training process to detect the correctness of each part of the function.
[0127] Step S3: model training and verification.
[0128] Step S31: The present application uses Python programming language to realize the training and inference of the model under the PyTorch 2.0 deep learning framework. PyTorch is a high-performance tensor calculation library based on Python, which supports GPU and CPU collaborative calculation. Due to its dynamic computation graph and high compatibility with Python, it is widely used in deep learning research and engineering practice. The present application trains on a GPU platform equipped with NVIDIA RTX 4090 (24GB video memory), uses AdamW optimizer, initial learning rate is 1e-4, and gradually adjusts to 1e-6 through Cosine annealing strategy. The training process is carried out with Batch Size 16, a total of 300 epochs, and the loss function is the weighted combination of BCE, GIoU and ATFLoss. The model performance is evaluated by mAP50, mAP50:95, GFLOPs and FPS, etc. to ensure the balance between detection accuracy and computational efficiency
[0129] Step S32: During the model training process, the present application uses the validation set to evaluate the network performance after completing a certain number of iterations. The main evaluation indexes are precision (Precision), recall (Recall) and mean average precision (mAP), of which mAP is divided into mAP@0.5 and mAP@0.5:0.95. Precision is used to measure the accuracy of predicted defects, Recall measures the integrity of detection, and mAP as a comprehensive index is widely used in object detection tasks, which can reflect the matching degree between predicted box and real box. The value of mAP ranges from 0 to 100%, and the higher the value, the better the model detection performance.
[0130] Step S4: After training, the network parameters are frozen, and the model is tested on NEU-DET steel defect dataset, PCB-DET circuit board defect dataset and DsPCBSD+ extended circuit board defect dataset to comprehensively evaluate the small target defect detection performance of the model in complex industrial environment. The evaluation indexes adopted include: mAP@0.5 / mAP@0.5:0.95: used to measure detection accuracy, the larger the better; model parameter quantity (Parameters, M): reflects the model size, the smaller the better; computational complexity (GFLOPs): represents the number of floating point operations required for inference, the lower the better; inference speed (FPS): represents the number of frames processed per second, the higher the better.
[0131] To demonstrate the superiority of the proposed VisDefectNet, the present application compares it with current mainstream detection methods, including: traditional two-stage methods (Faster R-CNN), lightweight one-stage detectors (YOLOv3-Tiny, YOLOv5s, YOLOv9s, YOLOv11s), and emerging Transformer architecture (RT-DETR).
[0132] On the NEU-DET dataset, VisDefectNet achieves 78.4% mAP@0.5, which is 3.6 percentage points higher than the baseline YOLOv11, and surpasses all comparison methods. Especially on the fine-grained texture defects such as "Crazing" and "Pitted surface", the detection accuracy is significantly improved, indicating that the present method has stronger edge detail capturing ability.
[0133] On the PCB-DET dataset, VisDefectNet achieves 95.7% mAP@0.5, which is 3.1% higher than YOLOv11, and performs the best on key defect categories such as "Missing Hole" and "Open Circuit", further proving its small target perception and complex shape adaptation ability.
[0134] On the DsPCBSD+ dataset, VisDefectNet achieves 85.9% mAP@0.5, which is 0.9% higher than YOLOv11. It achieves accuracy improvement on typical small defects such as "Spurious Copper" and "CFO", which reflects the ability of the present method to maintain stable detection in complex circuit background.
[0135] Table 1
[0136]
[0137] Complexity and efficiency comparisonFrom Table 1, it can be seen that although Faster R-CNN has higher accuracy in some scenarios, its parameter quantity and computational quantity are extremely large, and the inference speed is only 24.2FPS, which is difficult to meet the real-time detection requirements of industry. Although the lightweight YOLO series method has faster inference speed, its accuracy is generally lower than that of the present method. VisDefectNet significantly reduces the parameter quantity while maintaining the highest accuracy, which is only 8.3M, smaller than YOLOv11s, and the inference speed is close to 80FPS, fully meeting the dual requirements of real-time and accuracy in industrial production. For example, Figure 5 With Figure 6In the visualization detection results of the three data sets NEU-DET, PCB-DET and DsPCBSD+, it can be seen that the traditional method often appears missed detection or false detection. For example, YOLOv5s and YOLOv11s are prone to misjudge normal areas as defects under complex texture background, or cannot accurately locate tiny cracks. While VisDefectNet can capture the boundary and detail features of tiny defects while maintaining global structure recognition, and the detection box is more consistent with the actual defect area. Especially in
[0138] In the PCB-DET data set, VisDefectNet shows more stable and accurate detection effect for complex defect categories such as "short circuit (Short)" and "spur (Spur)". In summary, the VisDefectNet model proposed in the present application shows superior performance and wide applicability in multiple industrial defect detection tasks. Compared with existing methods, VisDefectNet not only achieves overall improvement in detection accuracy, but also shows significant advantages in model complexity and inference speed. This result is attributed to the proposed SS-CMM module for fine-grained feature enhancement, C2PSA-Topk for sparse attention mechanism, MS-KSU for adaptive up-sampling design, and ATFLoss for dynamic sample balancing strategy, so that the model can balance high precision and real-time performance in complex industrial background, fully meeting the application requirements of actual industrial detection.
[0139] In summary:
[0140] The method of the present application introduces a spatial shift channel mixing module (SS-CMM) based on the YOLOv11s framework, which enhances the local dependence modeling of shallow features through parameter-free multi-directional shift operation, effectively preserving the microstructure information of small defects; In the feature fusion stage, a cross-stage partial connection sparse attention module (C2PSA-Topk) is used, which combines spatial attention and Top-k sparse selection mechanism to suppress complex background interference and highlight small target feature response; In the up-sampling stage, a multi-scale convolution kernel space up-sampling module (MS-KSU) is introduced, which uses multi-scale offset prediction and content-aware convolution kernel generation to realize accurate recovery of fine-grained structure and improve small defect edge positioning accuracy; In the training process, an adaptive threshold focal loss function (ATFLoss) is combined to dynamically adjust the weights of foreground and background samples, and to alleviate the class imbalance problem. This method has low parameter quantity and high inference speed, and achieves excellent detection performance on public industrial defect data sets such as NEU-DET, PCB-DET and DsPCBSD+, and is particularly suitable for small defect target detection tasks in complex industrial environments.
[0141] It will be apparent to those skilled in the art that the application is not limited to the details of the above-exemplified embodiments and that the present application can be implemented in other particular forms without departing from the spirit or essential characteristics of the present application. The embodiments should therefore be considered in all respects as illustrative and not restrictive, the scope of the application being indicated by the appended claims rather than by the above description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. No reference signs in the claims should be considered as limiting the scope of the claims with respect to the figures of the patent document.
Claims
1. A lightweight detection method for small defects in complex industrial scenarios, characterized in that: At least the following steps are included: S1: Collect and construct an image dataset containing multiple types of typical industrial defects, preprocess the raw data, the preprocessing includes at least uniform size, grayscale conversion and normalization, and group and divide the data according to defect type, image clarity and scene complexity into training set, validation set and test set. S2: An improved lightweight detection network VisDefectNet is built on the basis of YOLOv11s. VisDefectNet includes a spatial shift channel mixing module, a cross-stage partial connection sparse attention module, and a multi-scale convolutional kernel spatial upsampling module, namely the SS-CMM module, the C2PSA-Topk module, and the MS-KSU module, and is combined with an adaptive threshold focus loss function, namely ATFLoss. S3: VisDefectNet is trained using a stochastic gradient descent optimizer with an initial learning rate of 0.01, momentum of 0.937, weight decay of 0.0005, 300-500 training epochs, and a batch size of 16. The training set of defect images collected and processed in S1 is used to obtain the trained network weights. S4: Input the test set described in S1 into the trained VisDefectNet, and output the detection box and category of the defect target to achieve efficient detection of small defects in complex backgrounds.
2. The lightweight detection method for small defects in complex industrial scenarios according to claim 1, characterized in that: The industrial image data collected in S1 includes at least steel surface defects, printed circuit board defects, and composite material defects. All images are processed into PNG format with a uniform resolution, and size scaling, pixel intensity normalization, and contrast enhancement are performed to ensure consistency and detection accuracy of input from different data sources.
3. The lightweight detection method for small defects in complex industrial scenarios according to claim 1, characterized in that: The application of VisDefectNet includes a feature extraction stage, a global context modeling stage, and a detection and prediction stage. The feature extraction stage embeds a spatial shift channel hybrid module into the YOLOv11s backbone, which enhances the fine-grained expression of shallow features through channel grouping and multi-directional shift operations. The global context modeling stage employs a cross-stage partially connected sparse attention module, combining spatial attention mechanisms with Top-k sparse filtering to enhance small target features and suppress background interference. The detection and prediction stage introduces a multi-scale convolutional kernel spatial upsampling module in the upsampling path to achieve content-aware feature reconstruction, restore the edge details of small defects and improve the localization accuracy. At the same time, it combines an adaptive threshold focus loss function to alleviate the imbalance between foreground and background samples during training, thereby improving the detection performance of small targets and the robustness of the network.
4. The lightweight detection method for small defects in complex industrial scenarios according to claim 1, characterized in that: The SS-CMM module performs parameterless spatial-channel reorganization at a shallow level, preserving microstructural features; The SS-CMM module divides the input features into several subgroups along the channels, performs cyclic shift operations in the up-down and left-right directions respectively, and then splices them in the channel dimension, thereby realizing parameter-independent spatial-channel feature recombination to enhance the ability of shallow features to represent local fine-grained defects. The shift operation in the SS-CMM module uses a fixed convolution kernel size and a cyclic translation method, without introducing additional trainable parameters, thereby reducing model complexity and improving inference speed.
5. A lightweight detection method for small defects in complex industrial scenarios according to claim 1, characterized in that: The cross-stage partial connection sparse attention module is used to suppress background noise by sparsifying the attention region; The C2PSA-Topk module introduces a Top-k sparse attention operator on the basis of the spatial attention mechanism of the cross-stage partial connection structure. It retains only the top k maximum response values of each query in the attention matrix to suppress background noise and enhance the response of small target features. The attention calculation method of the C2PSA-Topk module is as follows: SparseAtt(Q,K,V)=softmax(τ k (QK T / λ))V Where τ k Select the Top-k operator; λ is the scaling factor; Q, K, and V are the query, key, and value matrices of the attention mechanism, respectively.
6. A lightweight detection method for small defects in complex industrial scenarios according to claim 1, characterized in that: The multi-scale kernel space upsampling module recovers defect details through content-aware offset prediction. The MS-KSU module includes a multi-scale offset prediction branch and a convolutional kernel spatial generation branch. The input features are first compressed through a 1×1 convolution channel, and then enter the offset prediction and convolutional kernel generation paths respectively to achieve content-based adaptive upsampling. The multi-scale migration prediction branch includes two parallel depthwise separable convolutional branches with kernel sizes of 5×5 and 7×7, respectively, and uses dilation rates of 2 and 3 to model mid-range and long-range contextual features, ultimately generating a positional migration map. The spatial generation branch of the convolution kernel performs nonlinear transformation and normalization operations on the input features to generate a content-aware convolution kernel, which is then combined with a multi-scale offset mapping to achieve spatially adaptive feature sampling and reconstruction.
7. A lightweight detection method for small defects in complex industrial scenarios according to claim 1, characterized in that: The ATFLoss gives greater attention to small targets during backpropagation, balancing the training process of objects of different scales. The ATFLoss adaptive threshold focus loss function distinguishes between easily classified background samples and difficult-to-classify defect samples through a dynamic threshold and uses an adjustable modulation factor to enhance attention to small target difficult examples, thereby alleviating the problem of foreground-background sample ratio imbalance. The definition of ATFLoss is: When the predicted probability pt ≤ 0.5, When the predicted probability pt > 0.5, Where λ is the loss adjustment coefficient and pt is the class prediction probability.
8. A lightweight detection method for small defects in complex industrial scenarios according to claim 4, characterized in that: The application process of the SS-CMM module includes at least the following steps: Input feature map Divided into 4 subgroups along the channel dimension; Perform a cyclic shift operation on each subgroup, including: shift up, shift down, shift left, and shift right, with a shift magnitude of s pixels, defined as: T i (X i )=Roll(X i ,s i ,dim=d i ),s i ∈{+s,-s},d i ∈{H,W} The shifted features are concatenated along the channel dimension to obtain the output features: The concatenated features are input into the C3K2 module of YOLOv11s, and combined with multi-branch convolution and residual connection mechanisms, local detail enhancement and global context modeling are achieved.
9. A lightweight detection method for small defects in complex industrial scenarios according to claim 5, characterized in that: The application process of the C2PSA-Topk module includes at least the following steps: Compress the input features using a 1×1 convolution to reduce the channels; Local spatial context features are extracted using 3×3 depthwise separable convolution; The features are divided into three groups: Q, K, and V, for attention calculation. Top-k sparsification is applied to the attention matrix: Among them, t i This represents the k-th largest value in the j-th row; Note on computational sparsity: SparseAtt(Q,K,V)=softmax(τ k (QK T / λ))V The attention output is added element-wise to the original features to achieve background suppression and small target response enhancement.
10. A lightweight detection method for small defects in complex industrial scenarios according to claim 6, characterized in that: The implementation steps of the MS-KSU module include at least the following steps: The input features are compressed through 1×1 convolution; The compressed features are input into the multi-scale offset prediction branch and the convolution kernel generation branch, respectively. The offset prediction branch contains a 3×3 depthwise separable convolution and two parallel dilated convolution branches with kernels of 5×5 (dilation rate 2) and 7×7 (dilation rate 3), respectively, and outputs an offset mapping O. offset ; O offset =Conv 1×1 (SiLU(Conv 1×1 (x)+Conv 1×1 (F multi ))) The convolution kernel generation branch performs non-linear activation and normalization on the input features to generate a spatially adaptive convolution kernel; Offset mapping and convolution kernel work together to perform feature sampling, achieving position-sensitive adaptive upsampling.
Citation Information
Cited By
Intelligent detection method for reservoir piping phenomenon
CN121505240A
An intelligent detection method for reservoir piping phenomenon
CN121505240B