Defect detection method based on YOLO network architecture
By optimizing the hyperparameters of the YOLO network using reinforcement learning algorithms, the problem of time-consuming and labor-intensive manual parameter tuning is solved, achieving efficient and intelligent hyperparameter adjustment and improving the accuracy and robustness of industrial defect detection.
Patent Information
- Application Number
- CN202511111340.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-08
- Publication Date
- 2025-11-18
AI Technical Summary
In existing technologies, the configuration of hyperparameters for YOLO networks relies on human experience, which is time-consuming, labor-intensive, and highly subjective. It is difficult to find hyperparameter combinations with high accuracy, strong generalization, and high robustness, especially in industrial defect detection where it is difficult to effectively explore hyperparameter combinations for small targets and complex environments.
A policy network is constructed using reinforcement learning algorithms. By generating hyperparameter combinations and receiving reward values from environmental feedback, the hyperparameters of the YOLO network are optimized, achieving automatic and intelligent hyperparameter tuning.
It significantly improves the accuracy and efficiency of defect detection models, making it particularly suitable for industrial defect detection. It solves the problem of difficult parameter tuning caused by the variety of products, complex defect morphologies, and large differences in imaging environments, thereby improving detection accuracy and model generalization ability.
Smart Images

Figure CN120976167A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of defect detection, and particularly relates to a defect detection method based on a YOLO network architecture. BACKGROUND
[0002] As a mainstream target detection algorithm, the core advantage of the YOLO network is that it can integrate target positioning and classification tasks into one neural network architecture, thereby realizing end-to-end real-time target detection. However, although the YOLO network itself has strong detection capability, reasonable setting of hyperparameters is still crucial to fully exert the network performance.
[0003] In the field of industrial defect detection, in order to identify tiny defects (such as micron-level scratches and fine cracks), it is usually required that the detection model has extremely high precision and strong generalization ability to cope with diversified product surfaces and defect morphologies, and also has good robustness to overcome uneven illumination, background texture interference, occlusion and other complex imaging conditions. These stringent requirements make the configuration of hyperparameters such as learning rate, batch size, network depth, number and size of convolutional layers, anchor box size extremely sensitive and complex.
[0004] In the prior art, the hyperparameter adjustment method mainly relies on manual experience, that is, the hyperparameters are manually set and adjusted according to the experience of researchers or engineers. This method not only consumes time and effort, but also has great subjectivity, and it is difficult to guarantee that the optimal hyperparameter combination is found. In the industrial defect detection scene, facing a large number of product categories, different defect characteristics and complex on-site environments, relying on manual experience for parameter tuning is inefficient, and it is difficult to find a hyperparameter configuration that can meet the requirements of high precision, strong generalization and high robustness at the same time.
[0005] In addition, although the automatic hyperparameter configuration methods such as grid search and random search can improve the search efficiency to a certain extent, they require a large amount of computing resources, and are prone to local optimal solutions in high-dimensional hyperparameter space, especially difficult to efficiently explore the hyperparameter combinations that are crucial to tiny target detection and fine feature distinction in the industrial defect detection task, such as anchor boxes of specific scales, feature layer weights for small targets, etc. SUMMARY
[0006] In order to solve the above problems existing in the prior art, the application provides a defect detection method based on a YOLO network architecture. The technical problems to be solved by the application are solved by the following technical solutions: The application provides a defect detection method based on a YOLO network architecture, comprising: obtaining a to-be-detected picture; The image to be detected is input into the defect detection model to obtain the defect type detection result; wherein, the defect detection model is trained according to the following steps: Determine the hyperparameters that affect the accuracy of defect detection in the YOLO network; Based on the value range of each hyperparameter, construct the state space of each hyperparameter; Initialize the policy network and enable the policy network to generate a set of hyperparameter combinations based on the current policy and the state space of each hyperparameter; Set the corresponding hyperparameters in the YOLO network according to the hyperparameter combination, receive the reward value fed back from the environment, and update the parameters of the policy network according to the reward value to obtain the adjusted policy; If the current iteration count has not reached the preset iteration count, the adjusted strategy is used as the current strategy, and the process returns to the step of generating a set of hyperparameter combinations based on the current strategy and the state space of each hyperparameter. If the current iteration count has reached the preset iteration count, the current YOLO network is determined as the defect detection model.
[0007] In one embodiment of the present invention, the hyperparameters affecting the accuracy of defect detection include: initial learning rate, momentum parameter, weight decay coefficient, bounding box regression loss weight, classification loss weight, target existence loss weight, IoU training threshold, and anchor point matching threshold.
[0008] In one embodiment of the present invention, the step of initializing a policy network and causing the policy network to generate a set of hyperparameter combinations based on the current policy and the state space of each hyperparameter includes: Initialize the policy network; The policy network samples from the state space of each hyperparameter based on the current policy to generate a set of hyperparameter combinations.
[0009] In one embodiment of the present invention, for each hyperparameter, the policy network at the The sampling results in the next iteration follow a preset probability distribution. Indicates the preset number of iterations.
[0010] In one embodiment of the present invention, in the first In the next iteration, the initial learning rate of the policy network follows a uniform distribution, and the weight decay coefficient follows a logarithmic uniform distribution.
[0011] In one embodiment of the present invention, the step of setting the corresponding hyperparameters in the YOLO network according to the hyperparameter combination and receiving the reward value fed back from the environment includes: After setting the corresponding hyperparameters in the YOLO network according to the hyperparameter combination, the current YOLO network is used to perform defect detection on the test samples in the dataset. Based on the detection results of the current YOLO network on the test samples, the average detection accuracy of the current YOLO network is determined, and the average detection accuracy is used as the reward value for environmental feedback.
[0012] In one embodiment of the present invention, the average detection accuracy of the current YOLO network is determined according to the following formula: ; In the formula, Indicates that in accordance with the first When the corresponding hyperparameters in the YOLO network are set using a combination of hyperparameters, the average detection accuracy of the current YOLO network will increase. This indicates that the current YOLO network is in the [number]th [year]. Average detection accuracy across various defect types , Indicates the number of defect types.
[0013] In one embodiment of the present invention, the parameters of the policy network are updated according to the following formula: ; In the formula, Let represent the objective function of the policy network, and let represent the objective function of the policy network given the dataset. D Under the condition that the parameters in the policy network are Current strategy generate The expected average detection accuracy obtained by combining a set of hyperparameters. In a given dataset Under the condition that the parameters in the policy network are Current strategy Generate the first Group of hyperparameter combinations The probability density.
[0014] Compared with the prior art, the beneficial effects of the present invention are as follows: This invention provides a defect detection method based on the YOLO network architecture, comprising: acquiring an image to be detected; inputting the image to be detected into a defect detection model to obtain a defect type detection result; wherein, the defect type detection model is obtained by training a YOLO network, and the YOLO network includes multiple hyperparameters that affect the accuracy of defect detection. Therefore, this invention introduces a reinforcement learning algorithm to determine these hyperparameters during the training process. This invention uses a policy network that generates hyperparameter combinations as an agent, and the YOLO network and dataset as an environment. The agent receives the hyperparameter combinations generated by the policy network and outputs the performance index mAP as a reward value, thereby guiding the update of the policy network until the hyperparameter combination that makes the YOLO network achieve the best performance is found. This achieves automatic and intelligent hyperparameter optimization and adjustment, significantly improving the accuracy and efficiency of the defect detection model.
[0015] Furthermore, this invention is particularly applicable to the field of industrial defect detection, such as scratches, cracks, foreign objects, missing parts, or assembly errors on product surfaces. It can effectively solve the problems of difficulty in manual parameter adjustment, low efficiency, and insufficient generalization ability of detection models caused by the large variety of products, complex defect morphologies, and large differences in imaging environments.
[0016] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description
[0017] Figure 1 This is a flowchart of a defect detection method based on the YOLO network architecture provided in an embodiment of the present invention; Figure 2 This is a schematic diagram of the YOLOv5s baseline network; Figure 3 This is a graph showing the changes in reward value and loss value of the policy network with the number of iterations, provided in an embodiment of the present invention. Figure 4a This is the accuracy-confidence curve of the defect detection model provided in this embodiment of the invention; Figure 4b This is a recall-confidence curve of the defect detection model provided in this embodiment of the invention; Figure 4c This is a precision-recall curve of the defect detection model provided in this embodiment of the invention; Figures 5a~5b This is a diagram showing the crack detection results of a concrete structure provided in an embodiment of the present invention. Detailed Implementation
[0018] The present invention will be further described in detail below with reference to specific embodiments, but the implementation of the present invention is not limited thereto.
[0019] Figure 1This is a flowchart of a defect detection method based on the YOLO network architecture provided in an embodiment of the present invention. Figure 1 As shown, this embodiment of the invention provides a defect detection method based on the YOLO network architecture, including: S1. Obtain the image to be detected.
[0020] S2. Input the image to be detected into the defect detection model to obtain the defect type detection result; the defect detection model is trained according to the following steps: S21. Determine the hyperparameters in the YOLO network that affect the accuracy of defect detection.
[0021] In this embodiment, the YOLO network is selected as the neural network to be trained. Specifically, a network of appropriate size from the YOLO series can be used directly, or the network structure can be manually improved according to actual needs, such as adjusting the number of network layers and the size of convolution kernels, to ensure that the network architecture can adapt well to the dataset during training, laying the foundation for subsequent hyperparameter optimization.
[0022] S22. Based on the value range of each hyperparameter, construct the state space of each hyperparameter.
[0023] In the application scenario of defect detection, the hyperparameters that affect the accuracy of defect detection include: initial learning rate, momentum parameter, weight decay coefficient, bounding box regression loss weight, classification loss weight, target existence loss weight, IoU training threshold, and anchor point matching threshold.
[0024] Table 1 Hyperparameter State Space
[0025] The state space of the hyperparameters mentioned above is shown in Table 1. Specifically, the initial learning rate determines the step size for updating the network parameters of the policy, and its state space is [1×10]. -5 1×10 -2 An initial learning rate that is too small will slow down the convergence of the policy network, while one that is too large will cause the policy network to oscillate around the optimum. The momentum parameter (SGD / Adam) is used to accelerate convergence and reduce oscillations. A momentum parameter that is too small will cause the policy network to oscillate, while one that is too large may skip the optimum. Therefore, the state space of the momentum parameter is set to [0.8, 0.98]. The weight decay coefficient is used to prevent overfitting, and its state space is [1×10]. -6 1×10 -3The weight decay coefficient needs to be balanced with the initial learning rate; a high initial learning rate also requires a higher weight decay coefficient. The bounding box regression loss weight is used to control the localization accuracy of the defect detection result, with a state space of [0.02, 0.2]. If the bounding box regression loss weight is too small, it will ignore localization; if it is too high, it will suppress subsequent classification tasks. The target existence loss weight is used to control the sensitivity of target detection, with a state space of [0.5, 2.0]. For small targets or dense scenes, the target existence loss weight needs to be appropriately increased. The IoU training threshold has a state space of [0.1, 0.5] and is used to filter positive and negative samples. If the IoU training threshold is too low, it will introduce noise; if it is too high, it will reduce the number of positive samples. The anchor point matching threshold has a state space of [2.0, 6.0] and is used to determine the matching range between the estimated anchor box and the ground truth box. The larger the anchor point matching threshold, the looser the matching.
[0026] S23. Initialize the policy network and make the policy network generate a set of hyperparameter combinations based on the current policy and the state space of each hyperparameter.
[0027] Optionally, step S23 includes: Initialize the policy network; The policy network samples from the state space of each hyperparameter based on the current policy to generate a set of hyperparameter combinations.
[0028] It should be noted that, for each hyperparameter, the policy network in the th... The sampling results in the next iteration follow a preset probability distribution. This indicates the preset number of iterations. For example, in the 1st iteration... In the next iteration, the initial learning rate of the policy network follows a uniform distribution, and the weight decay coefficients follow a log-uniform distribution.
[0029] S24. Set the corresponding hyperparameters in the YOLO network according to the hyperparameter combination, receive the reward value fed back from the environment, and update the parameters of the policy network according to the reward value.
[0030] Specifically, in step S24, the corresponding hyperparameters in the YOLO network are set according to the hyperparameter combination, and the current YOLO network is used to detect defects in the test samples in the dataset. Then, based on the detection results of the current YOLO network on the test samples, the average detection accuracy of the current YOLO network is determined, and the average detection accuracy is used as the reward value of the environmental feedback.
[0031] In this embodiment, the average detection accuracy of the current YOLO network is determined according to the following formula: ; In the formula, Indicates that in accordance with the first When setting the corresponding hyperparameters in the YOLO network using a combination of hyperparameters, the average detection accuracy of the current YOLO network is [increased / decreased]. This indicates that the current YOLO network is at the [number]th [time]. Average detection accuracy across various defect types , Indicates the number of defect types.
[0032] Furthermore, based on the current average detection accuracy of the YOLO network, the parameters of the policy network are updated according to the following formula: ; In the formula, Let represent the objective function of the policy network, and let represent the objective function of the policy network given the dataset. D Under the condition that the parameters in the policy network are Current strategy generate The expected average detection accuracy obtained by combining a set of hyperparameters. In a given dataset Under the condition that the parameters in the policy network are Current strategy Generate the first Group of hyperparameter combinations The probability density.
[0033] S25. If the current iteration count has not reached the preset iteration count, the adjusted strategy is used as the current strategy, and the above steps are returned to make the strategy network generate a set of hyperparameter combinations based on the current strategy and the state space of each hyperparameter; if the current iteration count has reached the preset iteration count, the current YOLO network is determined as the defect detection model.
[0034] The following simulation experiment further illustrates the defect detection method based on the YOLO network architecture provided by this invention.
[0035] Specifically, the hyperparameters of the YOLO network are optimized using the defect detection model training method provided in this invention to obtain the trained defect detection model. The optimized hyperparameters are shown in Table 2. Table 2 Optimized hyperparameters
[0036] Next, the defect detection model provided by this invention and existing methods are tested using the Crack ground defect dataset. This dataset is a target detection dataset based on crack annotation, with only one category, including 879 training images, 80 verification images and 37 test images. The dataset is characterized by small targets with irregular shapes, making detection difficult.
[0037] This embodiment uses YOLOv5s as the base network. Figure 2 This is a schematic diagram of the YOLOv5s benchmark network. YOLOv5s is a lightweight real-time object detection model in the YOLOv5 series. Its network structure consists of three modules. The Backbone adopts an improved CSPDarknet53 architecture, which optimizes feature extraction efficiency and reduces redundant computation through cross-stage local connections (CSP). The Neck integrates FPN (Feature Pyramid) and PANet (Path Aggregation Network) to fuse multi-scale features to enhance small object detection capabilities. The Head outputs prediction results based on the anchor box mechanism, combines Focus slicing operations to reduce the number of downsampling operations, and uses the SiLU activation function to accelerate inference.
[0038] The experimental results are shown in Table 3: Table 3 Comparison of Defect Detection Results
[0039] As shown in Table 3, this invention models the hyperparameter optimization problem of the YOLO network as a reinforcement learning problem during the training process of the defect detection model. This allows the optimized hyperparameter configuration to exhibit significant advantages. Compared with the benchmark network YOLOv5s, the defect detection model provided by this invention achieves a 0.9% improvement in average detection accuracy (mAP) on the dataset. Furthermore, in comparison with the comprehensive performance of more advanced detection algorithms such as Faster R-CNN and the YOLO series, the detection performance of the defect detection model provided by this invention is also in a leading position. This result fully demonstrates that the hyperparameter optimization strategy adopted in this invention can significantly improve the feature representation capability of the YOLO network, providing strong support for the accuracy and robustness of target detection tasks in practical application scenarios.
[0040] Figure 3 This is a graph showing the changes in reward value and loss value of the policy network with the number of iterations, as provided in an embodiment of the present invention. Figure 3 As shown, the defect detection model exhibits a steady upward trend in performance as the number of training episodes increases. Starting from near 0 points initially, the reward value steadily increases to approximately 1.5 points in the first 20 episodes, then accelerates to approximately 3.5 points between episodes 20 and 60, finally reaching a level close to 5 points at episode 100. This continuous upward trend indicates that the defect detection model is continuously optimized during the learning process, and its performance gradually improves.
[0041] On the other hand, using a pre-defined loss function, the loss value of the policy network in each iteration is calculated, and this loss value exhibits an inverse trend to the reward value. The loss value of the policy network rapidly decreases from an initial value of approximately 4 points, sharply dropping to approximately 0.5 points within the first 20 rounds, then continuing to decrease slowly to around 0.1 points, and finally stabilizing after 60 iterations. This pattern of rapid decline followed by stabilization indicates that the policy network learns quickly in the early stages of training, then enters a convergence phase, finding a relatively stable solution. The trends in both the loss and reward values reflect the effectiveness and stability of the reinforcement learning algorithm during training.
[0042] Figure 4a This is the precision-confidence curve of the defect detection model provided in this embodiment of the invention, such as... Figure 4a As shown, the detection accuracy of the defect detection model increases rapidly with the increase of the confidence threshold. When the confidence exceeds 0.6, the detection accuracy reaches almost 100%, indicating that the prediction of the defect detection model is very reliable under high confidence.
[0043] Figure 4b This is a recall-confidence curve of the defect detection model provided in this embodiment of the invention. As can be seen, Figure 4a and Figure 4b The opposite trend is observed: when the confidence threshold is below 0.5, the recall rate remains at a high level (about 90%), but as the threshold continues to increase, the recall rate drops sharply. This indicates that the defect detection model will miss more real targets under strict threshold settings.
[0044] Figure 4c This is the precision-recall curve of the defect detection model provided in this embodiment of the invention, such as... Figure 4c As shown, the defect detection model achieves good recall while maintaining high detection accuracy. The curve indicates that at a recall of 0.52, the precision for crack detection reaches 0.87, demonstrating that the defect detection model maintains an excellent precision-recall tradeoff at the recall level. Overall, the defect detection model provided by this invention exhibits good performance in crack detection tasks.
[0045] Figures 5a~5b This is a diagram showing the crack detection results of a concrete structure provided in an embodiment of the present invention. Please refer to [link / reference]. Figures 5a~5b The system uses a red bounding box to accurately locate cracks, and the "crack" label enables rapid visual localization. A confidence score is then added to this system, which directly reflects the accuracy of the crack label localization.
[0046] This invention addresses the defect detection problem based on the YOLO network architecture by constructing a dynamic hyperparameter optimization method based on reinforcement learning. Through a gradient-driven parameter space exploration mechanism, it achieves a significant performance breakthrough over existing YOLO network architectures. Experiments show that the optimized hyperparameter set improves the detection accuracy of the defect detection model by 0.9%, effectively solving the hyperparameter sensitivity problem while maintaining computational efficiency.
[0047] As can be seen from the above embodiments, the beneficial effects of the present invention are as follows: This invention provides a defect detection method based on the YOLO network architecture, comprising: acquiring an image to be detected; inputting the image to be detected into a defect detection model to obtain a defect type detection result; wherein, the defect type detection model is obtained by training a YOLO network, and the YOLO network includes multiple hyperparameters that affect the accuracy of defect detection. Therefore, this invention introduces a reinforcement learning algorithm to determine these hyperparameters during the training process. This invention uses a policy network that generates hyperparameter combinations as an agent, and the YOLO network and dataset as an environment. The agent receives the hyperparameter combinations generated by the policy network and outputs the performance index mAP as a reward value, thereby guiding the update of the policy network until the hyperparameter combination that makes the YOLO network achieve the best performance is found. This achieves automatic and intelligent hyperparameter optimization and adjustment, significantly improving the accuracy and efficiency of the defect detection model.
[0048] Furthermore, this invention is particularly applicable to the field of industrial defect detection, such as scratches, cracks, foreign objects, missing parts, or assembly errors on product surfaces. It can effectively solve the problems of difficulty in manual parameter adjustment, low efficiency, and insufficient generalization ability of detection models caused by the large variety of products, complex defect morphologies, and large differences in imaging environments.
[0049] In the description of this invention, the terms "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to a specific feature, structure, material, or characteristic described in connection with that embodiment or example, which is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. In addition, those skilled in the art can combine and integrate the different embodiments or examples described in this specification.
[0050] The above description, in conjunction with specific preferred embodiments, provides a further detailed explanation of the present invention. It should not be construed that the specific implementation of the present invention is limited to these descriptions. For those skilled in the art, various simple deductions or substitutions can be made without departing from the concept of the present invention, and all such modifications and substitutions should be considered within the scope of protection of the present invention.
Claims
1. A defect detection method based on the YOLO network architecture, characterized in that, include: Obtain the image to be detected; The image to be detected is input into the defect detection model to obtain the defect type detection result; wherein, the defect detection model is trained according to the following steps: Determine the hyperparameters that affect the accuracy of defect detection in the YOLO network; Based on the value range of each hyperparameter, construct the state space of each hyperparameter; Initialize the policy network and enable the policy network to generate a set of hyperparameter combinations based on the current policy and the state space of each hyperparameter; Set the corresponding hyperparameters in the YOLO network according to the hyperparameter combination, receive the reward value fed back from the environment, and update the parameters of the policy network according to the reward value to obtain the adjusted policy; If the current iteration count has not reached the preset iteration count, the adjusted strategy is used as the current strategy, and the process returns to the step of generating a set of hyperparameter combinations based on the current strategy and the state space of each hyperparameter. If the current iteration count has reached the preset iteration count, the current YOLO network is determined as the defect detection model.
2. The defect detection method based on the YOLO network architecture according to claim 1, characterized in that, The hyperparameters that affect the accuracy of defect detection include: initial learning rate, momentum parameter, weight decay coefficient, bounding box regression loss weight, classification loss weight, target existence loss weight, IoU training threshold, and anchor point matching threshold.
3. The defect detection method based on the YOLO network architecture according to claim 1, characterized in that, The steps of initializing the policy network and enabling the policy network to generate a set of hyperparameter combinations based on the current policy and the state space of each hyperparameter include: Initialize the policy network; The policy network samples from the state space of each hyperparameter based on the current policy to generate a set of hyperparameter combinations.
4. The defect detection method based on the YOLO network architecture according to claim 3, characterized in that, For each hyperparameter, the policy network at the The sampling results in the next iteration follow a preset probability distribution. Indicates the preset number of iterations.
5. The defect detection method based on the YOLO network architecture according to claim 4, characterized in that, In the In the next iteration, the initial learning rate of the policy network follows a uniform distribution, and the weight decay coefficient follows a logarithmic uniform distribution.
6. The defect detection method based on YOLO network architecture according to claim 1, characterized in that, The steps of setting the corresponding hyperparameters in the YOLO network according to the said hyperparameter combination and receiving the reward value fed back from the environment include: After setting the corresponding hyperparameters in the YOLO network according to the hyperparameter combination, the current YOLO network is used to perform defect detection on the test samples in the dataset. Based on the detection results of the current YOLO network on the test samples, the average detection accuracy of the current YOLO network is determined, and the average detection accuracy is used as the reward value for environmental feedback.
7. The defect detection method based on the YOLO network architecture according to claim 6, characterized in that, The average detection accuracy of the current YOLO network is determined using the following formula: ; In the formula, Indicates that in accordance with the first When the corresponding hyperparameters in the YOLO network are set using a combination of hyperparameters, the average detection accuracy of the current YOLO network will increase. This indicates that the current YOLO network is in the [number]th [year]. Average detection accuracy across various defect types , Indicates the number of defect types.
8. The defect detection method based on the YOLO network architecture according to claim 7, characterized in that, Update the parameters of the policy network according to the following formula: ; In the formula, Let represent the objective function of the policy network, and let represent the objective function of the policy network given the dataset. D Under the condition that the parameters in the policy network are Current strategy generate The expected average detection accuracy obtained by combining a set of hyperparameters. In a given dataset Under the condition that the parameters in the policy network are Current strategy Generate the first Group of hyperparameter combinations The probability density.