Defect detection system and method based on improved target detection model

By improving the target detection model, optimizing defect detection using Wasserstein distance and combined loss function, and combining multi-GPU training and deployment acceleration techniques, the problems of low efficiency in multi-scale target matching and deployment are solved, achieving high-precision and efficient defect detection.

CN121937422APending Publication Date: 2026-04-28SHANGHAI STRATOSPHERE INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-01-16
Publication Date
2026-04-28

AI Technical Summary

Technical Problem

Existing technologies for industrial defect detection suffer from problems such as difficulty in multi-scale target matching, limitations in loss function design, insufficient dynamics in model training, and low deployment efficiency, making it difficult to achieve high-precision detection and efficient deployment in complex industrial scenarios.

Method used

We replace the traditional IoU with Wasserstein distance (NWD) based on distribution similarity, combine regression loss and classification loss, optimize the defect detection model through multi-GPU parallel training and deployment acceleration modules, including data augmentation and iterative optimization processes, and use ONNX and TensorRT to accelerate model deployment.

Benefits of technology

It improves the detection accuracy of small targets and defects with extreme aspect ratios, enhances the robustness of the model in complex scenarios, and reduces inference time, meeting the real-time requirements of industrial production lines.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121937422A_ABST
    Figure CN121937422A_ABST
Patent Text Reader

Abstract

The invention discloses a flaw detection system and method based on an improved target detection model, the system comprises an image acquisition module, a data processing module and a target detection module, and the target detection module realizes flaw detection based on the trained target detection model. Wherein the target detection model uses distance measurement based on distribution similarity to match flaw targets; the loss function comprises combined regression loss and classification loss; the training process comprises an iterative optimization process based on false detection and missing detection feedback; the system further comprises a deployment acceleration module which is used for converting the trained model into an efficient format and carrying out reasoning acceleration. The core problems of multi-scale target matching, loss function optimization, model dynamic iteration and reasoning acceleration are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of image processing technology, and in particular relates to a defect detection system and method based on an improved target detection model. Background Technology

[0002] In industrial production, machine vision-based defect detection systems have gradually replaced traditional manual inspection to improve efficiency and accuracy. Current technologies primarily rely on two types of methods: 1. Traditional image processing techniques (such as OTSU threshold segmentation and Canny edge detection) have the drawback of relying on manually designed features, making it difficult to adapt to changes in lighting or complex backgrounds (such as mold spots on a face mask being confused with background textures), and the types of detection are limited.

[0003] 2. Deep learning object detection models (such as Faster R-CNN and YOLO series) have made breakthroughs in accuracy, but the following key problems still exist: Label assignment is not robust: IoU-based matching strategies fail for targets with extreme aspect ratios (such as the "broken warp" defect in fabric with an aspect ratio of 50:1) or small targets (such as PCB solder joint defects that occupy only a few pixels), resulting in insufficient positive samples and sparse supervision.

[0004] Limitations of loss function design: Single regression loss (such as Smooth L1) does not consider the geometric relationship of the bounding box, resulting in low localization accuracy; classification loss does not handle the imbalance of samples, causing the model to be biased towards high-frequency defect categories.

[0005] The evaluation function is imprecise: IoU-based rectangular bounding box evaluation functions implicitly assume that elements within the box are equally important, but in most cases, the target region can be refined to the inscribed elliptical bounding box of the target, especially for small targets such as blemishes. Figure 3 As shown.

[0006] Lack of dynamic optimization mechanism: The training process is fixed and cannot be adaptively adjusted for missed / false detection samples. The generalization ability drops sharply in occluded scenes (such as the inner wall of hole-type parts) or blurred images.

[0007] Low deployment efficiency: The model is not optimized for computational redundancy (such as FP32 precision inference), making it difficult to meet the real-time requirements of the production line (such as the requirement of ≤0.3s per frame for mask detection).

[0008] Therefore, there is an urgent need for a defect identification solution that can achieve both high-precision detection and efficient deployment in complex industrial scenarios, in order to solve the core problems of multi-scale target matching, loss function optimization, dynamic model iteration, and inference acceleration. Summary of the Invention

[0009] The technical problem to be solved by the present invention is to provide a defect detection system and method based on an improved target detection model to address the shortcomings of the prior art, and to solve the core problems of multi-scale target matching, loss function optimization, dynamic model iteration and inference acceleration.

[0010] The first aspect of this invention discloses a defect detection system based on an improved target detection model, including an image acquisition module, a data processing module, and a target detection module. The target detection module performs defect detection based on a trained target detection model, wherein the target detection model uses a distance metric based on distribution similarity to match defect targets. Loss functions include combined regression loss and classification loss; The training process includes an iterative optimization process based on feedback from false positives and false negatives; The system also includes a deployment acceleration module for converting trained models into an efficient format and accelerating inference.

[0011] The aforementioned defect detection system includes a distribution-based distance metric, namely Normalized Wasserstein Distance (NWD), which models bounding boxes as probability distributions and calculates the similarity between two elliptical bounding boxes. The NWD formula is as follows: ;in: B1 and B2 represent two bounding boxes; B1 is the model output box, and B2 is the annotation box. N(μ1,Σ1) and N(μ2,Σ2) represent the Gaussian distributions modeled by bounding boxes B1 and B2, respectively, where μ1 and μ2 are the distribution mean vectors, corresponding to the center coordinates of the bounding boxes; Σ1 and Σ2 are covariance matrices, representing the size and orientation of the bounding boxes; Wd is the Wasserstein distance, used to calculate the transportation cost between two distributions; τ is a temperature parameter used to control the normalized scale of the distance; When NWD is used for small object detection, it prioritizes matching bounding boxes with high center similarity.

[0012] In the aforementioned defect detection system, the first loss term of the combined regression loss is calculated based on the NWD and is used to optimize the accurate regression of defect localization and detection boxes, as shown in the following formula:

[0013] The second loss term is the Focal-CIoU loss, used to address classification errors in dynamically weighted hard samples. The formula is as follows:

[0014] Where γ is a parameter that controls the degree of outlier suppression, and its value ranges from [0.5, 2.0].

[0015] and The formula is expressed as:

[0016] This represents the Euclidean distance between the center points of the predicted bounding box and the ground truth bounding box.

[0017] and The penalty term represents the aspect ratio of the bounding box, calculated based on the arctangent difference in aspect ratio between the predicted and ground truth boxes:

[0018] It is a scaling factor used for balancing Impact:

[0019] Finally, the formula for the combined regression loss is expressed as:

[0020] in This is a weighting coefficient used to balance the influence of precise detection box regression and basic detection box regression. Its value ranges from 0 to 1 and is dynamically adjusted, increasing linearly with the total number of iterations. This achieves the goal of focusing on sample imbalance and learning basic detection positions in the early stages, and focusing on precise regression of detection boxes based on NWD evaluation results in the later stages. In the aforementioned defect detection system, the data processing module includes an image segmentation unit for extracting the foreground region and removing background noise from the input image. Image segmentation is implemented using a segmentation model, and the data processing module is also configured to automatically remove low-quality images. Image blur is calculated based on variance analysis, and images with variance below a threshold are removed.

[0021] The aforementioned defect detection system further includes a data augmentation unit in its data processing module, which generates augmented training data by randomly cropping, rotating, or synthesizing virtual defects, wherein the virtual defects are synthesized using image editing techniques.

[0022] The defect detection system described above includes the following steps in its target detection model training process: The training is based on an object detection model, which is a YOLO series model. During training iterations, multi-GPU parallel processing is used to accelerate the process. A learning rate decay strategy and an early stopping mechanism are introduced to prevent overfitting. Based on false positives or false negatives, the samples are manually reviewed and added to the training set for retraining.

[0023] In the aforementioned defect detection system, the deployment acceleration module uses the ONNX format for model conversion and employs the TensorRT or OpenVINO framework for inference acceleration, thereby controlling the inference time to within 110ms.

[0024] A second aspect of this invention discloses a defect detection method based on an improved target detection model, comprising the following steps: Acquire images of the target object; Preprocessing the image includes segmenting the foreground region and removing background noise; The trained object detection model is used to detect defects, wherein the object detection model matches defective targets using a distance metric based on distribution similarity; the loss function of the object detection model includes a combination of regression loss and classification loss; the training process of the object detection model includes an iterative optimization process based on feedback from false positives and false negatives; Deployment to accelerate model inference; Feedback and iterative optimization are based on the detection results.

[0025] The aforementioned defect detection method, wherein the distance metric based on distribution similarity includes Normalized Wasserstein distance (NWD), used to model bounding boxes as probability distributions and calculate the similarity between two elliptical bounding boxes; wherein the formula for NWD is expressed as: ;in: B1 and B2 represent two bounding boxes; B1 is the model output box, and B2 is the annotation box. N(μ1,Σ1) and N(μ2,Σ2) represent the Gaussian distributions modeled by bounding boxes B1 and B2, respectively, where μ1 and μ2 are the distribution mean vectors, corresponding to the center coordinates of the bounding boxes; Σ1 and Σ2 are covariance matrices, representing the size and orientation of the bounding boxes; Wd is the Wasserstein distance, used to calculate the transportation cost between two distributions; τ is a temperature parameter used to control the normalized scale of the distance; When NWD is used for small object detection, it prioritizes matching bounding boxes with high center similarity.

[0026] The aforementioned defect detection method includes a combined regression loss comprising NWD regression loss and Focal-CIoU classification loss.

[0027] The above defect detection method includes a preprocessing step that automatically removes inferior images, calculates image quality based on variance analysis, and removes images when the variance is below a preset threshold.

[0028] The aforementioned defect detection method includes an iterative optimization step that involves recording false positives or false negatives, manually reviewing them, adding them to the training set, and retraining the model to form a closed-loop system of detection → feedback → optimization → re-detection.

[0029] Compared with the prior art, the present invention has the following advantages: 1. We use distribution similarity (Wasserstein distance) instead of the traditional IoU (Intersection over Union) as the basis for matching defect targets with anchor frames. This strategy is better suited to small targets, defects with extreme aspect ratios, or blurry textures (such as "broken warp" defects in fabric or micro-hole defects in PCBs), improving the accuracy of positive and negative sample assignment.

[0030] 2. The Complete Intersection over Union (CIoU) Loss is adopted, which simultaneously optimizes the overlapping area of ​​the bounding boxes, the distance between the center points and the aspect ratio, to solve the problem of misalignment between traditional L1 / L2 loss and evaluation metrics (such as the positioning error of extreme aspect ratios in fabric defects).

[0031] 3. Combine focus loss or weighted cross-entropy to mitigate model bias caused by imbalanced samples.

[0032] 4. A dynamic feedback loop is introduced during training to add false positive / false negative samples from the validation set to the training set and adjust the weights of the loss function (e.g., increasing the loss weight for false negative samples). This mechanism significantly improves the model's robustness in complex scenarios (such as scenarios where defects on the inner wall of hole-type parts are occluded).

[0033] 5. Convert the training model into an efficient format (such as TensorRT engine or ONNX) and apply techniques such as layer fusion and quantization (INT8 precision) to improve inference speed (such as reducing the single-frame processing time of the YOLOv8 defect detection system from 50ms to 15ms).

[0034] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description

[0035] Figure 1 This is a system module diagram of Embodiment 1 of the present invention.

[0036] Figure 2 This is a flowchart of the method in Embodiment 2 of the present invention.

[0037] Figure 3 This is a schematic diagram of the detection frame used in this invention.

[0038] Figure 4 This is a comparison chart of the test results of the present invention. Detailed Implementation

[0039] Example 1 like Figure 1 As shown, a defect detection system based on an improved target detection model includes an image acquisition module, a data processing module, and a target detection module. The target detection module performs defect detection based on a trained target detection model, wherein the target detection model uses a distance metric based on distribution similarity to match defect targets. Loss functions include combined regression loss and classification loss; The training process includes an iterative optimization process based on feedback from false positives and false negatives; The system also includes a deployment acceleration module for converting trained models into an efficient format and accelerating inference.

[0040] In implementation, the system first uses a high-resolution industrial camera (e.g., 1920×1920 pixels) to capture images of the face masks under constant lighting conditions, avoiding glare interference. The data processing module preprocesses the images, such as segmenting the foreground of the face mask and removing background noise. The object detection module applies optimization strategies based on a trained YOLOv8 model: during training, NWD is used to match blemish bounding boxes; the loss function combines NWD regression loss and Focal-CIoU classification loss; and false positives (normal face masks misclassified as blemishes) and false negatives (blemishes not identified) are recorded, manually reviewed, and then added to the training set for retraining, forming a closed-loop optimization. The deployment acceleration module converts the model from PyTorch to ONNX format and then uses TensorRT to accelerate inference. For example, in a face mask production line, after the camera captures images, the system automatically segments the background (e.g., removing conveyor belt stains), the model quickly detects blemishes, and if a hair blemish is missed, the operator reviews the image and adds it to the training data, automatically updating the model and improving accuracy. The entire system achieves parallel processing through hardware such as GPUs.

[0041] The above solution addresses the issues of unstable and insufficient real-time tag allocation, improving the detection accuracy and speed of minor defects (such as blemishes). For example, the tag allocation strategy reduces false matches caused by small offsets, the combined regression loss optimizes localization and classification, and accelerated deployment ensures rapid response in industrial environments.

[0042] See Figure 3 and Figure 4 As shown, in this embodiment, the distance metric based on distribution similarity includes Normalized Wasserstein distance (NWD), which is used to model the bounding boxes as a probability distribution and calculate the similarity between two elliptical bounding boxes; wherein, the formula for NWD is expressed as: ;in: B1 and B2 represent two bounding boxes; B1 is the model output box, and B2 is the annotation box. N(μ1,Σ1) and N(μ2,Σ2) represent the Gaussian distributions modeled by bounding boxes B1 and B2, respectively, where μ1 and μ2 are the distribution mean vectors, corresponding to the center coordinates of the bounding boxes; Σ1 and Σ2 are covariance matrices, representing the size and orientation of the bounding boxes; Wd is the Wasserstein distance, used to calculate the transportation cost between two distributions; τ is a temperature parameter used to control the normalized scale of the distance; When NWD is used for small object detection, it prioritizes matching bounding boxes with high center similarity.

[0043] "B1 and B2 represent two bounding boxes, where B1 is the predicted bounding box output by the model, and B2 is the labeled ground truth bounding box. Modeling is achieved by using the center coordinates of the bounding boxes as the mean vectors μ1 and μ2 of a Gaussian distribution, and the width and height of the bounding boxes as the covariance matrices Σ1 and Σ2. Specifically, the predicted box B1 corresponds to the distribution N(μ1, Σ1), and the ground truth box B2 corresponds to the distribution N(μ2, Σ2). NWD similarity calculation is used to prioritize matching bounding boxes with similar center points, which is especially suitable for small object detection (such as blemishes)." In implementation, each bounding box (e.g., the rectangular box representing a blemish) is first modeled as a two-dimensional Gaussian distribution, where the distribution center (μ) corresponds to the coordinates of the bounding box's center point, and the covariance matrix (Σ) represents the width and height of the box (importance decreases from the center to the edge). NWD similarity calculation measures the "transportation cost" between two distributions using the Wasserstein distance—a smaller distance indicates higher similarity—and then normalizes it to the 0-1 range using an exponential function (the temperature parameter τ controls the scale, with a default value of 0.5). In actual matching, anchor boxes and ground truth boxes with close center points are prioritized. For example, when detecting a discolored blemish with a diameter of only 10 pixels, traditional IoU might fail to match due to a small offset, but NWD calculates similarity based on the center point (e.g., high similarity when the center distance is less than 5 pixels), automatically assigning it as a positive sample to ensure the model learns small target features. In implementation, predefined NWD function libraries (e.g., the scipy.stats module in Python for calculating Wasserstein distance) can be called in the training code, eliminating the need to rewrite the algorithm.

[0044] The above solution solves the problem of difficult detection of small targets (such as small blemishes with a low pixel ratio), improves matching stability, and reduces the false negative rate.

[0045] In this embodiment, the first loss term of the combined regression loss is calculated based on the NWD and is used to optimize the accurate regression of defect localization and detection boxes. The formula is as follows:

[0046] The second loss term is the Focal-CIoU loss, used to address classification errors in dynamically weighted hard samples. The formula is as follows:

[0047] "The first loss term of the combined regression loss is calculated based on NWD and is used to optimize defect localization. The formula is..." , where N p N represents the Gaussian distribution of the predicted bounding box (corresponding to B1). g The Gaussian distribution representing the ground truth bounding boxes (corresponding to B2) is used. This loss term ensures that bounding box regression focuses on matches with high center similarity. in This is a parameter that controls the degree of outlier suppression. The attenuation factor weights the loss of high-quality anchor boxes, giving them a more significant role in the total loss. Specifically, γ is a parameter that controls the degree of outlier suppression, used to dynamically adjust the weights of easy and difficult samples, with a value range of [0.5, 2.0] (default value 1.5). Attenuation factor IOU γ The loss function assigns higher weight to high-quality anchor boxes (IoU close to 1), making them more significant in the total loss. For example, when γ=1.5, the weight of the loss for high-quality samples increases significantly, reducing the gradient contribution of simple samples. and The formula is expressed as:

[0048] This represents the Euclidean distance between the center points of the predicted bounding box and the ground truth bounding box. , , The coordinates of the top left corner of the prediction box. ; , : Coordinates of the bottom right corner of the prediction box ; , The coordinates of the top-left corner of the true bounding box. ; , : The coordinates of the bottom right corner of the true bounding box ; It is the center point penalty term (here b is the predicted bounding box, b gt (for the true bounding box). c: The diagonal length of the minimum bounding box (containing both the predicted and ground truth boxes); and The penalty term representing the aspect ratio of the bounding box is used to penalize mismatches between the aspect ratios of the predicted and ground truth boxes. The formula is as follows:

[0049] Where w and h are the width and height of the predicted bounding box, w gt and h gt These are the width and height of the actual bounding box; It is a scaling factor used for balancing Impact:

[0050] Finally, the formula for the combined regression loss is expressed as:

[0051] in It is a weighting coefficient used to balance the influence of precise detection box regression and basic detection box regression. Its value ranges from 0 to 1 and is dynamically adjusted. It has a linear relationship with the total number of iterations, so that in the early stage, the focus is on learning the sample imbalance and basic detection positions, and in the later stage, the focus is on the precise regression of detection boxes based on the NWD evaluation results.

[0052] L NWD It is a regression loss based on NWD, the value of which is calculated from the Gaussian distribution parameters of the bounding box and is used for exact regression; L Focal-CIoU It is the Focal-CIoU classification loss, which combines the Focal loss and CIoU loss to handle imbalanced samples.

[0053] The NWD regression loss is calculated based on the Gaussian distribution parameters of the bounding box and is used to optimize defect location prediction. The Focal-CIoU loss combines the Focal loss (which assigns higher weights to high-quality classified samples) and the CIoU loss (which considers overlapping regions and center distance). The weight coefficient λ is dynamically adjusted proportionally to the number of iterations to balance the impact. In implementation, the loss function class can be defined using an open-source framework such as PyTorch, and the hyperparameters can be set. Those skilled in the art can directly call the combined regression loss in the model training script, avoiding manual calculation.

[0054] The above solution addresses the issues of insufficient positioning accuracy and sample imbalance. See [link to technical details] for more information. Figure 4 As shown, this includes improving the accuracy of locating irregular defects (such as creases) and reducing training bias in samples with a high proportion of blemishes, thereby improving overall detection accuracy.

[0055] In this embodiment, the data processing module includes an image segmentation unit for extracting the foreground region from the input image and removing background noise. The image segmentation is implemented using a segmentation model, and the data processing module is also configured to automatically remove inferior images. The image blur is calculated based on variance analysis, and the image is removed when the variance is below a threshold.

[0056] The segmentation unit uses a pre-trained model such as YOLOv11s-seg to segment the input image, extracting the foreground and masking the background region, thus avoiding the influence of dirt on the conveyor belt. Inferior images are automatically removed using variance analysis: the variance of the image's grayscale values ​​is calculated (low variance indicates blur or trailing), and images below a threshold (e.g., 50) are discarded. For example, during image acquisition, if camera trailing (motion blur) occurs, the system calculates the variance of the entire image's pixels (e.g., a blurred image with a variance of only 30) and automatically skips that frame to avoid false detections. In implementation, OpenCV library functions are called to calculate the variance, and a simple if condition is set to determine the threshold. Those skilled in the art do not need complex programming; this step can be added to the preprocessing pipeline. The above solution addresses the problem of severe background interference (e.g., false detection due to conveyor belt reflection), thereby reducing the false detection rate and improving image quality stability.

[0057] In this embodiment, the data processing module further includes a data augmentation unit, which is used to generate augmented training data by randomly cropping, rotating, or synthesizing virtual defects, wherein the virtual defects are synthesized through image editing technology.

[0058] During implementation, randomly selected image regions are cropped and scaled, with rotation angles varying within ±15 degrees, and the images are flipped horizontally to mirror them. Virtual blemishes are synthesized using image editing techniques (such as Photoshop or OpenCV libraries) to add simulated spots or discolored areas to the original image. For example, if the training set lacks small blemish samples, the system automatically synthesizes a virtual blemish (e.g., adding gray spots at random locations) on a normal face mask image, increasing data diversity. During implementation, data augmentation toolkits from TensorFlow or PyTorch (such as torchvision.transforms) are called, and parameters are set to automatically generate augmented data.

[0059] In this embodiment, the target detection model training process includes the following steps: The training is based on an object detection model, which is a YOLO series model. During training iterations, multi-GPU parallel processing is used to accelerate the process. A learning rate decay strategy and an early stopping mechanism are introduced to prevent overfitting. Based on false positives or false negatives, the samples are manually reviewed and added to the training set for retraining.

[0060] Implementation: Using YOLOv8 as the base model, training is performed in multi-GPU parallelism (e.g., 4 GPUs distributing batch data). The learning rate starts at 0.01 and decays by 10% every 10 epochs. An early stopping mechanism terminates training if the validation loss does not decrease. False detection / false negative feedback: The detection system records erroneous samples during runtime, which are manually reviewed and added to the training set for retraining. For example, after initial training and deployment to the production line, if a missed cropping defect is found, the operator labels the image and adds it to the training set, and the model automatically undergoes secondary training for optimization. Implementation utilizes PyTorch's DataParallel and early stopping callback functions, with a feedback loop recording erroneous samples in the database.

[0061] The above solution addresses the issues of training instability and long-term performance degradation, accelerates training, prevents overfitting, and enables continuous model optimization.

[0062] In this embodiment, the deployment acceleration module uses the ONNX format for model conversion and employs the TensorRT or OpenVINO framework for inference acceleration, so as to control the inference time to within 110ms.

[0063] Implementation: Export the trained PyTorch model to ONNX format (a generic intermediate representation), and then use TensorRT or OpenVINO to optimize the inference engine for acceleration (quantization of weights, fusion layers, etc.). For example, on a face mask detection pipeline, after model conversion and loading onto an NVIDIA GPU, the processing time for a single image was reduced from 200ms to 100ms. Implementation uses the NVIDIA TensorRT toolkit command-line conversion, eliminating the need for extensive coding.

[0064] Example 2 like Figure 2 As shown, a defect detection method based on an improved target detection model includes the following steps: Acquire images of the target object; Preprocessing the image includes segmenting the foreground region and removing background noise; The trained object detection model is used to detect defects, wherein the object detection model matches defective targets using a distance metric based on distribution similarity; the loss function of the object detection model includes a combination of regression loss and classification loss; the training process of the object detection model includes an iterative optimization process based on feedback from false positives and false negatives; Deployment to accelerate model inference; Feedback and iterative optimization are based on the detection results.

[0065] Implementation: The method steps are executed sequentially: First, images (1920×1920 pixels) are acquired using an industrial camera; foreground segmentation is preprocessed (e.g., the segmentation model outputs the mask area); the detection model applies NWD and combined loss to predict defect locations; acceleration is deployed to ensure rapid inference; finally, the model is retrained based on false positive / false negative feedback. For example, after the operator starts the system, the loop of acquisition → segmentation → detection → output results → error recording → model optimization is automatically completed. Those skilled in the art can write Python scripts to connect the various modules.

[0066] In this embodiment, the distance metric based on distribution similarity includes Normalized Wasserstein distance (NWD), used to model bounding boxes as probability distributions and calculate the similarity between two elliptical bounding boxes; wherein, the formula for NWD is expressed as: ;in: B1 and B2 represent two bounding boxes; B1 is the model output box, and B2 is the annotation box. N(μ1,Σ1) and N(μ2,Σ2) represent the Gaussian distributions modeled by bounding boxes B1 and B2, respectively, where μ1 and μ2 are the distribution mean vectors, corresponding to the center coordinates of the bounding boxes; Σ1 and Σ2 are covariance matrices, representing the size and orientation of the bounding boxes; Wd is the Wasserstein distance, used to calculate the transportation cost between two distributions; τ is a temperature parameter used to control the normalized scale of the distance; When NWD is used for small object detection, it prioritizes matching bounding boxes with high center similarity.

[0067] In this embodiment, the combined regression loss includes NWD regression loss and Focal-CIoU classification loss.

[0068] In this embodiment, the preprocessing step includes automatically removing inferior images, calculating image quality based on variance analysis, and removing images when the variance is lower than a preset threshold.

[0069] In this embodiment, the iterative optimization step includes recording false detections or missed detections, manually reviewing them, adding them to the training set to retrain the model, forming a closed-loop system of detection → feedback → optimization → re-detection.

[0070] It should be noted that the technical principle of Embodiment 2 is the same as that of Embodiment 1, and specific implementation details can be found in Embodiment 1.

[0071] The above description is merely a preferred embodiment of the present invention and does not constitute any limitation on the present invention. Any simple modifications, alterations, or equivalent structural changes made to the above embodiments based on the technical essence of the present invention shall still fall within the protection scope of the present invention.

Claims

1. A defect detection system based on an improved target detection model, comprising an image acquisition module, a data processing module, and a target detection module, characterized in that, The object detection module detects defects based on a trained object detection model, wherein the object detection model uses a distance metric based on distribution similarity to match defective targets; the loss function of the object detection model includes combined regression loss and classification loss; The training process of the object detection model includes an iterative optimization process based on feedback from false positives and false negatives; The system also includes a deployment acceleration module for converting trained models into an efficient format and accelerating inference.

2. The defect detection system according to claim 1, characterized in that, The distance metric based on distribution similarity includes the Normalized Wasserstein distance (NWD), used to model bounding boxes as probability distributions and calculate the similarity between two elliptical bounding boxes; the formula for NWD is as follows: ;in: B1 and B2 represent two bounding boxes; B1 is the model output box, and B2 is the annotation box. N(μ1,Σ1) and N(μ2,Σ2) represent the Gaussian distributions modeled by bounding boxes B1 and B2, respectively, where μ1 and μ2 are the distribution mean vectors, corresponding to the center coordinates of the bounding boxes; Σ1 and Σ2 are covariance matrices, representing the size and orientation of the bounding boxes; Wd is the Wasserstein distance, used to calculate the transportation cost between two distributions; τ is a temperature parameter used to control the normalized scale of the distance; When NWD is used for small object detection, it prioritizes matching bounding boxes with high center similarity.

3. The defect detection system according to claim 2, characterized in that, The first loss term of the combined regression loss is calculated based on the NWD and is used to optimize the accurate regression of defect localization and elliptical detection boxes. The formula is as follows: The second loss term is the Focal-CIoU loss, used to address classification errors in dynamically weighted hard samples. The formula is: Where γ is a parameter controlling the degree of outlier suppression, with a value range of [0.5, 2.0]; and The formula is expressed as: in The penalty term represents the aspect ratio of the bounding box, and is calculated based on the arctangent difference of the aspect ratio between the predicted box and the ground truth box. It is a scaling factor used for balancing The impact; Finally, the formula for the combined regression loss is expressed as: in It is a weighting coefficient used to balance the influence of precise detection box regression and basic detection box regression. Its value ranges from 0 to 1 and is dynamically adjusted, with a linear relationship with the total number of iterations.

4. The defect detection system according to claim 1, characterized in that, The data processing module includes an image segmentation unit for extracting the foreground region from the input image and removing background noise. The image segmentation is implemented using a segmentation model. The data processing module is also configured to automatically remove inferior images, calculate image blur based on variance analysis, and remove the image when the variance is below a threshold.

5. The defect detection system according to claim 1, characterized in that, The data processing module also includes a data augmentation unit, which generates augmented training data by randomly cropping, rotating, or synthesizing virtual defects, wherein the virtual defects are synthesized using image editing technology.

6. The defect detection system according to claim 1, characterized in that, The training process for an object detection model includes the following steps: The training is based on an object detection model, which is a YOLO series model. During training iterations, multi-GPU parallel processing is used to accelerate the process. A learning rate decay strategy and an early stopping mechanism are introduced to prevent overfitting. Based on false positives or false negatives, the samples are manually reviewed and added to the training set for retraining.

7. The defect detection system based on the improved target detection model according to claim 1, characterized in that, The deployment acceleration module uses the ONNX format for model conversion and employs the TensorRT or OpenVINO framework for inference acceleration, aiming to keep the inference time within 110ms.

8. A defect detection method based on an improved target detection model, characterized in that, Includes the following steps: Acquire images of the target object; Preprocessing the image includes segmenting the foreground region and removing background noise; Defects are detected using a trained object detection model, wherein the object detection model matches defect targets using a distance metric based on distribution similarity; the loss function of the object detection model includes a combination of regression loss and classification loss; The training process of the object detection model includes an iterative optimization process based on feedback from false positives and false negatives; Deployment to accelerate model inference; Feedback and iterative optimization are based on the detection results.

9. The defect detection method according to claim 8, characterized in that, The distance metric based on distribution similarity includes the Normalized Wasserstein distance (NWD), used to model bounding boxes as probability distributions and calculate the similarity between two elliptical bounding boxes; the formula for NWD is as follows: ;in: B1 and B2 represent two bounding boxes; B1 is the model output box, and B2 is the annotation box. N(μ1,Σ1) and N(μ2,Σ2) represent the Gaussian distributions modeled by bounding boxes B1 and B2, respectively, where μ1 and μ2 are the distribution mean vectors, corresponding to the center coordinates of the bounding boxes; Σ1 and Σ2 are covariance matrices, representing the size and orientation of the bounding boxes; Wd is the Wasserstein distance, used to calculate the transportation cost between two distributions; τ is a temperature parameter used to control the normalized scale of the distance; When NWD is used for small object detection, it prioritizes matching bounding boxes with high center similarity.

10. The defect detection method according to claim 8 or 9, characterized in that, The combined regression loss includes NWD regression loss and Focal-CIoU regression loss.