Visual defect detection rule generation method based on decision tree and related device
By generating visual defect detection rules based on deep learning and decision trees, the problem of fuzzy rules in traditional methods that are difficult to adapt to the diversity of defects is solved, and high-accuracy and high-efficiency defect detection is achieved.
Patent Information
- Application Number
- CN202511831990.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-08
- Publication Date
- 2026-05-01
AI Technical Summary
Existing visual defect detection methods rely on manual qualitative judgment, resulting in vague rules that are difficult to adapt to the diversity of defects. Furthermore, fixed rules cannot dynamically match changes in defect features, leading to significant deviations in detection results.
A candidate defect set is generated using a deep learning algorithm, physical feature parameters are extracted, a decision tree model is trained using a recursive feature space segmentation algorithm, and quantitative defect rules are generated through iterative optimization to reduce the bias rate and improve detection accuracy.
By using decision tree learning, the bias rate of defect detection is reduced, the detection accuracy is improved, different defect types are adapted, and manual costs and rule analysis efficiency are reduced.
Smart Images

Figure CN121962694A_ABST
Abstract
Description
A method and related apparatus for generating visual defect detection rules based on decision trees Technical Field
[0001] This invention relates to the field of machine vision technology, and in particular to a method and related apparatus for generating visual defect detection rules based on decision trees. Background Technology
[0002] In industrial product quality inspection, industrial visual defect detection is widely used due to its high efficiency and non-contact nature. Current visual defect detection primarily involves preliminary defect detection of images using traditional or artificial intelligence algorithms, followed by filtering of the preliminary results using manually pre-defined quantitative rules to output the final defect judgment. This method relies on qualitative judgment by the human eye, but it is difficult for humans to precisely define judgment criteria, leading to ambiguity in the defect detection rules. Furthermore, fixed pre-defined rules cannot adapt to the diversity of defects, resulting in significant deviations between the judgment results based on these rules and manually labeled results. Moreover, rule adjustments in this method depend on manual trial and error, which is inefficient and unable to dynamically match changes in defect features, making it difficult to continuously reduce the deviation from human judgment. Summary of the Invention
[0003] The purpose of this invention is to overcome the shortcomings of the prior art. This invention provides a method and related apparatus for generating visual defect detection rules based on decision trees, which solves the problem of fuzzy and difficult-to-define traditional rules, and can greatly reduce the defect detection deviation rate and improve the accuracy of defect detection.
[0004] To address the aforementioned technical problems, this invention provides a method for generating visual defect detection rules based on decision trees. The method includes: acquiring a set of test images of industrial products; performing defect detection on the test image set using a deep learning algorithm to obtain defect detection information; and generating a defect candidate set based on the defect detection information and the test image set; extracting physical feature parameters from the defect candidate set; determining target label information for the defect candidate set; and generating a training dataset based on the physical feature parameters, the defect candidate set, and the target label information of the defect candidate set; training a decision tree model using a recursive feature space segmentation algorithm on the training dataset to obtain a trained decision tree model; extracting quantified defect rules based on the trained decision tree model; determining defect judgment labels based on the quantified defect rules and the defect candidate set; calculating a deviation rate based on the defect judgment labels; performing iterative optimization judgment on the decision tree model based on the deviation rate; generating target defect detection rules based on the iterative optimization judgment results; and deploying the target defect detection rules to a defect confirmation module.
[0005] Optionally, the step of performing defect detection on the test image set based on a deep learning algorithm to obtain defect detection information includes: inputting the test image set into a pre-trained YOLO model, the pre-trained YOLO model locating defect regions in each test image to obtain defect region information; determining the confidence level of the defect region information; and generating defect detection information based on the defect region information and the confidence level of the defect region information.
[0006] Optionally, the step of extracting the physical feature parameters of the defect candidate set and determining the target label information of the defect candidate set includes: extracting basic data from the defect candidate set to obtain target basic data; extracting the defect width, defect area, defect rotation angle, defect volume, edge roughness, and grayscale contrast of the defect candidate set based on the target basic data, and generating physical feature parameters based on the defect width, defect area, defect rotation angle, defect volume, edge roughness, and grayscale contrast; obtaining several initial label information of the defect candidate set, and determining the target label information from the several initial label information based on a majority voting mechanism.
[0007] Optionally, the step of training the decision tree model using a recursive feature space segmentation algorithm based on the training dataset to obtain a trained decision tree model includes: determining the hyperparameters of the decision tree model; and training the decision tree model using a recursive feature space segmentation algorithm based on the hyperparameters and the training dataset to obtain a trained decision tree model.
[0008] Optionally, the step of training the decision tree model using a recursive segmentation feature space algorithm based on the hyperparameters and the training dataset to obtain a trained decision tree model includes: determining target segmentation features and target segmentation feature thresholds based on the training dataset; and recursively segmenting child nodes and generating leaf nodes in the decision tree model based on the hyperparameters, target segmentation features, and target segmentation feature thresholds to obtain a trained decision tree model.
[0009] Optionally, the step of extracting quantified defect rules based on a trained decision tree model, determining defect judgment labels based on the quantified defect rules and a defect candidate set, and calculating the deviation rate based on the defect judgment labels includes: traversing the trained decision tree model, determining the path from the root node to the leaf node in the trained decision tree model, and determining quantified defect rules based on the path from the root node to the leaf node; integrating defect candidate data in the defect candidate set to obtain target defect candidate data; performing label judgment based on the target defect candidate data using quantified defect rules combined with preset rule logic to obtain defect judgment labels; comparing the defect judgment labels with manually assigned labels to obtain comparison results, and determining the deviation rate based on the comparison results.
[0010] Optionally, the step of iteratively optimizing the decision tree model based on the deviation rate, generating a target defect detection rule based on the iterative optimization result, and deploying the target defect detection rule to the defect confirmation module includes: identifying whether the deviation rate is greater than a preset threshold; if the deviation rate is less than or equal to the preset threshold, then using the quantized defect rule as the target defect detection rule and deploying the target defect detection rule to the defect confirmation module; if the deviation rate is greater than the preset threshold, then performing deviation cause analysis on the training dataset and the trained decision tree model to obtain the target deviation cause; iteratively optimizing the decision tree model based on the target deviation cause to obtain the iteratively optimized decision tree model, determining the target defect detection rule based on the iteratively optimized decision tree model, and deploying the target defect detection rule to the defect confirmation module.
[0011] In addition, the present invention also provides a visual defect detection rule generation device based on decision trees. The device includes: a candidate set generation module: used to collect a set of test images of industrial products, perform defect detection on the test image set based on a deep learning algorithm, obtain defect detection information, and generate a defect candidate set based on the defect detection information and the test image set; a dataset generation module: used to extract physical feature parameters of the defect candidate set, determine the target label information of the defect candidate set, and generate a training dataset based on the physical feature parameters, the defect candidate set, and the target label information of the defect candidate set; a model training module: used to train a decision tree model based on the training dataset using a recursive feature space segmentation algorithm to obtain a trained decision tree model; a deviation calculation module: used to extract quantified defect rules based on the trained decision tree model, determine defect judgment labels based on the quantified defect rules and the defect candidate set, and calculate the deviation rate based on the defect judgment labels; and a rule generation module: used to perform iterative optimization judgment of the decision tree model based on the deviation rate, generate target defect detection rules based on the iterative optimization judgment results, and deploy the target defect detection rules to the defect confirmation module.
[0012] In addition, the present invention also provides an electronic device, which includes a processor and a memory. The memory is used to store instructions, and the processor is used to call the instructions in the memory to cause the electronic device to execute the above-described method for generating visual defect detection rules based on decision trees.
[0013] In addition, the present invention also provides a computer-readable storage medium that stores computer instructions that, when executed on an electronic device, cause the electronic device to perform the above-described method for generating visual defect detection rules based on decision trees.
[0014] In this embodiment of the invention, a deep learning algorithm is used to detect defects in a test image set. A defect candidate set is generated based on the defect detection information and the test image set. Physical feature parameters of the defect candidate set are extracted, and target label information is determined. A training dataset is generated based on the physical feature parameters, the defect candidate set, and the target label information, making the obtained training dataset more comprehensive and improving the accuracy of subsequent model training. A decision tree model is trained using a recursive feature space segmentation algorithm based on the training dataset. Quantified defect rules are extracted from the trained decision tree model, and defect judgment labels are determined based on the quantified defect rules and the defect candidate set to calculate the deviation rate. Iterative optimization of the decision tree model is performed based on the deviation rate, and target defect detection rules are generated based on the iterative optimization results. These target defect detection rules are deployed to the defect confirmation module. Decision tree learning solves the problem of fuzzy and difficult-to-define traditional rules. Through the training, rule extraction, and iterative optimization of the decision tree model, the deviation rate can be greatly reduced, the accuracy of defect detection can be improved, and it can adapt to different defect types. Simultaneously, it reduces manual costs and improves the efficiency of rule analysis. Attached Figure Description
[0015] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 is a flowchart illustrating the method for generating visual defect detection rules based on decision trees in an embodiment of the present invention; Figure 2 is a flowchart illustrating the method for generating visual defect detection rules based on decision trees in another embodiment of the present invention; Figure 3 is a structural diagram illustrating the device for generating visual defect detection rules based on decision trees in an embodiment of the present invention; Figure 4 is a structural diagram illustrating the electronic device in an embodiment of the present invention. Detailed Implementation
[0017] The technical solutions of the embodiments of the present invention 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.
[0018] Please refer to Figure 1 for Example 1. Figure 1 is a flowchart illustrating the visual defect detection rule generation method based on decision trees in this embodiment of the invention. The method includes: S11: Collecting a set of test images of industrial products, performing defect detection on the test image set based on a deep learning algorithm to obtain defect detection information, and generating a defect candidate set based on the defect detection information and the test image set; In the specific implementation of this invention, a set of test images of industrial products is collected, and the test image set is input into a pre-trained YOLO (You Only Look Once) model. The pre-trained YOLO model locates defect regions in each test image to obtain defect region information; the confidence level of the defect region information is determined, and defect detection information is generated based on the defect region information and the confidence level of the defect region information. The defect candidate set is generated based on the defect detection information and the test image set, providing reliable data support for the generation of the training dataset.
[0019] S12: Extract the physical feature parameters of the defect candidate set, determine the target label information of the defect candidate set, and generate a training dataset based on the physical feature parameters, the defect candidate set, and the target label information of the defect candidate set. In the specific implementation of this invention, basic data is extracted from the defect candidate set to obtain target basic data. Based on the target basic data, the defect width, defect area, defect rotation angle, defect volume, edge roughness, and grayscale contrast of the defect candidate set are extracted, and physical feature parameters are generated based on the defect width, defect area, defect rotation angle, defect volume, edge roughness, and grayscale contrast. Several initial label information of the defect candidate set is obtained, and the target label information is determined from the several initial label information based on a majority voting mechanism. Generating a training dataset based on the physical feature parameters, the defect candidate set, and the target label information of the defect candidate set can generate a more comprehensive and accurate dataset, which can effectively improve the training accuracy of the model.
[0020] S13: Based on the training dataset, the decision tree model is trained using a recursive feature space segmentation algorithm to obtain a trained decision tree model; in the specific implementation of this invention, the hyperparameters of the decision tree model are determined; based on the hyperparameters and the training dataset, the decision tree model is trained using a recursive feature space segmentation algorithm to obtain a trained decision tree model, which can reduce the impact of noise on the model, reduce the workload of feature engineering, and improve the efficiency and accuracy of decision tree model training.
[0021] S14: Extract quantified defect rules based on the trained decision tree model, determine defect judgment labels based on the quantified defect rules and the defect candidate set, and calculate the deviation rate based on the defect judgment labels. In the specific implementation of this invention, the trained decision tree model is traversed to determine the path from the root node to the leaf node in the trained decision tree model, and quantified defect rules are determined based on the path from the root node to the leaf node. The defect candidate set is integrated to obtain target defect candidate data. Based on the target defect candidate data, the quantified defect rules are combined with preset rule logic to perform label judgment and obtain defect judgment labels. The defect judgment labels are compared with manual labels to obtain comparison results, and the deviation rate is determined based on the comparison results. The deviation rate is calculated based on the defect judgment labels. Through decision tree learning, manual qualitative judgment is transformed into quantified rules of physical feature thresholds plus logical relationships, solving the problem of fuzzy and difficult-to-define traditional rules.
[0022] S15: Based on the deviation rate, perform iterative optimization judgment of the decision tree model, generate target defect detection rules based on the iterative optimization judgment results, and deploy the target defect detection rules to the defect confirmation module.
[0023] In the specific implementation of this invention, it is determined whether the deviation rate is greater than a preset threshold. If the deviation rate is less than or equal to the preset threshold, the quantified defect rule is used as the target defect detection rule, and the target defect detection rule is deployed to the defect confirmation module. If the deviation rate is greater than the preset threshold, the deviation cause analysis is performed on the training dataset and the trained decision tree model to obtain the target deviation cause. Based on the target deviation cause, the decision tree model is iteratively optimized to obtain the iteratively optimized decision tree model. Based on the iteratively optimized decision tree model, the target defect detection rule is determined, and the target defect detection rule is deployed to the defect confirmation module. This can generate the optimal rule in a shorter time and reduce the workload of subsequent manual review, greatly reducing the deviation rate and significantly improving the detection accuracy, thereby making the detection results more consistent with manual judgment.
[0024] In this embodiment of the invention, a deep learning algorithm is used to detect defects in a test image set. A defect candidate set is generated based on the defect detection information and the test image set. Physical feature parameters of the defect candidate set are extracted, and target label information is determined. A training dataset is generated based on the physical feature parameters, the defect candidate set, and the target label information, making the obtained training dataset more comprehensive and improving the accuracy of subsequent model training. A decision tree model is trained using a recursive feature space segmentation algorithm based on the training dataset. Quantified defect rules are extracted from the trained decision tree model, and defect judgment labels are determined based on the quantified defect rules and the defect candidate set to calculate the deviation rate. Iterative optimization of the decision tree model is performed based on the deviation rate, and target defect detection rules are generated based on the iterative optimization results. These target defect detection rules are deployed to the defect confirmation module. Decision tree learning solves the problem of fuzzy and difficult-to-define traditional rules. Through the training, rule extraction, and iterative optimization of the decision tree model, the deviation rate can be greatly reduced, the accuracy of defect detection can be improved, and it can adapt to different defect types. Simultaneously, it reduces manual costs and improves the efficiency of rule analysis.
[0025] Please refer to Figure 2 for Example 2. Figure 2 is a flowchart illustrating a visual defect detection rule generation method based on decision trees in another embodiment of the present invention. The method includes: S201: collecting a set of test images of industrial products, performing defect detection on the test image set based on a deep learning algorithm to obtain defect detection information, and generating a defect candidate set based on the defect detection information and the test image set; In the specific implementation of the present invention, the step of performing defect detection on the test image set based on a deep learning algorithm to obtain defect detection information includes: inputting the test image set into a pre-trained YOLO model, the pre-trained YOLO model locating defect regions in each test image to obtain defect region information; determining the confidence level of the defect region information, and generating defect detection information based on the defect region information and the confidence level of the defect region information.
[0026] Specifically, a test image set of industrial products is collected, such as semiconductor wafers. The test image set contains images with varying degrees of defects and defect candidate regions, with a minimum of 100 images to ensure sample representativeness. This test image set is then input into a pre-trained YOLO model. The pre-trained YOLO model locates defect regions in each test image, automatically dividing the image into multiple grids. Each grid predicts the bounding box and class probability of the defect, directly outputting the coordinates of the defect candidate region, quickly completing the initial defect localization and obtaining defect region information.
[0027] The confidence level of defect region information is determined, and this confidence level can also be output in the model. Defect detection information is generated based on the defect region information and its confidence level. A defect candidate set is generated based on the defect detection information and the test image set. The defect detection information is labeled in the corresponding images of the test image set to form the defect candidate set. This ensures the representativeness of the defect samples and provides sufficient support for the construction of the dataset.
[0028] S202: Extract the physical feature parameters of the defect candidate set, determine the target label information of the defect candidate set, and generate a training dataset based on the physical feature parameters, the defect candidate set, and the target label information of the defect candidate set; In the specific implementation of this invention, the step of extracting the physical feature parameters of the defect candidate set and determining the target label information of the defect candidate set includes: extracting basic data from the defect candidate set to obtain target basic data; extracting the defect width, defect area, defect rotation angle, defect volume, edge roughness, and grayscale contrast of the defect candidate set based on the target basic data, and generating physical feature parameters based on the defect width, defect area, defect rotation angle, defect volume, edge roughness, and grayscale contrast; obtaining several initial label information of the defect candidate set, and determining the target label information from the several initial label information based on a majority voting mechanism.
[0029] Specifically, basic data is extracted from the defect candidate set to obtain target basic data. The basic data includes the minimum bounding rectangle and pixel equivalent of the defect region. The minimum bounding rectangle of the defect region can be obtained through the cv2.minAreaRect function, which is used to calculate the minimum bounding rectangle of the image point set. The pixel equivalent refers to the actual physical size represented by a pixel in the image.
[0030] Based on the target baseline data, the defect candidate set is extracted for defect width, defect area, defect rotation angle, defect volume, edge roughness, and grayscale contrast. The defect width can be obtained by multiplying the number of pixels in the minimum bounding rectangle by the pixel equivalent. The effective pixel count of the defect region is counted, and the defect area is obtained by multiplying the effective pixel count by the square of the pixel equivalent. The defect rotation angle is obtained by calculating the angle between the minimum bounding rectangle and the horizontal axis. The defect volume is calculated using depth data. The edge roughness is obtained by calculating the grayscale fluctuation of edge pixels. The grayscale contrast is obtained by calculating the grayscale difference between the defect region and the background. Physical feature parameters are generated based on the defect width, defect area, defect rotation angle, defect volume, edge roughness, and grayscale contrast, resulting in more comprehensive physical feature parameters.
[0031] Several initial label information is obtained from the defect candidate set. Several senior inspectors can then manually judge the defect candidate set, with the judgment criterion being whether it is a genuine defect. A genuine defect is one that affects product performance; a false defect is an area that does not affect performance, such as stains, image noise, or minor scratches. Based on the judgment results of each person, corresponding manual labels are matched to each image in the defect candidate set. These manual labels are the labels used to determine whether a defect is a genuine defect, and are thus the initial label information. A target label information is determined from the several initial label information based on a majority voting mechanism. That is, the initial label with the highest number of consistent judgments is selected as the final target label. For example, if ≥(K+1) / 2 of the K inspectors judge it as a genuine defect, then the label is 1; otherwise, the label is 0. A training dataset is generated based on the physical feature parameters, the defect candidate set, and the target label information of the defect candidate set. A mapping relationship between the physical feature parameters and the defect candidate set is established, such as the defect identifier of an image in the defect candidate set corresponding to the physical feature parameter of that image in the defect candidate set. A mapping relationship between the defect candidate set and its target label information is also established, such as the defect identifier of an image in the defect candidate set corresponding to the target label of that image in the defect candidate set. A training dataset is generated based on the mapping relationship between the two, and each training image data contains its corresponding physical feature parameters and target label.
[0032] S203: Based on the training dataset, the decision tree model is trained using a recursive feature space segmentation algorithm to obtain a trained decision tree model; In the specific implementation of this invention, the step of training the decision tree model based on the training dataset using a recursive feature space segmentation algorithm to obtain a trained decision tree model includes: determining the hyperparameters of the decision tree model; and training the decision tree model based on the hyperparameters and the training dataset using a recursive feature space segmentation algorithm to obtain a trained decision tree model.
[0033] Specifically, determine the hyperparameters of the decision tree model. The model hyperparameters include tree depth, minimum number of sample splits, and minimum number of sample leaf nodes. The tree depth can be 3-8 layers, which can avoid model overfitting.
[0034] Based on the hyperparameters and training dataset, the decision tree model is trained using the recursive feature space partitioning algorithm to obtain a trained decision tree model. The recursive feature space partitioning algorithm is the core mechanism of decision tree training. By recursively partitioning the dataset, a tree structure is gradually built to achieve the classification or regression goal. The decision tree partitions the dataset into subsets by recursively selecting the optimal feature each time, making the subsets more homogeneous and improving the model's generalization ability.
[0035] Furthermore, the step of training the decision tree model using a recursive segmentation feature space algorithm based on the hyperparameters and the training dataset to obtain a trained decision tree model includes: determining the target segmentation features and the target segmentation feature threshold based on the training dataset; and recursively segmenting child nodes and generating leaf nodes in the decision tree model based on the hyperparameters, the target segmentation features, and the target segmentation feature threshold to obtain a trained decision tree model.
[0036] Specifically, target segmentation features and target segmentation feature thresholds are determined based on the training dataset. Segmentation indices, such as information gain and Gini coefficient, are calculated for the physical feature parameters in the training dataset. The features with the best indices and their corresponding thresholds are selected as target segmentation features and target segmentation feature thresholds.
[0037] Based on the hyperparameters, target segmentation features, and target segmentation feature thresholds, the decision tree model is trained by recursively splitting child nodes and generating leaf nodes. Recursively splitting child nodes involves creating new nodes for each class of samples, repeatedly selecting segmentation features and thresholds until the hyperparameters' stopping conditions are triggered, such as when node sample labels are completely consistent, a preset tree depth is reached, or the number of samples is lower than the minimum number of splits. Generating a leaf node involves marking the stopped node as a leaf node and assigning it the corresponding artificial label to the majority of samples. This completes the recursive segmentation of the feature space, forming a mapping path from physical features to labels. By recursively segmenting the feature space, the sample labels corresponding to each leaf node are made as consistent as possible, ultimately generating a decision tree model that represents the mapping relationship between physical feature parameters and artificial labels. Simultaneously, the accuracy of the decision tree model on the validation set can be verified. If the accuracy is less than a preset threshold, the hyperparameters are adjusted or physical feature parameters are supplemented, and the model is retrained until the accuracy is greater than or equal to the preset threshold, finally obtaining the trained decision tree model.
[0038] S204: Extracting quantitative defect rules based on a trained decision tree model, determining defect judgment labels based on the quantitative defect rules and a defect candidate set, and calculating the deviation rate based on the defect judgment labels; In a specific implementation of this invention, the step of extracting quantitative defect rules based on a trained decision tree model, determining defect judgment labels based on the quantitative defect rules and a defect candidate set, and calculating the deviation rate based on the defect judgment labels includes: traversing the trained decision tree model, determining the path from the root node to the leaf node in the trained decision tree model, and determining quantitative defect rules based on the path from the root node to the leaf node; integrating defect candidate data in the defect candidate set to obtain target defect candidate data; performing label judgment based on the target defect candidate data using quantitative defect rules combined with preset rule logic to obtain defect judgment labels; comparing the defect judgment labels with manual labels to obtain comparison results, and determining the deviation rate based on the comparison results.
[0039] Specifically, the trained decision tree model is traversed to determine the path from the root node to the leaf node in the trained decision tree model, and the quantification defect rules are determined based on the path from the root node to the leaf node. Each path from the root node to the leaf node corresponds to a quantification defect rule. For example, path 1: if the defect width is > 0.3 mm → and the defect area is > 0.8 mm² → and the defect rotation angle is ∈ [0°, 45°] → label = 1 (true defect); path 2: if the defect width is ≤ 0.3 mm → or the edge roughness is < 0.1 μm → label = 0 (false defect).
[0040] The defect candidate set is integrated to obtain target defect candidate data, which involves organizing the physical feature parameters and target labels of the defect candidate set. Based on the target defect candidate data, label determination is performed using quantified defect rules combined with preset rule logic. Specifically, the physical feature parameters from the target defect candidate data are substituted into the quantified defect rules, and the determination labels are output according to the preset rule logic, thus obtaining the defect determination labels.
[0041] The defect judgment labels are compared with the manual labels to obtain the comparison results. Based on the comparison results, the deviation rate is determined. The absolute value of the difference between the defect judgment labels and the manual labels of all target defect candidate data is calculated. The absolute values of all differences are added together, and the sum is divided by the total number of defect candidates to obtain the deviation rate.
[0042] S205: Identify whether the deviation rate is greater than a preset threshold; In the specific implementation of this invention, identify whether the deviation rate is greater than a preset threshold, which can be set to 5%. If the deviation rate is greater than or equal to the preset threshold, proceed to step S207, where iterative optimization of the decision tree model is required. If the deviation rate is less than or equal to the preset threshold, iterative optimization of the decision tree is not required, and proceed to step S206.
[0043] S206: If the deviation rate is found to be less than or equal to a preset threshold, the quantized defect rule is used as the target defect detection rule, and the target defect detection rule is deployed to the defect confirmation module. In the specific implementation of this invention, if the deviation rate is found to be less than or equal to the preset threshold, it indicates that there is no need for iterative optimization of the decision tree model, and the extracted quantized defect rule is directly used as the target defect detection rule. Deploying the target defect detection rule to the defect confirmation module means integrating the optimal defect detection rule into the defect confirmation module of the industrial vision defect detection system. In actual detection, the system first outputs defect candidates through a preliminary detection algorithm. The defect confirmation module calls the optimal defect detection rule to determine the defect candidates and outputs the result of true / false defects. At the same time, the algorithm judgment results and manual review results in actual detection can be collected periodically to update the optimal rule and adapt to the long-term changes in defect characteristics.
[0044] S207: If the deviation rate is found to be greater than a preset threshold, then a deviation cause analysis is performed on the training dataset and the trained decision tree model to obtain the target deviation cause. In the specific implementation of this invention, if the deviation rate is found to be greater than the preset threshold, it indicates that the decision tree model needs to be iteratively optimized. The deviation cause analysis of the training dataset and the trained decision tree model is required. The steps for analyzing the deviation cause include: screening deviation samples, classifying them into missed detections (true defects are judged as false) and false detections (false defects are judged as true), and clarifying the main deviation types; comparing the physical characteristics of deviation samples and unbiased samples to find feature anomalies not covered by existing rules (such as missing key parameters); investigating sample (insufficient quantity / uneven distribution) and decision tree model (unreasonable hyperparameters, overfitting / underfitting) problems; summarizing the causes (feature missing, sample problems, model parameter problems), and determining the final deviation cause and improvement direction, such as supplementing physical feature parameters or expanding the test set sample size.
[0045] S208: Based on the cause of the target deviation, iteratively optimize the decision tree model to obtain the iteratively optimized decision tree model, determine the target defect detection rules based on the iteratively optimized decision tree model, and deploy the target defect detection rules to the defect confirmation module.
[0046] In the specific implementation of this invention, the decision tree model is iteratively optimized based on the causes of the target deviation. Specifically, the dataset and decision tree model are adjusted according to the causes of the target deviation, and the decision tree model is retrained until the deviation rate is less than or equal to a preset threshold, resulting in an iteratively optimized decision tree model. Based on the iteratively optimized decision tree model, target defect detection rules are determined and deployed to the defect confirmation module. Through a closed loop of training-extraction-verification-iteration, the rules are continuously optimized, and the deviation rate can be controlled within the preset threshold, thereby significantly improving the accuracy of defect detection.
[0047] In this embodiment of the invention, a deep learning algorithm is used to detect defects in a test image set. A defect candidate set is generated based on the defect detection information and the test image set. Physical feature parameters of the defect candidate set are extracted, and target label information is determined. A training dataset is generated based on the physical feature parameters, the defect candidate set, and the target label information, making the obtained training dataset more comprehensive and improving the accuracy of subsequent model training. A decision tree model is trained using a recursive feature space segmentation algorithm based on the training dataset. Quantified defect rules are extracted from the trained decision tree model, and defect judgment labels are determined based on the quantified defect rules and the defect candidate set to calculate the deviation rate. Iterative optimization of the decision tree model is performed based on the deviation rate, and target defect detection rules are generated based on the iterative optimization results. These target defect detection rules are deployed to the defect confirmation module. Decision tree learning solves the problem of fuzzy and difficult-to-define traditional rules. Through the training, rule extraction, and iterative optimization of the decision tree model, the deviation rate can be greatly reduced, the accuracy of defect detection can be improved, and it can adapt to different defect types. Simultaneously, it reduces manual costs and improves the efficiency of rule analysis.
[0048] Please refer to Figure 3 for Embodiment 3. Figure 3 is a schematic diagram of the structural composition of the visual defect detection rule generation device based on decision tree in this embodiment of the invention. The device includes: a candidate set generation module 31, used to collect a set of test images of industrial products, perform defect detection on the test image set based on a deep learning algorithm, obtain defect detection information, and generate a defect candidate set based on the defect detection information and the test image set; a dataset generation module 32, used to extract the physical feature parameters of the defect candidate set, determine the target label information of the defect candidate set, and generate a training dataset based on the physical feature parameters, the defect candidate set, and the target label information of the defect candidate set; a model training module 33, used to train a decision tree model using a recursive feature space segmentation algorithm based on the training dataset to obtain a trained decision tree model; a deviation calculation module 34, used to extract quantified defect rules based on the trained decision tree model, determine defect judgment labels based on the quantified defect rules and the defect candidate set, and calculate the deviation rate based on the defect judgment labels; and a rule generation module 35, used to perform iterative optimization judgment of the decision tree model based on the deviation rate, generate target defect detection rules based on the iterative optimization judgment results, and deploy the target defect detection rules to the defect confirmation module.
[0049] In the specific implementation of this invention, the specific implementation of the device item can be referred to the implementation of the method item above, and will not be repeated here.
[0050] In this embodiment of the invention, a deep learning algorithm is used to detect defects in a test image set. A defect candidate set is generated based on the defect detection information and the test image set. Physical feature parameters of the defect candidate set are extracted, and target label information is determined. A training dataset is generated based on the physical feature parameters, the defect candidate set, and the target label information, making the obtained training dataset more comprehensive and improving the accuracy of subsequent model training. A decision tree model is trained using a recursive feature space segmentation algorithm based on the training dataset. Quantified defect rules are extracted from the trained decision tree model, and defect judgment labels are determined based on the quantified defect rules and the defect candidate set to calculate the deviation rate. Iterative optimization of the decision tree model is performed based on the deviation rate, and target defect detection rules are generated based on the iterative optimization results. These target defect detection rules are deployed to the defect confirmation module. Decision tree learning solves the problem of fuzzy and difficult-to-define traditional rules. Through the training, rule extraction, and iterative optimization of the decision tree model, the deviation rate can be greatly reduced, the accuracy of defect detection can be improved, and it can adapt to different defect types. Simultaneously, it reduces manual costs and improves the efficiency of rule analysis.
[0051] This invention provides a computer-readable storage medium storing a computer program. When executed by a processor, this program implements the decision tree-based visual defect detection rule generation method of any of the above embodiments. The computer-readable storage medium includes, but is not limited to, any type of disk (including floppy disk, hard disk, optical disk, CD-ROM, and magneto-optical disk), ROM (Read-Only Memory), RAM (Random Access Memory), EPROM (Erasable Programmable Read-Only Memory), EEPROM (Electrically Erasable Programmable Read-Only Memory), flash memory, magnetic cards, or optical cards. In other words, the storage device includes any medium that can store or transmit information in a readable form by a device (e.g., a computer, a mobile phone), and can be a read-only memory, a disk, or an optical disk, etc.
[0052] Please refer to Figure 4 for Example 4. Figure 4 is a schematic diagram of the structural composition of the electronic device in this embodiment of the invention.
[0053] This invention also provides an electronic device, as shown in FIG4. The electronic device includes a memory 41, a processor 43, and a computer program 42 stored in the memory 41 and executable on the processor 43. Those skilled in the art will understand that the electronic device shown in FIG4 does not constitute a limitation on all devices and may include more or fewer components than shown, or combine certain components. The memory 41 can be used to store the computer program 42 and various functional modules. The processor 43 runs the computer program 42 stored in the memory 41, thereby performing various functional applications and data processing of the device. The memory can be internal memory or external memory, or both. Internal memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), flash memory, or random access memory. External memory may include hard disks, floppy disks, ZIP disks, USB flash drives, magnetic tapes, etc. Processor 43 can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor, a single-chip microcomputer, or processor 43 can be any conventional processor. The processors and memories disclosed in this invention include, but are not limited to, these types of processors and memories. The processors and memories disclosed in this invention are only examples and not limitations.
[0054] As one embodiment, the electronic device includes: one or more processors 43, a memory 41, and one or more computer programs 42, wherein the one or more computer programs 42 are stored in the memory 41 and configured to be executed by the one or more processors 43, and the one or more computer programs 42 are configured to execute the decision tree-based visual defect detection rule generation method in any of the above embodiments. For specific implementation details, please refer to the above embodiments, which will not be repeated here.
[0055] In this embodiment of the invention, a deep learning algorithm is used to detect defects in a test image set. A defect candidate set is generated based on the defect detection information and the test image set. Physical feature parameters of the defect candidate set are extracted, and target label information is determined. A training dataset is generated based on the physical feature parameters, the defect candidate set, and the target label information, making the obtained training dataset more comprehensive and improving the accuracy of subsequent model training. A decision tree model is trained using a recursive feature space segmentation algorithm based on the training dataset. Quantified defect rules are extracted from the trained decision tree model, and defect judgment labels are determined based on the quantified defect rules and the defect candidate set to calculate the deviation rate. Iterative optimization of the decision tree model is performed based on the deviation rate, and target defect detection rules are generated based on the iterative optimization results. These target defect detection rules are deployed to the defect confirmation module. Decision tree learning solves the problem of fuzzy and difficult-to-define traditional rules. Through the training, rule extraction, and iterative optimization of the decision tree model, the deviation rate can be greatly reduced, the accuracy of defect detection can be improved, and it can adapt to different defect types. Simultaneously, it reduces manual costs and improves the efficiency of rule analysis.
[0056] Furthermore, the above provides a detailed description of a decision tree-based visual defect detection rule generation method and related apparatus provided by the embodiments of the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A method for generating visual defect detection rules based on decision trees, characterized in that, The method includes: acquiring a set of test images of industrial products; performing defect detection on the test image set using a deep learning algorithm to obtain defect detection information; and generating a defect candidate set based on the defect detection information and the test image set; extracting physical feature parameters from the defect candidate set, determining target label information for the defect candidate set, and generating a training dataset based on the physical feature parameters, the defect candidate set, and the target label information for the defect candidate set; training a decision tree model using a recursive feature space segmentation algorithm based on the training dataset to obtain a trained decision tree model; extracting quantified defect rules based on the trained decision tree model, determining defect judgment labels based on the quantified defect rules and the defect candidate set, and calculating a deviation rate based on the defect judgment labels; performing iterative optimization judgment on the decision tree model based on the deviation rate, generating target defect detection rules based on the iterative optimization judgment results, and deploying the target defect detection rules to the defect confirmation module.
2. The method for generating visual defect detection rules based on decision trees according to claim 1, characterized in that, The step of performing defect detection on the test image set based on a deep learning algorithm to obtain defect detection information includes: inputting the test image set into a pre-trained YOLO model, the pre-trained YOLO model locating defect regions in each test image to obtain defect region information; determining the confidence level of the defect region information; and generating defect detection information based on the defect region information and the confidence level of the defect region information.
3. The method for generating visual defect detection rules based on decision trees according to claim 1, characterized in that, The step of extracting the physical feature parameters of the defect candidate set and determining the target label information of the defect candidate set includes: extracting basic data from the defect candidate set to obtain target basic data; extracting the defect width, defect area, defect rotation angle, defect volume, edge roughness, and grayscale contrast of the defect candidate set based on the target basic data, and generating physical feature parameters based on the defect width, defect area, defect rotation angle, defect volume, edge roughness, and grayscale contrast; obtaining several initial label information of the defect candidate set, and determining the target label information from the several initial label information based on a majority voting mechanism.
4. The method for generating visual defect detection rules based on decision trees according to claim 1, characterized in that, The step of training the decision tree model using a recursive feature space segmentation algorithm based on the training dataset to obtain a trained decision tree model includes: determining the hyperparameters of the decision tree model; and training the decision tree model using a recursive feature space segmentation algorithm based on the hyperparameters and the training dataset to obtain a trained decision tree model.
5. The method for generating visual defect detection rules based on decision trees according to claim 4, characterized in that, The step of training the decision tree model using a recursive segmentation feature space algorithm based on the hyperparameters and training dataset to obtain a trained decision tree model includes: determining target segmentation features and target segmentation feature thresholds based on the training dataset; and recursively segmenting child nodes and generating leaf nodes in the decision tree model based on the hyperparameters, target segmentation features, and target segmentation feature thresholds to obtain a trained decision tree model.
6. The method for generating visual defect detection rules based on decision trees according to claim 1, characterized in that, The process of extracting quantified defect rules based on a trained decision tree model, determining defect judgment labels based on the quantified defect rules and a defect candidate set, and calculating the deviation rate based on the defect judgment labels includes: traversing the trained decision tree model to determine the path from the root node to the leaf node in the trained decision tree model, and determining quantified defect rules based on the path from the root node to the leaf node; integrating defect candidate data in the defect candidate set to obtain target defect candidate data; performing label judgment based on the target defect candidate data using quantified defect rules combined with preset rule logic to obtain defect judgment labels; comparing the defect judgment labels with manually assigned labels to obtain comparison results, and determining the deviation rate based on the comparison results.
7. The method for generating visual defect detection rules based on decision trees according to claim 1, characterized in that, The step of iteratively optimizing the decision tree model based on the deviation rate, generating a target defect detection rule based on the iterative optimization result, and deploying the target defect detection rule to the defect confirmation module includes: identifying whether the deviation rate is greater than a preset threshold; if the deviation rate is less than or equal to the preset threshold, then using the quantized defect rule as the target defect detection rule and deploying the target defect detection rule to the defect confirmation module; if the deviation rate is greater than the preset threshold, then performing deviation cause analysis on the training dataset and the trained decision tree model to obtain the target deviation cause; iteratively optimizing the decision tree model based on the target deviation cause to obtain the iteratively optimized decision tree model, determining the target defect detection rule based on the iteratively optimized decision tree model, and deploying the target defect detection rule to the defect confirmation module.
8. A visual defect detection rule generation device based on decision trees, characterized in that, The apparatus includes: a candidate set generation module for acquiring a set of test images of industrial products, performing defect detection on the test image set based on a deep learning algorithm to obtain defect detection information, and generating a defect candidate set based on the defect detection information and the test image set; a dataset generation module for extracting physical feature parameters of the defect candidate set, determining the target label information of the defect candidate set, and generating a training dataset based on the physical feature parameters, the defect candidate set, and the target label information of the defect candidate set; a model training module for training a decision tree model using a recursive feature space segmentation algorithm based on the training dataset to obtain a trained decision tree model; a deviation calculation module for extracting quantified defect rules based on the trained decision tree model, determining defect judgment labels based on the quantified defect rules and the defect candidate set, and calculating a deviation rate based on the defect judgment labels; and a rule generation module for iteratively optimizing the decision tree model based on the deviation rate, generating target defect detection rules based on the iterative optimization judgment results, and deploying the target defect detection rules to the defect confirmation module.
9. An electronic device, the electronic device comprising a processor and a memory, characterized in that, The memory is used to store instructions, and the processor is used to call the instructions in the memory to cause the electronic device to execute the decision tree-based visual defect detection rule generation method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed on an electronic device, cause the electronic device to perform the decision tree-based visual defect detection rule generation method as described in any one of claims 1 to 7.