Industrial defect image scoring method and system based on DINOv3 and label reconstruction
Patent Information
- Application Number
- CN202611151896.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-31
- Publication Date
- 2026-10-02
AI Technical Summary
[0005]本发明的目的:为了克服现有技术的缺陷,本发明提供了一种基于DINOv3与标签重构的工业缺陷图像评分方法及系统,解决了现有模型预测值向均值坍缩、难以区分关键风险样本的问题
(1)S1标签重构策略的效果:通过设置预设的分界分位点,将评分值低于该分位点,即表征合格品,的原始评分标签统一截断至预设的截断目标值,并对多评分样本取截断后均值作为监督标签值,有效降低了低分段样本的标注噪声,缓解了多人标注分歧,提高了监督信号的稳定性,同时,将无意义的合格品细粒度差异合并,使模型聚焦于缺陷品的真实质量梯度,消除了长尾低分样本对回归任务的噪声干扰;
Smart Images

Figure CN122866797A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer vision and intelligent quality assessment technology, specifically relating to an industrial defect image scoring method and system based on DINOv3 and label reconstruction. Background Technology
[0002] Existing defect scoring schemes mostly use classification models or conventional regression models, such as MSE / L1 loss. When faced with skewed score distribution and uncertain labeled samples, the predicted values tend to concentrate in the middle range, such as 7-8 points in a 10-point scoring system. This can easily lead to a "prediction collapse" phenomenon, making it difficult for the model to distinguish key risk samples.
[0003] In addition, the low-score segments (1-4) in the original annotations usually have higher noise and subjective differences. If they are used directly for training, they will reduce the model's sensitivity to high-risk boundary samples, resulting in the model having an acceptable overall error but insufficient discrimination ability on key samples.
[0004] Existing solutions generally lack an integrated design for label governance, model structure, loss function, training strategy, and inference evaluation, making it difficult to balance convergence stability, business interpretability, and actual deployment effectiveness. Summary of the Invention
[0005] The purpose of this invention is to overcome the shortcomings of the prior art. This invention provides an industrial defect image scoring method and system based on DINOv3 and label reconstruction, which solves the problems of existing model predictions collapsing to the mean and difficulty in distinguishing key risk samples.
[0006] The first objective of this invention is to provide an industrial defect image scoring method based on DINOv3 and label reconstruction, comprising the following steps: S1, data acquisition and label reconstruction: acquiring an industrial defect image and one or more corresponding original scoring labels; the original scoring labels have a preset continuous scoring interval, within which there is a preset boundary point for pass or defect; all original scoring labels that represent pass or defect with scores below the boundary point are uniformly truncated to a preset truncation target value; for the same image with multiple original scoring labels, the arithmetic mean of the truncated scores is calculated as the supervision label value of the image; S2. Feature Extraction and Fusion: The industrial defect image processed in step S1 is input into the DINOv3 Vision Transformer backbone network to extract the classification token (CLS Token) features and image patch token (PatchToken) features of the image. The global mean pooling is performed on all PatchToken features along the sequence dimension to obtain the Patch mean features. The CLS Token features and the Patch mean features are concatenated along the feature dimension to obtain the fused feature vector. S3. Regression Prediction: Input the fused feature vector obtained in step S2 into the multilayer perceptron regression head, constrained by the Sigmoid activation function, and output the predicted score normalized to the preset numerical range. S4. Model Training: The supervision label values obtained in step S1 are normalized to the preset numerical range and used as the training target. A piecewise loss function is adopted, which applies nonlinear gradient enhancement to the small error range and linear gradient to the large error range. The DINOv3 backbone network and the multilayer perceptron regression head are trained in a distributed data parallel manner through backpropagation. S5. Inference and Inverse Normalization: Perform Test-Time Augmentation (TTA) on the test image. Input the original image and the horizontally flipped image into the trained model respectively, and take the average of the two predicted scores. Map the average result back to the effective score range through inverse normalization transformation, and use it as the final score output.
[0007] The above technical solution has the following beneficial effects: (1) Effect of S1 label reconstruction strategy: By setting a preset threshold, the original score labels of qualified products with scores below the threshold are uniformly truncated to the preset truncation target value. The mean of the truncated samples is taken as the supervision label value, which effectively reduces the labeling noise of low-score samples, alleviates the discrepancy of multiple labeling, and improves the stability of supervision signals. At the same time, meaningless fine-grained differences of qualified products are merged, so that the model focuses on the true quality gradient of defective products and eliminates the noise interference of long-tail low-score samples on the regression task. (2) Effect of S2 feature fusion: By concatenating the mean of CLS Token and Patch Token, the regression head can simultaneously perceive the global classification semantics of the image and the spatial texture statistics of the whole image, realizing the dual-path information complementarity of global semantics and local texture, enabling the regression head to simultaneously perceive the overall severity of the defect and the local texture details. (3) Effect of S4 piecewise loss function: Wing Loss or Focal L1 Loss is used as the training objective function. By nonlinearly weighting the prediction error, the characteristic of the gradient of the traditional L1 / L2 loss function being constant or monotonically decreasing is broken, which forces the model to not stay near the mean of the training set and effectively suppresses prediction collapse. Experimental verification shows that the standard deviation of the model prediction after adopting the scheme of this invention is 1.8474, which is very close to the standard deviation of the true label 1.8954, while the baseline model completely collapses, proving that the model has completely gotten rid of the stubborn problem of prediction collapse; the MAE of the scheme of this invention is 0.6236, which is far better than the baseline MAE of 1.6825. (4) Effects of S5 TTA and inverse normalization: The test time enhancement strategy of horizontal flipping reduces the prediction bias caused by unilateral lighting or shooting angle; the inverse normalization transformation maps the model output back to the effective scoring range, making the prediction results business interpretable and easy for quality inspectors to understand and accept.
[0008] A further feature of the present invention is that the dividing point is the 40th percentile of the continuous scoring interval from low to high, the cutoff target value is the score value adjacent to the score value corresponding to the dividing point and facing the high-score defect side, and the effective scoring interval is the portion of the continuous scoring interval from the cutoff target value to the upper limit of the interval.
[0009] By adopting the above further settings, the dividing point is defined as the 40th percentile of the continuous scoring interval from low to high, the truncation target value is the score value adjacent to the score value corresponding to the dividing point and facing the high-scoring defect side, and the effective scoring interval is the part from the truncation target value to the upper limit of the interval. This limitation clarifies the dividing position between qualified and defective products under a specific scoring system, as well as the effective scoring range of the model's actual learning and reasoning after truncation. This enables those skilled in the art to directly determine the corresponding specific values according to different scoring systems, while ensuring the business rationality of the truncation operation, that is, the truncation target value is exactly the lowest grading starting point of the defective product.
[0010] A further setting of the present invention: The DINOv3 backbone network in step S2 adopts the ViT-B / 16 variant, and the input image resolution is set to 518×518 pixels. The DINOv3 backbone network is input with an image of 518×518 pixel resolution, and is divided into 16×16 block sizes by the Patch Embedding layer to generate 1024 Patch Tokens, each with a dimension of 768. The CLS Token feature dimension is 768, the Patch mean feature dimension is 768, and the dimension of the concatenated fused feature vector is 1536. The multilayer perceptron regression head consists of three fully connected layers. The input and output dimensions of each fully connected layer are as follows: the first layer linearly maps 1536 dimensions to 512 dimensions, the second layer linearly maps 512 dimensions to 256 dimensions, and the third layer linearly maps 256 dimensions to 1 dimension. The first two layers are followed by a GELU activation function and a Dropout layer with a Dropout rate of 0.3.
[0011] With the above further settings, the 518×518 resolution increases the pixel area by about 5.4 times compared to the DINOv3 pre-training standard resolution of 224×224, enabling the model to capture finer-grained defect texture information, which is particularly suitable for the accurate identification of minute flaws in industrial defect detection.
[0012] A further arrangement of the present invention: in step S4, the training adopts a full-parameter fine-tuning strategy and uses layered learning rates, wherein the learning rate of the DINOv3 backbone network is set to one tenth of the learning rate of the regression head, and the learning rate of the DINOv3 backbone network is , and the learning rate of the multi-layer perceptron regression head is ; a cosine annealing learning rate scheduling strategy is adopted, and the minimum learning rate is attenuated to 0; the single-GPU batch size is 16, and the NVIDIA Collective Communication Library (NCCL) backend is used for distributed communication.
[0013] With the above further arrangement, full-parameter fine-tuning enables the backbone network to adapt to the distribution of industrial defect data; layered learning rates enable the regression head to quickly converge to a task-related optimal solution space with a large step size, while fine-tuning the backbone network with a small step size to avoid catastrophic forgetting of pre-trained knowledge. The cosine annealing strategy enables the model to quickly explore the parameter space with a large step size in the early training stage, and converge finely with small fluctuations in the later training stage, avoiding oscillation near the optimal solution.
[0014] A further arrangement of the present invention: in step S4, the loss function for nonlinearly weighting the prediction error is the Wing Loss loss function, and its mathematical expression is: , ; wherein, e is the difference between the prediction score described in step S3 and the supervision label value described in step S1, w is a preset small error interval width threshold, ε is a preset curvature parameter, and C is a continuous offset constant; Alternatively, the loss function for nonlinearly weighting the prediction error is the Focal L1 Loss loss function, and its mathematical expression is: , wherein, N is the total number of samples in one training batch, i is the sequence number of the sample in the batch, is the prediction error of the i-th sample, and γ is a preset focusing parameter greater than 1; the Wing Loss loss function and the Focal L1 Loss loss function are exclusively selected through configuration parameters, and only one of the loss functions is used in a single training.
[0015] With the above further arrangement, the segmented loss function is defined as Wing Loss or Focal L1 Loss; in the small error interval (|e|<w), the gradient of the logarithmic function of Wing Loss is much larger than the constant gradient of L1, which can provide stronger fine-grained optimization signals for the model, and is particularly suitable for regression scenarios that require accurate distinguishing of adjacent scores; Focal L1 Loss solves the problem of class imbalance or mean collapse by amplifying hard samples and suppressing easy samples.
[0016] A further setting of the present invention: the preset small error interval width threshold w = 0.2, the preset curvature parameter ε = 0.1; the preset focusing parameter γ = 2.0; The formula for the inverse normalization transformation in step S5 is: ;in For the final score, R is the predicted mean, R is the width of the rating interval, and B is the lower limit of the rating interval.
[0017] The above further settings further limit the hyperparameter values of Wing Loss, Focal L1, and the inverse normalization formula. The inverse normalization transformation adopts the order of averaging first and then inverse normalization. Based on the consideration of numerical stability, the Sigmoid at the model output combined with the clamp ensures that the predicted score is strictly within the [0,1] interval. The mean operation within this interval can completely avoid numerical overflow.
[0018] Another objective of this invention is to provide an industrial defect image scoring system based on DINOv3 and label reconstruction, comprising: a data governance module for parsing annotation files, obtaining industrial defect images and one or more original scoring labels corresponding to them, wherein the original scoring labels have a preset continuous scoring interval, wherein there is a preset dividing point within the continuous scoring interval, truncating labels whose scoring values are lower than the scoring values corresponding to the dividing point to a preset truncation target value, calculating the mean after truncation for multiple scoring samples, and generating a training set and validation set partitioning list; The feature extraction module, based on the DINOv3 visual Transformer backbone network, is used to extract the CLSToken and Patch Token features of the input image, and then concatenates the global mean of the Patch Token with the CLS Token to output the fused features. The regression prediction module includes a multilayer perceptron regression head, which is used to receive the fused features and output a continuous score normalized to a preset numerical range by a Sigmoid constraint. The training optimization module employs a distributed data parallelism and hierarchical learning rate strategy, using a loss function that non-linearly weights the prediction error for model training. The inference evaluation module is used to perform test-time enhancement, predictive score denormalization, and output sample-level error statistics and visualization reports. In the data governance module, if the labeled score exceeds the preset continuous scoring range when parsing the labeled file, the score that exceeds the range is silently discarded; if all labels of an image exceed the range, the image is skipped and not included in the training set; if the image file is missing or corrupted, causing reading errors, a warning log is printed and a pure black image is returned as a replacement.
[0019] By adopting the above technical solution, each module forms a closed-loop process at the engineering level, encompassing data, training, inference, and evaluation, thereby enhancing reproducibility, auditability, and deployment availability. This closed-loop design ensures that the entire process from initial XML annotation to the final evaluation report requires only three commands, with no manual intervention. Experiments can be reproduced with a single click, results can be audited sample by sample, and models can be version-managed. Attached Figure Description
[0020] Figure 1 This is an architecture diagram of the evaluation method in a specific embodiment of the present invention; Figure 2 This is a schematic diagram of the evaluation system in a specific embodiment of the present invention. Detailed Implementation
[0021] The technical solutions in this embodiment will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0022] An industrial defect image scoring method based on DINOv3 and label reconstruction specifically includes the following steps: Step S1, Data Acquisition and Tag Reconstruction, this step corresponds to Figure 1 The data preparation phase includes the following specific steps: P1-1. Obtaining Original Rating Labels: In this embodiment, images of defects in the appearance of a mobile phone body are used as the object. Each image is labeled by one or more quality inspectors. The labeling dimensions include defect type (dents, cracks, leather damage) and severity. A ten-point rating system (1 to 10 points) is adopted, with a preset continuous rating range of 1 to 10 points. The more severe the defect, the higher the score. Due to the multi-person annotation mechanism, the same image may have two or more severity scores; Read the original rating labels corresponding to each image in the XML annotation file and extract the original ratings from 1 to 10. P1-2. Low-score truncation: In this embodiment, the original score label has a preset dividing point within the interval to distinguish between qualified and defective products. In this embodiment, the dividing point is the 40th percentile of the continuous score interval from low to high, i.e., 4 points. The truncation target value is the score value adjacent to the score value corresponding to the dividing point and facing the high-score defect side, i.e., 5 points. All original score labels with scores lower than the score value corresponding to the dividing point, i.e., ≤4 points, are uniformly truncated to the preset truncation target value of 5 points. The basis is: In industrial quality inspection scenarios, 1 to 4 points represent no defects or almost no defects, which are all qualified products; 5 points and above represent visible defects, which need to be graded. The core goal of quality inspection is to distinguish the defect level, rather than distinguish between perfect and extremely minor defects. Therefore, 1 to 4 points are uniformly mapped to 5 points, the lowest defect dividing point, merging meaningless fine-grained differences, so that the model focuses on the true quality gradient of 5 to 10 points, while eliminating the noise interference of long-tail low-score samples on the regression. P1-3, Multi-rating mean fusion: For the same image with multiple original rating labels, after truncation, the arithmetic mean of each rating value is directly taken as the supervision label value of the image, without outlier detection or standard deviation threshold determination. It should be noted that if the annotation score of an image is found to be outside the range of 1 to 10 in the XML, the score that exceeds the range will be silently discarded; if all the labels of an image are outside the range, the image will be skipped and will not be included in the training set; if an image file is missing or corrupted, causing an error in reading, a warning log will be printed, and a pure black image will be returned as a replacement.
[0023] P1-4. Data partitioning: All valid samples after the above processing are divided into training set and validation set in an 8:2 ratio. In this embodiment, the training set has 15,180 images and the validation set has 3,796 images, for a total of 18,976 images. The fixed random seed is 42 to ensure that the partitioning results are completely consistent each time.
[0024] Step S2: Feature extraction and fusion. This step corresponds to... Figure 1 The training optimization phase includes the following specific steps: P2-1. Backbone Network Input and Preprocessing: The industrial defect image processed in step S1 is scaled to 518×518 pixels and normalized according to the mean [0.485, 0.456, 0.406] and standard deviation [0.229, 0.224, 0.225]. This is then input into the DINOv3 vision Transformer backbone network. In this embodiment, the DINOv3 backbone network adopts the ViT-B / 16 variant, with a total of 12 Transformer layers, an embedding dimension of 768, 12 attention heads, an FFN expansion ratio of 4x, GELU activation function and LayerNorm (eps=1e-5) normalization, rotational position encoding (RoPE), a fundamental frequency of 100, coordinate normalization mode of "separate", and a 2x coordinate scaling. The backbone network is pre-trained in a self-supervised manner on the large-scale dataset LVD-1689M (1.689 billion images).
[0025] P2-2, Token Generation: The image is divided into 16×16 blocks by the Patch Embedding layer, generating 1024 Patch Tokens, each with a dimension of 768. The front end concatenates one CLS Token and four register Tokens to form a complete Token sequence with a length of 1029 and a dimension of 768 for each Token. This sequence is then fed into a 12-layer Transformer encoder for layer-by-layer interaction. At the end of the encoder, a uniform LayerNorm normalization is applied to all Tokens, and the output is a 768-dimensional CLS Token and all 1024 768-dimensional Patch Tokens.
[0026] P2-3. Feature fusion: Take the global mean pooling of all Patch Tokens along the sequence dimension, compress the 1024 Patch Tokens (each with a dimension of 768) into a single global description vector (with a dimension of 768), and concatenate the CLS Token with the mean pooled Patch vector along the feature dimension to obtain a 1536-dimensional fused feature vector.
[0027] Step S3, Regression Prediction: This step corresponds to... Figure 1 The training optimization phase includes the following specific steps: The fused feature vector (1536 dimensions) obtained in step S2 is input into the multilayer perceptron regression head: the first layer linearly maps the 1536 dimensions to 512 dimensions, and then performs GELU activation and Dropout (p=0.3) regularization; the second layer maps the 512 dimensions to 256 dimensions, and then performs GELU activation; the third layer maps the 256 dimensions to a 1-dimensional scalar. Finally, the output is compressed to the (0,1) interval by the Sigmoid function and forcibly constrained to the range [0,1], outputting a normalized prediction score. CLS Token carries image-level global classification semantics, while Patch Token's mean pooling aggregates the spatial texture information of the entire image. The combination of the two allows the regression head to simultaneously perceive the overall severity of the defect and local texture details.
[0028] Step S4, Model Training: This step corresponds to... Figure 1 The training optimization phase includes the following specific steps: P4-1. Normalize the supervision label values. Linearly normalize the supervision label scores obtained in step S1 from [5,10] to the interval [0,1] as the model training target. P4-2, Loss function: Using the normalized supervision label value as the training objective, a piecewise loss function is adopted, and the DINOv3 backbone network and multilayer perceptron regression head are optimized through backpropagation. In this embodiment, the loss function used is Wing Loss, and its mathematical expression is as follows: , ; Where e is the difference between the predicted score in step S3 and the supervision label value in step S1, w is the preset small error interval width threshold, ε is the preset curvature parameter, and C is the continuous offset constant. In this embodiment, w=0.2, ε=0.1, ; Alternatively, Focal L1 Loss can be used as the loss function, and its mathematical expression is: ; Where N is the total number of samples in a training batch, and i is the sequence number of the sample in the batch. Let γ be the prediction error of the i-th sample, and γ be the preset focusing parameter. In this embodiment, γ = 2.0. The Wing Loss and Focal L1 Loss mentioned above are mutually exclusive in configuration parameters, and only one of the loss functions is used in a single training session.
[0029] P4-3, Distributed Data Parallel Training: Distributed data parallel training is adopted, and NCCL is used for the communication backend. The batch size of each GPU is 16. Both the training set and the validation set are divided into samples using a distributed sampler to ensure that each GPU processes non-overlapping subsets of data. Before each training round, the sampler division is changed by setting a random seed to ensure that each GPU sees different data divisions in different training rounds. In terms of cross-process metric aggregation, the training loss and MAE of the validation phase are accumulated in their respective processes, summed through reduction operations, and then divided by the total number of processes and the number of data loader batches to obtain the global average. Progress bar display and model saving are only executed in the main process.
[0030] P4-4. Full parameter fine-tuning and hierarchical learning rate: In this embodiment, the DINOv3 backbone adopts a full parameter fine-tuning strategy, that is, all parameters of the backbone participate in backpropagation. A hierarchical learning rate strategy is adopted, and the parameters are grouped according to whether the model parameter name contains the backbone network keyword: parameters whose names contain the backbone network keyword are assigned to the backbone network group, and the remaining parameters (i.e., MLP regression heads) are assigned to the regression head group. The optimizer used is AdamW, with a weight decay coefficient of 0.05, a first-order momentum coefficient β1=0.9, and a second-order momentum coefficient β2=0.999; The specific learning rate configuration is as follows: Backbone network (DINOv3 ViT-B / 16): MLP (Mean Regression Head): The learning rate of the backbone network is set to one-tenth of that of the regression head.
[0031] P4-5, Learning Rate Scheduling and Early Stopping: The learning rate scheduler uses a cosine annealing strategy with a period parameter set to 200. Within 200 training cycles, the learning rate smoothly decreases from its initial value along a cosine curve to near zero. The early stopping mechanism uses the denormalized MAE on the validation set, mapped back to the original 5-10 scale mean absolute error, as the monitoring metric. If the validation set MAE does not decrease further for 20 consecutive rounds, early stopping is triggered, terminating the training cycle. The latest model is saved for each training epoch, and the optimal model is saved only when the MAE on the validation set is optimal. Training interruption recovery and version rollback are supported.
[0032] P4-6: Experiment tracking, integrating with the MLflow experiment management platform to achieve centralized tracking of parameters, metrics, and models throughout the entire training lifecycle. Recorded parameters include model name, input resolution, batch size, learning rate, weight decay, loss type, total number of rounds, early stopping patience value, etc.
[0033] Step S5: Reasoning and Inverse Normalization, this step corresponds to Figure 1 The reasoning and evaluation phase in the process includes the following specific steps: P5-1. Preprocessing: Perform the same preprocessing as training on the images to be evaluated: scale to 518×518 pixels and normalize by mean [0.485, 0.456, 0.406] and standard deviation [0.229, 0.224, 0.225].
[0034] P5-2, TTA test enhancement: Input the original image and the horizontally flipped image into the trained model respectively to obtain two normalized spatial prediction scores, and take the average of them; It should be noted that a horizontal flipping strategy is always used to ensure that the same prediction results are always produced for the same input, instead of vertical flipping and multi-scale TTA. The reason for not using vertical flipping is that in the scenario of detecting defects in the appearance of mobile phone body, the image has a clear vertical spatial semantics. The two are fundamentally different in terms of structure and defect distribution pattern. If vertical flipping is applied, the top bump area is mapped to the bottom, and the bottom scratch is mapped to the top. The defect spatial distribution of the image conflicts with the vertical correspondence learned by the model from the labeled data during the training phase. As a result, the prediction result after flipping introduces semantic noise, which reduces rather than improves the inference accuracy.
[0035] The reason for not adopting multi-scale TTA is that the current solution already uses a high-resolution input of 518×518, which is about 5.4 times larger than the DINOv3 pre-training standard of 224×224. The details of defect textures have been fully preserved. Although multi-scale TTA can theoretically further improve robustness, it will bring a significant increase in inference latency, which is too costly in the current batch inference scenario. In addition, the current single-scale plus horizontal flip TTA has achieved stable evaluation accuracy, and the marginal benefits of multi-scale are limited.
[0036] P5-3, Inverse Normalization: Inverse normalize the above mean results to the effective score interval [5,10]. The inverse normalization formula is as follows: ;in For the final score, R is the width of the rating interval, and B is the lower limit of the rating interval; In this embodiment, the scaling factor of 5.0 corresponds to the original score interval width R = 10 - 5 = 5, and the offset of 5.0 corresponds to the lower limit B of the original score interval. The final score... This yields a continuous score within the interval [5,10].
[0037] P5-4, Output and Evaluation: Output sample-level prediction scores, including five columns: image name, prediction score, ground truth value, absolute error, and whether there is a ground truth label. The prediction results for any single image can be traced. Output error statistics: MAE (Mean Absolute Error), MSE (Mean Square Error), RMSE (Root Mean Square Error) (Accuracy rate with an error ≤ 0.5 points) (accuracy with an error ≤ 1.0 point), as well as Pearson correlation coefficient and Spearman correlation coefficient, are used to comprehensively evaluate the model's prediction accuracy and the correlation between predicted and true values.
[0038] It automatically generates visualization results charts, including error distribution histograms, GT-Pred scatter plots, and prediction visualization overlays. Each test chart automatically overlays predicted and actual values with text annotations and saves them. It also generates statistical analysis reports, including error distribution analysis and correlation diagnosis, supporting comprehensive evaluation and manual auditing of model behavior.
[0039] Experimental Verification: To verify the effectiveness of the proposed solution for predicting collapse problems, the following two sets of comparative experiments were designed: Control group: Baseline model: The predicted scores of all test samples were uniformly set to the training set label mean of 7.13 points, and no learning was performed; Experimental group: ViT-B backbone and Wing Loss: DINOv3 ViT-B was used as the backbone network, and training was performed using Strategy E label reconstruction and Wing Loss loss function.
[0040] Calculate the mean absolute error (MAE) and the standard deviation of the predicted values (PredStd) for both groups: Among them, the predicted standard deviation is a core indicator for diagnosing whether a model has experienced predictive collapse. It is judged by comparing it with the true labeled standard deviation (GTStd). The closer PredStd is to the true labeled standard deviation (GTStd), the more it indicates that the model retains the dispersion of the original score distribution and can effectively distinguish different levels; mean absolute error. , This represents the total number of test samples with ground truth annotations. For the first The model's predicted score after TTA mean fusion and inverse normalization of each sample. This is the actual labeled score after processing with the corresponding Strategy E; Predicted standard deviation (PredStd): ,in This is the average of all predicted scores.
[0041] If the model experiences prediction collapse, its predicted standard deviation (PredStd) will be much smaller than the true labeled standard deviation (GTStd), and the MAE will approach the baseline error of the constant prediction mean. In this experiment, GTStd = 1.8954. Specific experimental results are shown in the table below:
[0042] Experiments have verified that after adopting the scheme of this invention (ViT-B+Wing Loss), the standard deviation of the model prediction (PredStd) is 1.8474, which is close to the standard deviation of the true label (GTStd=1.8954), achieving a state of no collapse, and the MAE is 0.6236, which is far better than the baseline MAE (1.6825). To further verify the ability of the present invention to distinguish key samples, boundary samples were analyzed separately. Boundary samples refer to samples whose true scores are at both ends of the distribution (the low range of 5-6 points and the extreme range of 10 points). These samples have the largest error in the collapse model and also happen to be the critical decision interval for pass / fail determination in industrial quality inspection. The specific results are shown in the table below:
[0043] The MAE in the low-score segment (5-6 points) decreased from 2.13 points to 0.19 points, meaning that the model's judgment error for minor defects and no obvious defects has decreased from more than 2 levels to less than 0.2 levels; the MAE in the extreme value segment (10 points) decreased from 2.87 points to 0.39 points, meaning that the recognition accuracy for the most serious defects has improved from almost random to highly reliable.
[0044] Furthermore, to measure the overall stability of the model in fine-grained scoring, the error threshold accuracy is calculated. The error threshold accuracy measures whether the error between the model's predicted value and the true value falls within a preset tolerance range. Its calculation formula is as follows: Accuracy with an error ≤ 0.5 points ; Accuracy with an error ≤ 1.0 point ; in, This is an indicator function that takes the value 1 if the condition is true and 0 otherwise. The percentage of samples whose predicted values differ from the actual values by no more than 0.5 points can be considered as the exact hit rate. The percentage of samples with an error of no more than 1.0 points can be considered as the acceptable bias rate. Both are presented as percentages, and the higher the percentage, the stronger the stability of the model in fine-grained scoring.
[0045] In this experiment, 960 images were randomly selected from the validation set as the test set, which was not used for training or early stopping monitoring to ensure the reproducibility of the experiment. The total number of test samples was N=960, and the prediction error for each sample was calculated. The final result on the entire test set Reaching 62.9%, The accuracy rate reached 83.9%, indicating that the model possesses stable and reliable discrimination ability in fine-grained scoring tasks.
[0046] This embodiment also provides an industrial defect image scoring system based on DINOv3 and tag reconstruction for implementing the above method. This system employs a distributed server architecture or is deployed on a single high-performance workstation. Figure 2 As shown, it specifically includes the following functional modules: Data Governance Module: This module is used to perform the label reconstruction and dataset partitioning operations described in step S1. The module uses the annotation file parser as the entry point, reads the XML format annotation file generated in the quality inspection process, traverses each image node to extract the original score list, and the parser has built-in score interval verification logic: when a score value is detected to be outside the preset continuous interval of 1 to 10 points, the score is marked as invalid and silently discarded; if all scores associated with an image are invalid, the image is skipped and a warning message is recorded in the log. For valid scores that pass the verification, the truncation processor uniformly resets all values below the preset threshold (i.e., 4 points) to the truncation target value (i.e., 5 points). Then, the mean fusion processor is called to calculate the arithmetic mean of multiple truncated scores of the same image to generate the supervision label value of the image. Finally, the partition manager uses a fixed random seed to partition all valid samples into training set and validation set at a ratio of 8:2, and outputs a list file containing the image path and label mapping relationship.
[0047] Feature Extraction Module: This module is equipped with a DINOv3 visual Transformer backbone network pre-trained on a large-scale dataset, specifically using a ViT-B / 16 network variant. The module's input receives a 518×518 pixel RGB image after scaling and normalization. The image is then passed through a block embedding layer and a 12-layer Transformer encoder for forward propagation. At the output, the class label vector and all image block label vectors are extracted, while the four register label vectors built into the network are discarded and do not participate in subsequent calculations. After extraction, the pooling unit performs global mean pooling on all image block label vectors along the sequence dimension to obtain a single global spatial description vector. Then, the concatenation unit concatenates and fuses this description vector and the class label vector along the feature dimension, outputting a fused feature vector with a dimension of 1536.
[0048] Regression Prediction Module: This module contains a multilayer perceptron regression head, which takes the fused feature vector output by the feature extraction module as input. The regression head adopts a three-layer fully connected cascaded structure: the first layer maps the 1536-dimensional input to a 512-dimensional intermediate representation, the second layer maps the 512-dimensional input to a 256-dimensional hidden layer representation, and the third layer maps the 256-dimensional input to a 1-dimensional scalar value. The outputs of the first and second layers are respectively cascaded with nonlinear activation units and random deactivation regularization units to suppress overfitting. The scalar value output by the third layer is constrained by a sigmoid activation function, and the final output is normalized to a continuous prediction score in the closed interval of 0 to 1.
[0049] Training and Optimization Module: This module is deployed on a computing server equipped with multiple GPUs, employing a distributed data parallel training strategy. The communication backend is implemented based on the NVIDIA Collective Communication Library. The module includes a hierarchical learning rate scheduler and optimizer: for the backbone network parameters, it assigns them... The base learning rate; for the regression head parameters, assign them... Both the base learning rate and the cosine annealing strategy are used to smoothly decay the learning rate to near zero throughout the training cycle. The loss calculation unit uses a piecewise loss function and selects Wing Loss or Focal L1 Loss as the training target through mutual exclusion of external configuration files. The prediction error is calculated batch by batch and backpropagation is triggered. At the same time, all trainable parameters of the backbone network and the regression head are updated. In addition, the module integrates an early stopping monitor, which uses the mean absolute error on the validation set as the monitoring index. When the index does not decrease for a preset number of rounds, such as 20 rounds, the training cycle is automatically terminated and the current optimal model weights are saved.
[0050] Inference Evaluation Module: This module is used to perform the test-time enhancement and denormalization operations described in step S5, and to perform batch inference on the test set images offline. During inference, a horizontal flip transformation is forcibly applied to each original image. The original image and the horizontally flipped image are respectively sent to the trained feature extraction module and regression prediction module to obtain two normalized prediction scores. The mean unit calculates the arithmetic mean, and the denormalization calculation unit performs a linear transformation on the mean result according to the preset scaling factor and offset, mapping it back to the original business score range of 5 to 10 points. Finally, the result output unit organizes the image identifier, predicted score, true labeled score and absolute error of each test image in tabular form, and generates an error distribution statistical chart for quality inspectors to verify.
Claims
1. A method for scoring industrial defect images based on DINOv3 and label reconstruction, characterized in that, Includes the following steps: S1. Data Acquisition and Label Reconstruction: Acquire industrial defect images and one or more corresponding original rating labels; the original rating labels have a preset continuous rating interval, within which there is a preset boundary point for pass or defect; all original rating labels that represent pass or defect with rating values lower than the boundary point are uniformly truncated to a preset truncation target value. For the same image with multiple original rating labels, calculate the arithmetic mean of the truncated rating values and use it as the supervised label value for that image. S2. Feature Extraction and Fusion: The industrial defect image processed in step S1 is input into the DINOv3 Vision Transformer backbone network to extract the CLS Token features and all Patch Token features of the image. The all Patch Token features are then subjected to global mean pooling along the sequence dimension to obtain the Patch mean features. The CLS Token features and the Patch mean features are then concatenated along the feature dimension to obtain the fused feature vector. S3. Regression Prediction: Input the fused feature vector obtained in step S2 into the multilayer perceptron regression head, constrained by the Sigmoid activation function, and output the predicted score normalized to the preset numerical range. S4. Model Training: The supervision label values obtained in step S1 are normalized to the preset numerical range and used as the training target. A piecewise loss function is adopted, which applies nonlinear gradient enhancement to the small error range and linear gradient to the large error range. The DINOv3 backbone network and the multilayer perceptron regression head are trained in a distributed data parallel manner through backpropagation. S5. Inference and Denormalization: Perform test-time enhancement on the test image by inputting the original image and the horizontally flipped image into the trained model respectively, and taking the average of the two prediction scores. The mean result is mapped back to the valid score interval through an inverse normalization transformation, and used as the final score output.
2. The method according to claim 1, characterized in that, The dividing point is the 40th percentile of the continuous scoring interval from low to high. The cutoff target value is the score value adjacent to the score value corresponding to the dividing point and facing the high-score defect side. The effective scoring interval is the portion of the continuous scoring interval from the cutoff target value to the upper limit of the interval.
3. The method according to claim 1, characterized in that, The DINOv3 backbone network described in step S2 uses a ViT-B / 16 variant, and the input image resolution is set to 518×518 pixels.
4. The method according to claim 3, characterized in that, The training described in step S4 adopts a full parameter fine-tuning strategy and uses a hierarchical learning rate, wherein the learning rate of the DINOv3 backbone network is set to one-tenth of the learning rate of the regression head.
5. The method according to claim 4, characterized in that, The learning rate of the DINOv3 backbone network is The learning rate of the multilayer perceptron regression head is The cosine annealing learning rate scheduling strategy is adopted, and the minimum learning rate decays to 0. The batch size of a single card is 16, and NCCL backend is used for distributed communication.
6. The method according to claim 3, characterized in that, The DINOv3 backbone network described in step S2 is input with a 518×518 pixel resolution image, and after passing through the Patch Embedding layer, it is divided into 16×16 block sizes to generate 1024 PatchTokens, each with a dimension of 768. The CLS Token feature dimension is 768, the Patch mean feature dimension is 768, and the dimension of the concatenated fused feature vector is 1536. The multilayer perceptron regression head consists of three fully connected layers. The input and output dimensions of each fully connected layer are as follows: the first layer linearly maps 1536 dimensions to 512 dimensions, the second layer linearly maps 512 dimensions to 256 dimensions, and the third layer linearly maps 256 dimensions to 1 dimension. The first two layers are followed by a GELU activation function and a Dropout layer with a Dropout rate of 0.
3.
7. The method according to claim 1, characterized in that, The loss function used in step S4 to nonlinearly weight the prediction error is the Wing Loss function, and its mathematical expression is: , ; Where e is the difference between the predicted score in step S3 and the supervision label value in step S1, w is the preset small error interval width threshold, ε is the preset curvature parameter, and C is the continuous offset constant. Alternatively, the loss function that non-linearly weights the prediction error is the Focal L1 Loss function, whose mathematical expression is: Where N is the total number of samples in a training batch, and i is the index of the sample in the batch. Let γ be the prediction error of the i-th sample, and γ be a preset focusing parameter greater than 1. The Wing Loss function and the Focal L1 Loss function are mutually exclusive through configuration parameters, and only one of the loss functions is used in a single training session.
8. The method according to claim 7, characterized in that, The preset small error interval width threshold w=0.2, the preset curvature parameter ε=0.1, and the preset focusing parameter γ=2.0; The formula for the inverse normalization transformation in step S5 is: ;in For the final score, R is the predicted mean, R is the width of the rating interval, and B is the lower limit of the rating interval.
9. An industrial defect image scoring system based on DINOv3 and label reconstruction, characterized in that, include: The data governance module is used to parse the annotation file, obtain industrial defect images and one or more original rating labels corresponding to them. The original rating labels have a preset continuous rating interval. There is a preset dividing point within the continuous rating interval. Labels with rating values lower than the rating values corresponding to the dividing point are truncated to a preset truncation target value. The mean after truncation is calculated for multiple rating samples, and a list of training set and validation set partitions is generated. The feature extraction module, based on the DINOv3 visual Transformer backbone network, is used to extract the CLSToken and Patch Token features of the input image, and then concatenates the global mean of the Patch Token with the CLS Token to output the fused features. The regression prediction module includes a multilayer perceptron regression head, which is used to receive the fused features and output a continuous score normalized to a preset numerical range by a Sigmoid constraint. The training optimization module employs a distributed data parallelism and hierarchical learning rate strategy, using a loss function that non-linearly weights the prediction error for model training. The inference evaluation module is used to perform test-time enhancements, predictive score denormalization, and output sample-level error statistics and visualization reports.
10. The system according to claim 9, characterized in that, In the data governance module, if the labeled score exceeds the preset continuous scoring range when parsing the labeled file, the score that exceeds the range is silently discarded; if all labels of an image exceed the range, the image is skipped and not included in the training set; if the image file is missing or corrupted, causing reading errors, a warning log is printed and a pure black image is returned as a replacement.