An industrial part defect detection method, system and training method

CN122989708APending Publication Date: 2026-10-27SHENZHEN ZHONGHENG INNOVATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611373874.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-07
Publication Date
2026-10-27

AI Technical Summary

Benefits of technology

[0039]1.通过引入前景—背景协同判别模块,本发明能够对候选区域的内部特征进行精细化分析。具体地,通过计算背景混淆风险,能够有效识别并抑制那些由复杂背景纹理、划痕或光照不均引起的伪缺陷(即假阳性样本),使得模型不再仅仅依赖于粗略的分类特征,从而大幅提升检测结果的精确率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122989708A_ABST
    Figure CN122989708A_ABST
Patent Text Reader

Abstract

The application belongs to the technical field of industrial visual detection, and discloses an industrial part defect detection method, a system and a training method.The detection method comprises the following steps: obtaining a to-be-detected image, extracting a multi-scale feature to generate a candidate target, and the candidate target comprising a candidate frame, a basic classification score and candidate segmentation information; extracting a candidate frame context feature according to the candidate frame, and decoupling the context feature into a candidate foreground feature and a candidate background feature according to the candidate segmentation information; performing multi-branch collaborative discrimination on the candidate target, performing foreground authenticity discrimination based on the candidate foreground feature to output a foreground discrimination score, and performing background confusion risk discrimination based on the candidate background feature to output a background passing probability; jointly re-scoring according to the basic classification score, an enhanced classification score, the foreground discrimination score and the background passing probability, calculating a final confidence and outputting a defect detection result.The application suppresses false positives caused by complex backgrounds and maintains the detection ability for real defects.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of industrial visual inspection technology, specifically relating to a method, system and training method for detecting defects in industrial parts. Background Technology

[0002] In modern industrial production, automated surface defect detection based on machine vision has become a crucial step in ensuring product quality. However, defects in industrial parts often exhibit characteristics such as small target size, extremely low proportion in the overall image, and varied and irregular shapes. Simultaneously, the visual features of defects are often highly similar to normal surface textures (such as periodic machining marks and brushed textures), structures (such as chamfers, contour edges, and embossed characters), and interfering factors during the imaging process (such as specular reflections, oil stains, dust, shadows, uneven exposure, and sensor noise). These normal areas are easily confused with defects such as cracks, scratches, dents, or stains in their local features, leading to a large number of false positives from deep learning detection networks.

[0003] Single-stage detection networks, represented by YOLOv8 and its segmentation version (YOLOv8-seg), have been widely used in industry due to their efficient end-to-end design. These networks can simultaneously perform candidate box localization, object classification, and instance segmentation. However, their inherent design also has limitations: the decision of their classification branch mainly relies on specific locations on the feature map and their limited receptive field. This makes it difficult for the model to explicitly and holistically perceive the complete structure within the candidate box, the precise shape of the candidate segmentation mask, and the background information of the candidate box's external neighborhood. In practical applications, to ensure that no possible real defects are missed (i.e., to improve recall), the model's detection confidence threshold is usually set relatively low. However, this inevitably amplifies the false positive problem on normal images; even defect-free images may output a large number of false boxes, seriously affecting the reliability and practicality of the detection system.

[0004] To address the aforementioned false positive problem, existing technologies have proposed several improvement schemes. These schemes can be broadly categorized as: adjusting post-processing strategies (e.g., increasing the confidence threshold), optimizing training data (e.g., adding normal samples), modifying network structure (e.g., adding attention modules, modifying the classifier head), adjusting the loss function (e.g., adjusting the segmentation loss weights), and introducing a secondary classifier. While these methods can achieve certain results in specific scenarios, they generally suffer from the following shortcomings:

[0005] 1. Simply raising the confidence threshold is a one-size-fits-all strategy. While it filters out false positives, it is also very likely to filter out real defects with low confidence, leading to a significant decrease in recall.

[0006] 2. Modifying only the classification head of the detection network does not explicitly separate the foreground and background of the candidate target from the input features. As a result, the model still has difficulty accurately locating the root cause of false alarms, i.e., it cannot determine whether the high response is caused by a real defect or by similar background texture.

[0007] 3. When adding an auxiliary classification head next to the original detection head, if the auxiliary head and the main classification head use the exact same region of interest (ROI) features as input, the two branches are likely to learn repetitive or highly related information, resulting in limited improvement in discrimination ability.

[0008] 4. For some difficult false alarm samples with very high confidence caused by reflection, process edges, etc., simply adjusting the weight of the segmentation loss or increasing the number of normal samples is often not effective in suppressing them.

[0009] 5. Using an independent secondary classifier to further filter the output of the main detection network can improve accuracy, but it usually requires repeated image cropping and feature extraction of candidate regions, introducing additional inference latency and deployment complexity, making it unsuitable for industrial scenarios with high real-time requirements.

[0010] 6. There is a discrepancy in the distribution of candidate boxes during the training and inference phases. During training, the auxiliary branch often learns using accurate ground truth bounding boxes, while during inference, it faces predicted boxes with inaccurate positions and sizes. This distribution difference may lead to a decrease in model performance.

[0011] 7. Existing methods generally lack a mechanism for jointly modeling instance segmentation information with the inner and outer backgrounds of candidate boxes, and fail to fully utilize the precise spatial information provided by segmentation masks to assist in false alarm detection. Summary of the Invention

[0012] The present invention aims to at least partially solve the aforementioned technical problems. Therefore, the objective of the present invention is to provide a method, system, and training method for detecting defects in industrial parts.

[0013] The technical solution adopted in this invention is as follows:

[0014] To achieve the above objectives, a first aspect of the present invention provides a method for detecting defects in industrial parts. This method is based on a deep learning detection and segmentation network with instance segmentation capabilities and includes the following steps:

[0015] First, an image of the industrial part to be inspected is acquired, and multi-scale feature maps of the image are extracted through forward propagation of the detection and segmentation network. Based on these multi-scale feature maps, the main detection and segmentation branch of the network generates at least one candidate target. Each candidate target includes a candidate bounding box containing its location information, a base classification score indicating that it belongs to a certain defect category, and candidate segmentation information describing its precise shape.

[0016] Next, feature decoupling is performed on the generated candidate targets. Specifically, based on the position and size of the candidate box, candidate box context features covering the entire candidate box region are extracted from the corresponding multi-scale feature map. Then, using candidate segmentation information as spatial guidance, the candidate box context features are explicitly separated into two parts: candidate foreground features representing the defect ontology, and candidate background features representing the non-defect region within the candidate box.

[0017] Subsequently, multi-branch collaborative discrimination is performed on the candidate targets. This step involves multiple parallel discrimination paths:

[0018] (1) Based on the candidate foreground features, perform foreground authenticity judgment. The purpose is to determine whether there are real defective entities in the candidate region and output a foreground judgment score.

[0019] (2) Based on the candidate background features, perform background confusion risk judgment. The purpose is to evaluate the possibility that the background patterns (such as reflection and texture) inside and outside the candidate box may cause the current false alarm, and output a background pass probability.

[0020] (3) The local classification features corresponding to the candidate target location, the candidate box context features and the candidate foreground features are fused to generate a context-enhanced classification score.

[0021] Finally, a joint re-scoring process is performed on the candidate targets. This step comprehensively utilizes information from different discrimination paths, calculating a more reliable final confidence score based on the initial base classification score, the context-enhanced classification score generated in the preceding steps, the foreground discrimination score obtained from foreground realism discrimination, and the background passage probability obtained from background confusion risk discrimination. Based on this final confidence score, all candidate targets are filtered and post-processed (e.g., non-maximum suppression), ultimately outputting defect detection results with a confidence score higher than a preset threshold. The results may include the defect's bounding box, category, final confidence score, and corresponding segmentation mask.

[0022] In a preferred embodiment, the candidate segmentation information is specifically a candidate soft mask, where each pixel value is between 0 and 1, representing the probability that the location belongs to the foreground. The feature decoupling step is specifically implemented as follows: by performing an element-wise weighted operation (such as multiplication) on the candidate box context features and the candidate soft mask, and then performing spatial pooling (such as global average pooling) on ​​the result, the candidate foreground features are obtained; simultaneously, by performing an element-wise weighted operation (i.e., 1 minus the soft mask) on the complementary weights of the candidate box context features and the candidate soft mask (i.e., 1 minus the soft mask), and then performing pooling, the background features within the candidate box are obtained.

[0023] In a preferred embodiment, to more comprehensively evaluate the background influence, the candidate background features are fused from two parts: one part is the background features within the candidate box, and the other part is the annular background features. The annular background features are obtained by constructing an outwardly expanding annular region (the outwardly expanding annular region) based on the original candidate box and extracting features within this region. This allows the model to perceive the contextual information of the regions immediately adjacent to the candidate box.

[0024] In a preferred embodiment, the joint re-scoring step employs a multiplicative fusion approach to calculate the final confidence score. For example, the final confidence score can be obtained by multiplying the base classification score, the enhanced classification score, the foreground discrimination score, and the background pass probability. In this approach, a low score in any dimension (such as an unrealistic foreground or a high-risk background) will significantly lower the final score, thereby achieving effective false positive suppression.

[0025] In a preferred embodiment, to accommodate defects of different sizes, the extraction of candidate bounding box context features is dynamic. Specifically, based on the area or long side size of the candidate bounding box, an optimal resolution level is dynamically selected from the multi-scale feature pyramid (e.g., high-resolution feature maps for small targets and low-resolution feature maps for large targets). Then, region of interest (ROI) sampling operations (e.g., ROI Align or ROI Pooling) are performed on the candidate bounding box region on the selected feature map to obtain a feature map with a fixed spatial size, which facilitates subsequent processing.

[0026] In a preferred embodiment, to balance detection accuracy and inference efficiency, the method includes a pre-screening step before performing computationally expensive feature decoupling and multi-branch collaborative discrimination. This step quickly sorts the candidate targets based on their basic classification scores and selects only the top K (Top-K) candidate targets. Subsequent refined discrimination processes are only performed on these K most likely true defects, thereby significantly reducing the overall computational cost.

[0027] A second aspect of the present invention provides an industrial part defect detection system designed to implement the aforementioned method. The system includes:

[0028] A feature extraction module is configured to load and run a detection and segmentation network to process the input image to be detected, extract multi-scale features, and generate candidate targets containing candidate boxes, basic classification scores, and candidate segmentation information.

[0029] A feature decoupling module is connected to the feature extraction module. It is configured to extract the context features of the candidate box based on the candidate box and use the candidate segmentation information to separate the context features into candidate foreground features and candidate background features.

[0030] A collaborative discrimination module, connected to a feature decoupling module, is configured to receive decoupled features and perform foreground authenticity discrimination in parallel to output a foreground discrimination score, and perform background confusion risk discrimination to output a background pass probability; and to fuse the local classification features corresponding to the candidate target location, the candidate box context features, and the candidate foreground features to generate an enhanced classification score.

[0031] A joint re-scoring module, connected to the feature extraction module and the collaborative discrimination module, is configured to aggregate the basic classification score, the enhanced classification score, the foreground discrimination score, and the background pass probability, calculate the final confidence score, and select candidate targets accordingly, and output the final defect detection result.

[0032] A third aspect of the present invention provides a training method for an industrial part defect detection model, which is used to train the deep learning model used in the aforementioned methods and systems. The method includes the following steps:

[0033] First, a training sample set is constructed, which includes not only sample images with precise defect annotations (bounding boxes and segmentation masks), but also a large number of normal part images without any defects.

[0034] Secondly, a course-based hybrid candidate training strategy is adopted. In the initial stage of training, ground truth bounding boxes and positive sample boxes generated by the label assignment strategy are mainly used as candidate sources, allowing the model to learn basic discriminative abilities. As training progresses, the sampling ratio of predicted boxes generated by the model itself and high-confidence false positive candidate boxes mined from normal images is gradually increased in the training batch. This training approach, from easy to difficult, helps the model better adapt to real-world situations during the inference phase.

[0035] Then, a joint loss function is used to optimize the parameters of the entire network end-to-end. This joint loss function is a weighted sum of multiple loss terms, including at least the main classification loss for localization, the foreground discriminant loss for foreground realism detection, and the background discriminant loss for background confusion risk detection. Additionally, it may include bounding box regression loss, instance segmentation loss, augmentation classification loss, etc.

[0036] Finally, the training method also includes an iterative optimization loop. Periodically (e.g., every few training epochs), the currently trained model is scanned against a normal image database to discover newly discovered high-confidence false positive candidate boxes and add them to the training process, thereby continuously allowing the model to learn and overcome its most error-prone patterns.

[0037] In a preferred embodiment, high-confidence false positive candidate boxes mined from normal images are assigned specific supervision signals during training. Specifically, the training labels corresponding to these boxes in the foreground authenticity discrimination task are set as negative samples (i.e., non-real foreground), while the training labels corresponding to these boxes in the background confusion risk discrimination task are set as positive samples (i.e., high-risk background). This is done to specifically train the auxiliary discrimination branch to learn to recognize these typical easily confused background patterns.

[0038] The beneficial effects of this invention are as follows:

[0039] 1. By introducing a foreground-background collaborative discrimination module, this invention enables refined analysis of the internal features of candidate regions. Specifically, by calculating the risk of background confusion, it can effectively identify and suppress false defects (i.e., false positive samples) caused by complex background textures, scratches, or uneven lighting, so that the model no longer relies solely on coarse classification features, thereby significantly improving the accuracy of detection results.

[0040] 2. By designing a segmentation context fusion module, this invention can utilize the contextual information surrounding the defect region to assist in judgment. For real defects with weak features, low contrast, or blurred shapes, even if their own features are insufficient to generate a high confidence score, this module can still confirm their existence by analyzing their differences from the surrounding normal background, thereby effectively rescuing these easily overlooked defects and significantly improving the detection recall rate.

[0041] 3. This invention combines local precision judgment (foreground-background collaborative discrimination) with global corroboration (segmentation context fusion) to form a dual verification mechanism. This mechanism enables the model to focus not only on the defect itself but also on the relationship between the defect and its environment, thus making the defect discrimination more comprehensive and reliable. Therefore, this invention exhibits stronger robustness and adaptability to defects of different shapes and sizes, as well as to varying industrial background environments.

[0042] 4. The joint re-scoring strategy proposed in this invention organically integrates the basic classification score, foreground confidence, background pass probability, and context enhancement score to generate a more reliable final confidence score. This final confidence score can more accurately reflect the probability that the candidate region is a real defect. In the subsequent non-maximum suppression (NMS) processing, using this high-quality confidence score for sorting and filtering can more effectively retain the best detection boxes while eliminating redundant and erroneous detection boxes, ultimately achieving a significant improvement in core performance indicators such as mean average precision (mAP). Attached Figure Description

[0043] Figure 1 This is a schematic diagram of the overall technical process according to the present invention.

[0044] Figure 2 This is a flowchart illustrating the candidate feature extraction and mask-guided decoupling subsystem according to the present invention.

[0045] Figure 3 This is a schematic diagram of the candidate multi-branch collaborative discrimination subsystem according to the present invention.

[0046] Figure 4 This is a flowchart illustrating the joint rescoring and candidate post-processing subsystem according to the present invention.

[0047] Figure 5 This is a graph showing the loss curves of bounding box regression, segmentation, and distributed bounding box regression during the model training process after applying the method of this invention.

[0048] Figure 6 This is a graph showing the classification, foreground, background, and context classification loss curves during the model training process after applying the method of this invention.

[0049] Figure 7 This is a graph showing the precision and recall rates during model training after applying the method of this invention.

[0050] Figure 8 The graph shows the loss curves for box regression, segmentation, and distributed box regression during the training process without applying the method of this invention.

[0051] Figure 9 This is a classification loss curve during the training process without applying the method of this invention.

[0052] Figure 10 This is a graph showing the precision and recall during the training process without applying the method of this invention. Detailed Implementation

[0053] The technical solution of the present invention will now be clearly and completely described with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention.

[0054] It should be understood that, and also noted, in the embodiments, the functions / actions may appear in a different order than those shown in the figures. For example, depending on the functions / actions involved, they may actually be performed substantially concurrently, or sometimes the two figures shown consecutively may be performed in reverse order.

[0055] This invention provides a method and system for detecting defects in industrial parts. For each high-probability candidate target generated by a basic detection segmentation network, instead of directly accepting its initial classification score, a refined secondary review process is used to confirm its quality. This process decouples the features of the candidate region into foreground and background parts using an instance segmentation mask, and establishes a dedicated discrimination branch that considers two orthogonal dimensions: whether the foreground is real and whether the background is deceptive. Finally, all evidence is synthesized to form a more reliable final judgment.

[0056] Reference Figure 1 The overall technical process of this invention can be divided into a training and optimization path and a detection and inference main path. In the detection and inference main path, the system first receives an image of an industrial part to be detected. After preprocessing (such as scaling and normalization), the image is fed into a basic detection and segmentation network. In this embodiment, the YOLOv8-seg model is preferably used, but it is not limited to this; any other network that can output multi-scale feature maps and perform detection and instance segmentation simultaneously can be applied.

[0057] Main detection segmentation: The backbone and neck of the network (such as the Feature Pyramid Network, FPN) process the image, generating multi-scale feature maps such as P3, P4, and P5. Subsequently, the main detection segmentation head performs dense predictions on these feature maps, outputting a large number of initial candidate objects. Each candidate object includes a candidate bounding box B. i Basic category confidence S base The parameters for box regression and the mask coefficients used to generate the segmentation mask are used. Through decoding, the initial candidate boxes and candidate segmentation information M are obtained. i (Usually a soft mask).

[0058] Candidate box selection: To control computational overhead, the system does not perform further fine-tuning on all initial candidates. Instead, it selects candidates based on the base category confidence S. base Sort the candidates and select the top-K candidates with the highest scores to proceed to the next step. The value of K is an adjustable hyperparameter, for example, it can be set to 100.

[0059] Candidate feature extraction and mask-guided decoupling: For details, please refer to [link / reference]. Figure 2 For each selected candidate, the system executes:

[0060] a. Assign appropriate feature levels to candidate boxes based on their size (e.g., P3 for small boxes and P5 for large boxes).

[0061] b. From the selected feature layer, extract the box-level context features F corresponding to the overall region of the candidate box using operations such as ROI Align. box Simultaneously, local classification features F corresponding to the candidate positions are extracted. local .

[0062] c. Utilize the candidate's soft mask M i , for F box Perform weighted separation. (With M) i The multiplied portion is considered as the foreground feature F fg , and (1-M i The multiplied portion is considered as the background feature F within the box. inner-bg .

[0063] d. In candidate box B i An annular region is constructed externally, and the feature F of this region is extracted. ring F inner-bg and F ring Together, they constitute the background context features F used for background discrimination. bg .

[0064] Multi-branch collaborative discrimination: The decoupled features are fed into three parallel auxiliary discriminant heads. See the specific structure for details. Figure 3 .

[0065] a. Seg-Context Head: Fusion of local classification features F local , box-level context features F box and foreground features F fg Output a context-enhanced classification score S. ctx This branch aims to refine the initial classification score by utilizing richer contextual information.

[0066] b. FG Head (Foreground Authenticity Determination): Primarily receives foreground features F fg And can selectively bind F box This is used to determine whether the foreground portion of the candidate is a real defect. Its output is a probability value S. fg , which represents the confidence level of "is the true prospect".

[0067] c. BG Head (Background Obfuscation Detection): Receives background context features F bg This is used to determine whether the candidate is triggered by a confusing background (such as reflections, textures, or edges). Its output is a background confusion risk probability R. bg .

[0068] Joint rescoring and result output: Refer to Figure 4 The system merges the outputs of each branch.

[0069] a. First, consider the risk of background confusion R. bg Conversion to background with probability S bg-pass =1-R bg The higher the value, the "cleaner" the background, and the less likely the candidate is to be a false positive caused by the background.

[0070] b. Then, the basic classification score S base Enhanced classification score S ctx The data is then integrated to obtain a comprehensive classification score S. cls .

[0071] c. Finally, the final confidence level is calculated using multiplicative fusion: S final =S cls ×S fg ×S bg-pass .

[0072] d. All candidates must satisfy the gating conditions of each discriminant branch (e.g., S). fg and S bg-pass (all are greater than a certain threshold), then according to S final After performing final post-processing such as non-maximum suppression (NMS), the final defect detection and segmentation results are output.

[0073] In the training optimization path, the system utilizes a dataset containing real defects, normal samples, and historical false positive samples to jointly optimize the entire network (including the main network and all auxiliary discriminators). Training employs a special curriculum-based hybrid candidate strategy and joint loss function, which will be described in detail in subsequent chapters.

[0074] Example 1: Basic Fusion Model Based on YOLOv8s-seg

[0075] This embodiment uses YOLOv8s-seg as the base network. The input image size is uniformly 640×640 pixels. The neck layer of the network outputs three feature maps: P3, P4, and P5. The main detection segmentation head provides each candidate output bounding box coordinate, basic classification score, a 32-dimensional mask coefficient vector, and a shared mask prototype set.

[0076] During the training and inference phases, for a given candidate box B i First, determine which feature map layer to use based on its area. For example, if the area is less than 32... 2 Use P3, greater than 96 2 Use P5 for values ​​that fall between P5 and P4 for values ​​in between. Then, apply the following to B on this feature map. i Perform the ROI Align operation to extract contextual features F of a candidate bounding box with a fixed size of 7×7. box To enhance feature representation, before ROI Align, a 1×1 convolution can be used to uniformly project the number of channels of each layer's feature map to 128.

[0077] Meanwhile, the predicted soft mask M corresponding to this candidate i The image is scaled to 7×7 using bilinear interpolation. Foreground features F are computed using element-wise multiplication and global average pooling. fg =Pool(F box ×M i ) and background feature F within the frame inner-bg =Pool(F box ×(1-M i )).

[0078] To obtain information outside the box, candidate box B... i The width and height are both expanded outwards at a ratio of 1.3, forming the expanded frame B. exp The annular region between the expanded bounding box and the original candidate box is defined as the annular background. Features of this annular region are extracted from the corresponding feature map and pooled to obtain Fo. ring The final background feature F bg By F inner-bg and F ring It was pieced together.

[0079] The specific implementations of the three auxiliary discriminant heads are as follows:

[0080] Seg-Context Head: Input is F local F box (After flattening) F fg The concatenated vectors, after passing through several fully connected layers, output an enhanced classification score S. ctx .

[0081] FG Head: Input is F fg and F box The (flattened) concatenated vector is passed through a small convolutional network or multilayer perceptron (MLP) to output the foreground authenticity probability S. fg .

[0082] BG Head: Input is F bgSimilarly, after passing through a small convolutional network or MLP, the output background obfuscation risk R is obtained. bg .

[0083] During inference, only the base score S output by the main detection head is considered. base The top 100 candidates undergo the complete feature decoupling and multi-branch discrimination process described above to ensure real-time performance.

[0084] Example 2: Auxiliary branch training driven by difficult negative samples

[0085] To enable the FG Head and BG Head to learn to identify the most challenging false alarms, this embodiment employs a difficult negative sample mining strategy.

[0086] 1. Sample Library Construction: First, a pre-trained baseline model (YOLOv8s-seg without auxiliary branches) is used to infer all defect-free normal training images. All false positive candidate boxes with a base classification score above a certain threshold (e.g., 0.25) and an IoU (Intersection over Union) of 0 with any real defect annotation are collected. These candidate boxes are the hard negative samples. Based on their image content, they are labeled with attributes such as reflection, edge, texture, and oil stains, and stored in a hard negative sample library along with their ROI image and location information.

[0087] 2. Sampling Strategy: During training, the ROI samples in each training batch no longer come solely from real defects, but are composed of multiple sources mixed in a specific ratio. For example, sampling can be performed according to a ratio of "real defects: historical false alarms: process similar areas: random background ≈ 1:1:1:1".

[0088] 3. Label assignment: Samples from different sources will have different supervision labels on the auxiliary branches.

[0089] For true defect candidates: the prospective truthfulness label Y fg =1, Background Confusion Risk Label Y bg-risk =0.

[0090] For historical false positives (difficult negative samples) candidates: Y fg =0, Y bg-risk =1.

[0091] For a clean background region randomly sampled from a normal image: Y fg =0, Y bg-risk =0.

[0092] In this way, the FG Head is trained to distinguish between real defects and various pseudo-defects, while the BG Head is specifically trained to identify background patterns that are prone to false alarms.

[0093] Example 3: Joint Loss Function and Weight Optimization

[0094] The training process of this invention employs a joint loss function L. total It is a weighted sum of the losses from multiple tasks:

[0095] L total =λ box *L box +λ cls *L cls +λ dfl *L dfl +λ mask *L mask +λ ctx *L ctx +λ fg *L fg +λ bg *L bg

[0096] in:

[0097] L box ,L cls ,L dfl ,L mask These are the original bounding box regression loss, main classification loss, distributed bounding box regression loss, and instance segmentation loss of the basic network.

[0098] L ctx ,L fg ,L bg These are the newly added context-enhanced classification loss, foreground authenticity binary classification loss (such as BCELoss), and background confusion risk binary classification loss (such as BCE Loss).

[0099] λ is the weighting coefficient for each loss.

[0100] The setting of loss weights is crucial to model performance, especially the segmentation loss weight λ. mask This affects the quality of the segmentation mask, and the mask quality directly determines the effectiveness of foreground / background feature decoupling. If λ mask If the value is too high, the model may focus too much on pixel-level segmentation accuracy and neglect the learning of high-level semantic features, which is detrimental to classification. This embodiment suggests setting λ... mask As an adjustable parameter, it can be set independently of other classification and discrimination losses. For example, the default weights of YOLOv8s-seg (L) can be maintained. box =7.5,λ cls =0.5,λ dfl =1.5), and then test λ respectively. maskThe results are shown for losses of 1.0, 0.5, 0.25, and 0.1. Simultaneously, appropriate weights, such as λ, are set for the newly added auxiliary branch loss. ctx =0.5,λ fg =0.5,λ bg =0.5. By evaluating multiple metrics such as defect recall, mask mAP, and false positive rate in the normal graph on the validation set, a set of weight configurations that achieves the best balance (i.e., recall does not decrease significantly while the false positive rate is minimized) is selected.

[0101] Example 4: Multi-ring background discrimination

[0102] To provide a more refined analysis of the background, the input to the BG Head can be further enriched. This embodiment constructs two annular backgrounds at different scales:

[0103] Near-ring zone: By expanding the candidate box by 1.2 times, it is used to capture detailed information such as process texture and edges that are close to the candidate box boundary.

[0104] Far ring band: obtained by expanding the candidate box by 1.5 times and subtracting the expanded area by 1.2 times, used to capture a larger range of part structure context.

[0105] Features extracted from the near and far annular bands can be fused with the background features within the bounding box through concatenation or attention mechanisms before being input into the BG Head. This multi-layered background modeling helps the model better distinguish between local texture noise and global structural background.

[0106] Example 5: Lightweight Deployment Solution

[0107] For scenarios deployed on edge devices with limited computing power, the method of this invention can be modified to be lightweight:

[0108] Reduce the number of precise judgments: Lower the Top-K value, for example, set it to 50 or even less.

[0109] Reduce ROI resolution: Reduce the output size of ROI Align from 7×7 to 5×5.

[0110] Shared network layers: The FG Head and BG Head share a portion of the initial convolutional layers, retaining only their own independent output layers at the end, in order to reduce the number of parameters and computational cost.

[0111] Tiered processing: Only for the base score S base Candidates in the uncertainty range (e.g., scores between 0.2 and 0.7) are processed by an auxiliary discriminant head. Candidates with extremely high scores (>0.7) are accepted directly, while candidates with extremely low scores (<0.2) are discarded.

[0112] To verify the effectiveness of the present invention, a series of comparative experiments were conducted.

[0113] 1. Data partitioning

[0114] The experimental dataset contains approximately 30,000 images of industrial parts, divided into training and validation sets at a ratio of 80% to 20%. The defect categories cover a wide range of types, including 20 categories such as FLEX_BUR (burrs), FLEX_SCT (scratches), and PAD_DOS (stains).

[0115] 2. Setting of main parameters for experimental training

[0116] Two models were trained: a standard YOLOv8s-seg model as the baseline (without applying this invention), and an improved model applying the method described in this invention. The hyperparameters of both models were kept consistent, as shown in the table below:

[0117] epochs 400 weight_decay 0.0005 mask 1 batch 100 warmup_epochs 3 dfl 1.5 imgsz 800 warmup_momentum 0.8 pose 12 iou 0.7 warmup_bias_lr 0.1 hsv_h 0.015 lr0 0.001 dis 6 hsv_s 0.2 lrf 0.01 box 7.5 hsv_v 0.2 momentum 0.937 cls 0.5 scale 0.5

[0118] For the model applying this invention, the newly added loss weight λ ctx , λ fg , λ bg All are set to 0.5.

[0119] 3. Comparison of training process losses

[0120] Apply this improvement scheme ( Figures 5 to 7 ) and the baseline model that did not apply this improvement scheme ( Figures 8 to 10 The loss curve and performance metrics during the training process. For example... Figure 5 As shown, after applying this invention, the box regression loss (box regression loss) loss ), segmentation loss (seg) loss ) and Distributed box regression loss (dfl) loss Both showed a steady downward trend and leveled off after about 200 epochs, indicating that the model's localization and segmentation capabilities improved simultaneously. Figure 6 The newly added auxiliary task loss is further illustrated: foreground discrimination loss (cls) fg Background discrimination loss (cls) bg ) and context-enhanced classification loss (cls) ctx All of them can converge effectively without oscillation or divergence, proving that each auxiliary discriminant head can stably learn meaningful discriminant features. Figure 7 The precision and recall curves gradually increased and remained stable in the later stages of training, indicating that the multi-branch collaborative discrimination mechanism of this invention continuously improves precision without sacrificing recall.

[0121] As a comparison Figures 8 to 10 The training curves of the baseline model without applying this invention are shown. Figure 8 While the bounding box regression and segmentation loss can converge, Figure 10 The accuracy curve is significantly lower than Figure 7 Furthermore, the recall rate fluctuates significantly, indicating that the model struggles to maintain stable detection capabilities under conditions of low false alarms. Figure 9 While the classification loss is stable, it lacks specific constraints on foreground authenticity and background risk, causing the model to be unable to effectively distinguish false defects, ultimately limiting accuracy improvement. Figure 5-10 The comprehensive comparison shows that the auxiliary discrimination branch and joint training strategy introduced in this invention not only do not interfere with the learning of the backbone network, but also make the overall training process more stable by providing more refined supervision signals, and lay a solid foundation for improving the final detection accuracy.

[0122] This training process analysis, together with the test set results (a 69.9% reduction in false positive rate and an approximately 4.4% improvement in mAP), forms a complete "training-verification-testing" evidence chain, fully verifying the effectiveness and engineering applicability of the present invention.

[0123] 4. Comparison of test set results

[0124] The final performance of the two models was evaluated on an independent test set containing 1166 defective samples and 2031 defect-free samples. The experiment was repeated three times and the average results were taken, as shown below:

[0125] Comparison of false alarms and missed detection rates:

[0126] Number of defective samples 1166 1166 Number of defect-free samples 2031 2031 Leakage 62 45 False alarm 23 7 Leakage rate 0.0532 0.0387 False alarm rate 0.0113 0.0034

[0127] As can be seen from the table above, after applying the method of the present invention, the number of false positive samples decreased significantly from 23 to 7, and the false positive rate decreased by approximately 69.9%. At the same time, the number of missed defect samples also decreased from 62 to 45, and the miss rate decreased by approximately 27.3%. This indicates that the method of the present invention not only greatly suppresses false positives, but also improves the recall capability for real defects.

[0128] Comparison of standard testing and segmentation indicators:

[0129] Precision (B) 0.6783 0.7383 Recall(B) 0.6753 0.6907 mAP50(B) 0.7069 0.738 mAP50-95(B) 0.5432 0.5719 Precision (M) 0.648 0.7116 Recall(M) 0.6547 0.661 mAP50(M) 0.6715 0.6908

[0130] Where B represents the bounding box detection metric and M represents the mask segmentation metric.

[0131] As can be seen from the table above, after applying this invention, all major accuracy metrics (Precision, Recall, mAP) are significantly improved in both bounding box detection and instance segmentation. This demonstrates that the multi-branch collaborative discrimination and joint re-scoring mechanism of this invention can guide the model to learn more discriminative features, thereby comprehensively improving the performance of detection and segmentation.

[0132] This invention, by introducing mask-guided feature decoupling, foreground-background co-discrimination, difficult negative sample training, and joint re-scoring, successfully reduces the false alarm rate in industrial part defect detection while maintaining or even improving defect recall and segmentation quality, demonstrating significant beneficial effects and practical application value.

[0133] This invention is not limited to the above-described optional embodiments. Anyone can derive other various forms of products under the guidance of this invention. However, regardless of any changes made in their shape or structure, any technical solution that falls within the scope of the claims of this invention shall be protected by this invention.

Claims

1. A method for detecting defects in industrial parts, characterized in that, Includes the following steps: An image to be detected is acquired, and a detection and segmentation network extracts multi-scale features from the image to be detected, and generates at least one candidate target, wherein the candidate target includes a candidate bounding box, a basic classification score and candidate segmentation information; The candidate target is decoupled from the feature, the candidate box context features are extracted from the multi-scale features according to the candidate box, and the candidate box context features are separated into candidate foreground features and candidate background features according to the candidate segmentation information. Multi-branch collaborative discrimination is performed on the candidate targets. Based on the candidate foreground features, foreground authenticity is judged to output a foreground discrimination score, and based on the candidate background features, background confusion risk is judged to output a background pass probability. By fusing the local classification features corresponding to the candidate target location, the candidate bounding box context features, and the candidate foreground features, an enhanced classification score is generated. The candidate targets are jointly re-scored, and the final confidence level is calculated based on the basic classification score, the enhanced classification score, the foreground discrimination score and the background pass probability. The candidate targets are then selected based on the final confidence level to output the defect detection results.

2. The method for detecting defects in industrial parts according to claim 1, characterized in that, The candidate segmentation information is a candidate soft mask; The feature decoupling step specifically involves: performing element-wise weighted operations on the candidate box context features and the candidate soft mask, followed by pooling, to obtain the candidate foreground features; And by performing element-wise weighting and pooling on a complementary weight of the candidate box context features and the candidate soft mask, the background features within the candidate box are obtained.

3. The method for detecting defects in industrial parts according to claim 2, characterized in that, The candidate background feature is formed by fusing the background feature within the candidate box with a ring-shaped background feature; the ring-shaped background feature is obtained by constructing an outer ring-shaped region of the candidate box and extracting features within that region.

4. The method for detecting defects in industrial parts according to claim 1, characterized in that, In the joint re-scoring step, the final confidence score is calculated by multiplicatively fusing the base classification score, the enhanced classification score, the foreground discrimination score, and the background score using probabilities.

5. The method for detecting defects in industrial parts according to claim 1, characterized in that, The method for extracting the context features of the candidate box is as follows: based on the size of the candidate box, a feature map with a corresponding resolution is dynamically selected from the multi-scale features, and a region of interest sampling operation is performed on the candidate box region on the feature map to obtain a feature map with a fixed spatial size.

6. The method for detecting defects in industrial parts according to claim 1, characterized in that, Before performing the feature decoupling and multi-branch collaborative discrimination, the method further includes: sorting all candidate targets according to the basic classification score, selecting a preset number of candidate targets, and performing the subsequent feature decoupling and multi-branch collaborative discrimination steps only on the selected candidate targets.

7. An industrial parts defect detection system, characterized in that, include: A feature extraction module is used to acquire an image to be detected, and a detection and segmentation network extracts multi-scale features of the image to be detected, and generates at least one candidate target, wherein the candidate target includes a candidate box, a basic classification score and candidate segmentation information; A feature decoupling module is used to extract candidate box context features from the multi-scale features based on the candidate box, and to separate the candidate box context features into candidate foreground features and candidate background features based on the candidate segmentation information. A collaborative discrimination module is used to perform foreground authenticity discrimination based on the candidate foreground features to output a foreground discrimination score, and to perform background confusion risk discrimination based on the candidate background features to output a background pass probability; And to fuse the local classification features corresponding to the candidate target location, the candidate box context features and the candidate foreground features to generate an enhanced classification score; A joint re-scoring module is used to calculate the final confidence level based on the basic classification score, the enhanced classification score, the foreground discrimination score and the background pass probability, and to filter the candidate targets based on the final confidence level to output the defect detection result.

8. A training method for an industrial part defect detection model, characterized in that, Includes the following steps: Construct a training sample set containing sample images with defect annotations and normal images without defects; A course-based hybrid candidate training strategy is adopted. During the training process, the real bounding boxes are used as the initial main source of candidates, and the sampling ratio of predicted boxes generated by the model and high-confidence false alarm candidate boxes mined from the normal images is gradually increased as the training progresses. The detection model is optimized using a joint loss function, which includes at least a main classification loss, a foreground discrimination loss, and a background discrimination loss. The normal images are periodically scanned using the currently trained detection model to uncover new high-confidence false positive candidate boxes and add them to the training process.

9. The training method according to claim 8, characterized in that, The training labels corresponding to the high-confidence false alarm candidate boxes are set as follows during training: the labels for the foreground authenticity discrimination task are negative samples, and the labels for the background confusion risk discrimination task are positive samples, so as to train the model to learn to distinguish between real defects and easily confused background patterns.