Industrial part defect detection method based on improved YOLOv8 model

By improving the YOLOv8 network structure, introducing CBAM and Mish activation functions, and adopting the GIoU loss function, the YOLOv8 model was optimized, solving the problem of insufficient accuracy in small object recognition and achieving high-precision and efficient defect detection of industrial parts.

CN118967602APending Publication Date: 2024-11-15NANJING UNIV OF POSTS & TELECOMM

Patent Information

Application Number
CN202411003944.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-25
Publication Date
2024-11-15

AI Technical Summary

Technical Problem

The YOLOv8 model has insufficient accuracy in recognizing small objects in object detection, and it suffers from problems with information filtering and poor target localization in complex scenes, making it difficult to meet the high accuracy and high efficiency requirements for defect detection of industrial parts.

Method used

By improving the YOLOv8 network structure, introducing the channel attention mechanism CBAM and the spatial attention module SAM, replacing the activation function with the Mish function, adopting the GIoU loss function, optimizing the network structure, and using a predefined learning rate scheduling strategy, the learning rate is dynamically adjusted to improve model accuracy and generalization ability.

Benefits of technology

It improves the accuracy and speed of defect detection in industrial parts, enhances the ability to perceive small targets, improves the generalization performance of the model, and is applicable to other target detection tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118967602A_ABST
    Figure CN118967602A_ABST
Patent Text Reader

Abstract

The invention discloses an industrial part defect detection method based on an improved YOLOv8 model, and the method comprises the steps: collecting industrial part images, making the industrial part images into an industrial part image data set, and dividing the industrial part image data set into a training set, a verification set and a test set; preprocessing the industrial part image data set; obtaining a data set and a weight file, and obtaining a standard YOLOv8 network structure for pre-training to obtain a pre-training weight; the method comprises the following steps of: improving a standard YOLOv8 network structure to obtain an improved YOLOv8 network; repeatedly training the improved YOLOv8 network model and adjusting parameters to optimize the model to obtain a finally trained YOLOv8 model; and performing defect detection on the industrial part based on the trained YOLOv8 model to obtain a detection result. According to the method, the richness of training data is increased, the target detection efficiency is enhanced, and the detection precision of an original network model is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the fields of deep learning and target detection, and in particular to an industrial parts defect detection method based on an improved YOLOv8 model. Background Art

[0002] Object detection is a core research topic in the field of computer vision, which aims to identify and locate the target objects of interest from images or video sequences. In recent years, deep learning has made great progress in the field of object detection. Currently, the mainstream object detection algorithms can be summarized into two categories: two-stage detection algorithms and single-stage detection algorithms.

[0003] The YOLO algorithm is an end-to-end single-stage target detection technology that uses a single convolutional neural network to achieve target recognition and obtain the results from the input image to the final prediction in one go. The YOLOv8 algorithm is the 8th version of the YOLO series. Although the network structure of YOLOv8 is similar to that of YOLOv5, YOLOv8 has made remarkable achievements in target detection through some unique improvements and performance optimizations. First, the backbone network still uses the idea of ​​CSP, but in order to meet the needs of different projects, it also designs models of different scales based on scale coefficients similar to YOLOv5, and, under the premise of retaining the original idea of ​​YOLOv5, the C2f module is designed with reference to the ELAN structure in YOLOv7. The implementation is further lightweight, and the number of channels of models of different scales is adjusted, which significantly improves the performance of the model. At the same time, the SPPF module used in architectures such as YOLOv5 is still in use. The neck network still uses the idea of ​​PAN, but the convolution structure of CBS in the PAN-FPN upsampling stage in YOLOv5 is deleted. Its classification loss uses the BCE loss. The regression loss is in the form of CIOU loss plus DFL. The head network is changed from the original coupling head to the decoupling head, separating the classification head from the detection head, and changing from anchor-based to anchor-free mode. Dynamic task allocation is used for matching strategy to calculate the alignment of the anchor level of each instance. When the number of parameters is the same, YOLOv8 has a higher mean value of average precision (mAP), which can more accurately locate and classify targets in target detection. It has a lightweight network architecture and an effective feature fusion method, but there are still some problems in the recognition of small objects in complex scenes. The use of Maxpool will filter out information that it considers unimportant, and some target information will be automatically filtered out, which reduces the resolution and has a great impact on the final accuracy. Secondly, when extracting features under special circumstances, small-sized targets can be easily misled by normal-sized targets, resulting in less and less information until the information disappears completely. In addition, the problem of poor target positioning persists throughout the network. Summary of the invention

[0004] In order to solve the above technical problems, the present invention proposes an industrial parts defect detection method based on an improved YOLOv8 model. By optimizing the YOLOv8 network method, the accuracy of the model in industrial parts defect detection is effectively improved, and the detection speed is improved, thereby meeting the industrial requirements for high precision, high efficiency and real-time performance of industrial parts defect detection.

[0005] The present invention adopts the following technical solutions to solve the above technical problems:

[0006] The industrial parts defect detection method based on the improved YOLOv8 model specifically includes the following steps:

[0007] Collect industrial parts images, make the industrial parts images into industrial parts image datasets, and divide them into training set, verification set and test set;

[0008] Preprocessing of industrial parts image dataset;

[0009] Obtain the standard YOLOv8 network structure for pre-training and obtain the pre-training weights;

[0010] Improve the standard YOLOv8 network structure to obtain an improved YOLOv8 network;

[0011] Repeat the training of the improved YOLOv8 network model and adjust the parameters to optimize the model to obtain the final trained YOLOv8 model;

[0012] Based on the trained YOLOv8 model, defect detection is performed on industrial parts to obtain detection results.

[0013] Furthermore, the industrial parts image dataset specifically includes: normal images and images of different types of defects at different angles and backgrounds, and a corresponding error label is annotated for each defective industrial parts image.

[0014] Furthermore, the industrial parts image dataset is preprocessed, including the following steps:

[0015] Scaling the industrial parts image dataset and cropping or padding the images;

[0016] Image enhancement technology is used to adjust the brightness, contrast and saturation of images in the industrial parts image dataset, and random flip, rotation and scaling operations are performed;

[0017] The numerical range of image pixels in the industrial parts image dataset is normalized and the pixels are scaled.

[0018] Further, obtaining the pre-training weights includes the following steps:

[0019] Get the ILSVRC2012 dataset and weight file, and adjust the image size of the ILSVRC2012 dataset to match the size of the images in the preprocessed industrial parts image dataset;

[0020] Get the standard YOLOv8 network structure;

[0021] Use a predefined learning rate scheduling strategy to adjust the initial learning rate; gradually increase the learning rate in the early stage to ensure fast convergence; reduce the learning rate in the later stage for fine correction;

[0022] Use the adjusted ILSVRC2012 dataset and pre-define the learning rate scheduling strategy to pre-train the standard YOLOv8 network structure and obtain the pre-training weights.

[0023] Furthermore, the improved YOLOv8 network includes a backbone network, a neck network and a detection head; an attention mechanism CBAM is inserted after the C2f module; the Mish activation function is introduced to replace the activation function SiLU in the original YOLOv8 algorithm; and GIoU is introduced instead of CIoU as a new bounding box regression loss function.

[0024] Furthermore, the attention mechanism CBAM includes:

[0025] Channel attention module CAM and spatial attention module SAM;

[0026] Among them, the specific formula of the channel attention module CAM is:

[0027]

[0028] Among them, F represents the intermediate feature map, σ represents the Sigmoid activation function, MLP represents the multi-layer perceptron, AvgPool represents the average pooling, MaxPool represents the maximum pooling, W1 and W0 represent the input shared weights, respectively. Represent the average pooling features and maximum pooling features of the channel respectively;

[0029] The specific formula of the spatial attention module SAM is:

[0030]

[0031] Among them, F represents the intermediate feature map, σ represents the Sigmoid activation function, and f 7*7 represents a convolution operation with a filter size of 7×7, AvgPool represents average pooling, and MaxPool represents maximum pooling. They represent the average pooling features and the maximum pooling features of the space respectively.

[0032] Furthermore, the specific formula of the Mish activation function is:

[0033] f(x)=xtanh(ln(1+e x )) (3)

[0034] The specific formula of the GIoU loss function is:

[0035]

[0036] Among them, IoU represents the ratio of the intersection area to the union area, B∪B gt represents the union area of ​​the predicted box and the true box, and C represents the minimum enclosing rectangular area of ​​the detection box and the predicted box.

[0037] Furthermore, obtaining the final YOLOv8 model includes the following steps:

[0038] Use the pre-trained weights as the initial weights of the improved YOLOv8 network structure and configure the model's hyperparameters, including input image size, anchor box settings, and number of categories;

[0039] Define the loss function and additional loss items, select the optimizer and set the learning rate; the loss function includes the generalized intersection-over-union loss function GioULoss and the focus loss function FocalLoss. The specific formula is:

[0040] GioULoss=IoU-(C-Union) / C (5)

[0041]

[0042] Among them, C represents the minimum enclosing box of the predicted bounding box and the true bounding box; Union represents the union of the predicted bounding box and the true bounding box; pt represents the probability that the predicted category is a positive sample; represents the adjustment factor set by the hyperparameter,

[0043] Build a data loader to load the preprocessed images and corresponding annotation information from the industrial parts image dataset;

[0044] Iterate through the training set, perform weight training and parameter update on the improved YOLOv8 network structure, calculate the loss between the prediction result and the true annotation, and perform back propagation to update the weight; evaluate the performance of the improved YOLOv8 network structure on the validation set, and evaluate the weight, including calculating the accuracy, recall rate, and average precision mean; until the recognition rate reaches a certain threshold, the weight at this time is the final weight, and the final YOLOv8 model is obtained.

[0045] According to one aspect of the present invention, a storage medium is provided, wherein instructions are stored in the storage medium. When a computer reads the instructions, the computer executes any one of the above-mentioned industrial parts defect detection methods based on the improved YOLOv8 model.

[0046] According to another aspect of the present invention, there is provided an electronic device, comprising a processor and the above-mentioned storage medium, wherein the processor executes instructions in the storage medium.

[0047] Compared with the prior art, the present invention has the following beneficial effects:

[0048] 1. The present invention adopts a predefined learning rate scheduling strategy and dynamically adjusts the learning rate according to the performance indicators in the training process, speeds up the training process of the model, provides good feature initialization for the target detection task, and improves the generalization ability of the model.

[0049] 2. This paper optimizes the YOLOv8 network structure and introduces the channel attention mechanism CBAM to enhance the feature extraction capability of the backbone network in view of the shortcomings of YOLOv8 in detecting small targets. CBAM adaptively adjusts the weights of different channel features, enabling the network to better focus on the feature channels that are more critical to the detection target, thereby improving the perception of small defects.

[0050] 3. The present invention replaces the original IoU loss function with a more robust GIoU loss function. GIoU not only considers the overlap between the predicted box and the true box, but also introduces the relative position information of the bounding box, which can more accurately evaluate the quality of the predicted box, thereby optimizing the positioning performance of the network. In addition, the activation function is changed from Leaky ReLU to the Mish function with better performance. The Mish function has a smoother gradient characteristic, which helps to improve the convergence speed and generalization ability of the network, thereby further improving the detection accuracy.

[0051] 4. The design method of the present invention is universal, and the improved model has better generalization performance, making it easy to deploy in other target detection tasks, providing application examples and solutions for the industrial application of small object target detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:

[0053] Figure 1 It is a schematic diagram of the overall process of an embodiment of the present invention.

[0054] Figure 2 4 is a structural diagram of a CBAM module according to an embodiment of the present invention.

[0055] Figure 3 GIoU loss function principle diagram of an embodiment of the present invention.

[0056] Figure 4 4 is a network structure diagram of the improved YOLOv8 model according to an embodiment of the present invention.

[0057] Figure 5 This is a comparison chart of the improved YOLOv8 model and the original YOLOv8 effect of an embodiment of the present invention. DETAILED DESCRIPTION

[0058] In order to make the purpose, technical solutions and advantages of the present invention more clear, the present invention is described in detail below with reference to the accompanying drawings and specific embodiments.

[0059] Figure 1 As shown, the present invention proposes an industrial parts defect detection method based on an improved YOLOv8 model, comprising:

[0060] S1. Collect industrial parts images and make them into industrial parts image datasets. Divide the images and labels in the dataset into training set, validation set and test set according to 8:1:1. The specific contents are as follows:

[0061] Use industrial cameras to collect images of industrial parts on the factory assembly line, including normal and different types of defective images at different angles and backgrounds, and annotate each defective industrial part image with corresponding error labels, including short circuit, open circuit, missing hole, rat bite, false copper, and stray six types of defects, to obtain industrial part images

[0062] Dataset.

[0063] S2. Preprocess the industrial parts image dataset. The specific contents are as follows:

[0064] S201, image cropping and scaling: scaling the industrial parts image dataset, and cropping or padding the image to make the image size 640*640.

[0065] S202, Image Enhancement: Improve robustness and generalization capabilities through image enhancement technology, adjust the brightness, contrast and saturation of images in the industrial parts image dataset to 1.25 times the original; and perform random flipping, rotation and scaling operations to expand the dataset.

[0066] S203, image normalization operation: normalize the value range of image pixels in the industrial part image dataset, and scale the pixels from the [0,255] range to the [0,1] or [-1,1] range.

[0067] S3. Download the ILSVRC2012 dataset and weight file from the ImageNet official website, and obtain the standard YOLOv8 network structure from the official website for pre-training to obtain the pre-training weights. The specific contents are as follows:

[0068] S301. Adjust the image size of the ILSVRC2012 dataset to 640*640 to match the size of the images in the preprocessed industrial parts image dataset.

[0069] S302. Obtain the standard YOLOv8 network structure from the YOLOv8 official website.

[0070] S303, learning rate scheduling: Use the predefined learning rate scheduling strategy to adjust the initial learning rate to 0.000001; gradually increase the learning rate, control the maximum learning rate not to exceed 0.01, and converge quickly with a higher learning rate in the early stage, at which time the learning rate is in the range of [0.01, 0.006]; in the later stage, use a lower learning rate for fine correction, at which time the learning rate is in the range of [0.001, 0.003]; and dynamically adjust the learning rate according to the performance indicators during the training process.

[0071] S304, weight initialization: the weight in step S301 is used as the initial weight.

[0072] S305. Use the adjusted ILSVRC2012 dataset and a predefined learning rate scheduling strategy to pre-train the standard YOLOv8 network structure to obtain pre-training weights.

[0073] S4. Improve the standard YOLOv8 network structure to obtain an improved YOLOv8 network structure.

[0074] like Figure 4 As shown in the figure, the improved YOLOv8 network includes a backbone network, a neck network and a detection head; the backbone network includes a basic convolution module, a C2f module and an SPPF module, an attention mechanism CBAM is inserted after the C2f module, the Mish activation function is introduced to replace the activation function SiLU in the original YOLOv8 algorithm, and GIoU is introduced to replace CIoU as a new bounding box regression loss function. The specific contents are:

[0075] like Figure 2 As described above, the CBAM attention mechanism structure diagram, given an intermediate feature map, infers the attention weights along the spatial and channel dimensions in turn, and then multiplies them with the original feature map to adaptively adjust the features. CBAM is a lightweight universal module that can be seamlessly integrated into any CNN architecture. The CBAM attention mechanism is divided into two parts: channel attention and spatial attention:

[0076] The formula of the channel attention module (CAM) is as follows:

[0077]

[0078] The input is a H×W×C feature F. First, a global average pooling and a maximum pooling are performed to obtain two 1×1×C channel descriptions. Then they are sent to a two-layer neural network. The number of neurons in the first layer is C / r, the activation function is Relu, and the number of neurons in the second layer is C. The two layers of the neural network are shared. Then, the two features are added together and passed through a Sigmoid activation function to obtain the weight coefficient M c Finally, multiply the weight coefficient by the original feature F to get the scaled new feature.

[0079] The formula of the Spatial Attention Module (SAM) is as follows:

[0080]

[0081] Similar to channel attention, given a H×W×C feature F', first perform average pooling and maximum pooling in a channel dimension to obtain two H×W×1 channel descriptions, and then splice these two descriptions together according to the channel. Then, after a 7×7 convolution layer, the activation function is Sigmoid, and the weight coefficient M is obtained. s Finally, the weight coefficient is multiplied by the feature F' to obtain the scaled new feature.

[0082] The Mish activation function is introduced to replace the activation function SiLU (Sigmoid Linear Unit) used in the backbone network and other modules in the original YOLOv8 algorithm. The Mish function is a smooth, continuous, self-regularized, non-monotonic activation function that not only has a smooth gradient characteristic, but also shows better learning efficiency and generalization performance in some benchmark tests.

[0083] The specific formula is:

[0084] The Mish function is defined as:

[0085] f(x)=xtanh(ln(1+e x )) (3)

[0086] Compared with SiLU, the Mish function can better capture the nonlinear relationship in the input features and propagate information, thereby further enhancing the network's expressiveness. By replacing the SiLU activation function in the YOLOv8 network with the Mish activation function, the performance of the model in industrial parts defect detection tasks can be further improved, especially for the detection of some small targets.

[0087] GIoU is introduced instead of CIoU as a new bounding box regression loss function. The GIoU loss function not only focuses on the detected overlapping areas, but also on other non-overlapping areas, which can better characterize the overlapping relationship.

[0088] like Figure 3 As shown, the GIoU loss function is defined as:

[0089]

[0090] Among them, IoU represents the ratio of the intersection area to the union area, B∪B gt represents the union area of ​​the predicted box and the true box, and C represents the minimum enclosing rectangular area of ​​the detection box and the predicted box.

[0091] When IoU is equal to 0, the GIoU value remains unchanged, indicating that there is no intersection between the detection box and the prediction box. The increase in the parameter C value means that the separation between the detection box and the prediction box increases, which will lead to a decrease in the GIoU value, and then an increase in the GIoU distance. This phenomenon indicates that the correspondence between frames is reduced. On the contrary, a smaller GIoU distance indicates a higher degree of alignment between frames. It can be seen that GIoU can better capture the geometric relationship between bounding boxes, and the calculation process is simpler and more intuitive. It also has better numerical characteristics and can better guide the optimization process of the model.

[0092] S5. Use the pre-trained weights as the initial weights, use the pre-processed industrial parts image dataset to train the improved YOLOv8 network structure, evaluate the weights obtained after training, perform hyperparameter optimization, and repeat the training until the recognition rate reaches more than 90%. The weights at this time are the final weights, and the final YOLOv8 model is obtained. The specific contents are as follows:

[0093] S501. Use the pre-trained weights as the initial weights of the improved YOLOv8 network structure. Configure the model's hyperparameters, including input image size, anchor box settings, and number of categories, according to the requirements of industrial part recognition.

[0094] S502. Define loss functions suitable for the industrial parts defect detection task, including GioULoss (generalized intersection-over-union loss function) and FocalLoss (focus loss function). Define additional loss items, including weights for category loss and box regression loss. Select an optimizer suitable for the task, including SGD (Stochastic Gradient Descent) and Adam (adaptive moment estimation), and set the learning rate. Define the loss function and additional loss items, select the optimizer and set the learning rate; the specific formula of the loss function is:

[0095] GioULoss=IoU-(C-Union) / C (5)

[0096]

[0097] Among them, C represents the minimum enclosing box of the predicted bounding box and the true bounding box; Union represents the union of the predicted bounding box and the true bounding box; pt represents the probability that the predicted category is a positive sample; represents the adjustment factor set by the hyperparameter,

[0098] S503. Use the PyTorch data loading framework DataLoader to build a data loader to load the preprocessed images and corresponding annotation information in the industrial parts image dataset.

[0099] S504, iterate through the training set, perform weight training and parameter update on the improved YOLOv8 network structure, calculate the loss between the prediction result and the true annotation, and perform back propagation to update the weight. According to the training strategy, adjust the learning rate to control the convergence and stability of the training process. Evaluate the performance of the improved YOLOv8 network structure on the validation set, and evaluate the weights, including calculating the accuracy, recall rate, and mAP (mean average precision); until the recognition rate reaches more than 90%, the weight at this time is the final weight, and the final YOLOv8 model is obtained for subsequent deployment and application.

[0100] In this embodiment, the training batch is set to 64. The performance of the model on the validation set is observed through the loss functions GIoULoss and FocalLoss. The smaller the value of GIoULoss, the higher the overlap between the predicted bounding box and the true bounding box, and the predicted bounding box of the model overlaps with the true bounding box more accurately. The smaller the value of FocalLoss, the more attention the model pays to the positive and negative samples in the classification problem.

[0101] S6. Deploy the final YOLOv8 model as a target detection model for detecting industrial parts defects in a specific production or use environment, input the target to be detected into the model for detection, and determine the corresponding defect type based on the obtained confidence score.

[0102] The performance comparison results of YOLOv8 and improved YOLOv8 algorithms are shown in the following table:

[0103] Table 1 Performance comparison results of YOLOv8 and improved YOLOv8 algorithms

[0104] Model Recall Precision mAP0.5 mAP0.5:0.95 YOLOv8 0.733 0.712 0.809 0.485 Improved YOLOv8 0.833 0.896 0.847 0.494

[0105] The computer-readable storage medium of this embodiment may be an internal storage unit of the terminal, such as a hard disk or memory of the terminal; the computer-readable storage medium of this embodiment may also be an external storage device of the terminal, such as a plug-in hard disk, a smart memory card, a secure digital card, a flash memory card, etc. equipped on the terminal; further, the computer-readable storage medium may also include both an internal storage unit of the terminal and an external storage device.

[0106] The computer-readable storage medium of this embodiment is used to store computer programs and other programs and data required by the terminal. The computer-readable storage medium can also be used to temporarily store data that has been output or is to be output.

[0107] A person skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.

[0108] The examples described in the present invention are merely descriptions of the preferred implementation modes of the present invention, and are not intended to limit the concept and scope of the present invention. Without departing from the design concept of the present invention, various modifications and improvements made to the technical solutions of the present invention by engineers and technicians in this field should all fall within the protection scope of the present invention.

Claims

1. An industrial parts defect detection method based on an improved YOLOv8 model, characterized in that: The specific steps include: Collect industrial parts images, make the industrial parts images into industrial parts image datasets, and divide them into training set, verification set and test set; Preprocessing of industrial parts image dataset; Obtain the standard YOLOv8 network structure for pre-training and obtain the pre-training weights; Improve the standard YOLOv8 network structure to obtain an improved YOLOv8 network; Repeat the training of the improved YOLOv8 network model and adjust the parameters to optimize the model to obtain the final trained YOLOv8 model; Based on the trained YOLOv8 model, defect detection is performed on industrial parts to obtain detection results.

2. The method according to claim 1, characterized in that The industrial parts image dataset specifically includes: normal images and images of different types of defects at different angles and backgrounds, and annotates each defective industrial parts image with a corresponding error label.

3. The method according to claim 2, characterized in that The preprocessing of industrial parts image dataset includes the following steps: Scaling the industrial parts image dataset and cropping or padding the images; Image enhancement technology is used to adjust the brightness, contrast and saturation of images in the industrial parts image dataset, and random flip, rotation and scaling operations are performed; The numerical range of image pixels in the industrial parts image dataset is normalized and the pixels are scaled.

4. The method according to claim 3, characterized in that Obtaining pre-trained weights involves the following steps: Get the ILSVRC2012 dataset and weight file, and adjust the image size of the ILSVRC2012 dataset to match the size of the images in the preprocessed industrial parts image dataset; Get the standard YOLOv8 network structure; Use a predefined learning rate scheduling strategy to adjust the initial learning rate; gradually increase the learning rate in the early stage to ensure fast convergence; reduce the learning rate in the later stage for fine correction; Use the adjusted ILSVRC2012 dataset and pre-define the learning rate scheduling strategy to pre-train the standard YOLOv8 network structure and obtain the pre-training weights.

5. The method according to claim 1, characterized in that The improved YOLOv8 network includes the backbone network, the neck network and the detection head; the attention mechanism CBAM is inserted after the C2f module; the Mish activation function is introduced to replace the activation function SiLU in the original YOLOv8 algorithm; GIoU is introduced instead of CIoU as the new bounding box regression loss function.

6. The method according to claim 5, characterized in that The attention mechanism CBAM includes: Channel attention module CAM and spatial attention module SAM; Among them, the specific formula of the channel attention module CAM is: Among them, F represents the intermediate feature map, σ represents the Sigmoid activation function, MLP represents the multi-layer perceptron, AvgPool represents the average pooling, MaxPool represents the maximum pooling, W1 and W0 represent the input shared weights, respectively. and Represent the average pooling features and maximum pooling features of the channel respectively; The specific formula of the spatial attention module SAM is: Among them, F represents the intermediate feature map, σ represents the Sigmoid activation function, and f 7*7 represents a convolution operation with a filter size of 7×7, AvgPool represents average pooling, and MaxPool represents maximum pooling. and They represent the average pooling features and the maximum pooling features of the space respectively.

7. The method according to claim 5, characterized in that The specific formula of the Mish activation function is: f(x)=xtanh(ln(1+e x )) (3) The specific formula of the GIoU loss function is: Among them, IoU represents the ratio of the intersection area to the union area, B∪B gt represents the union area of ​​the predicted box and the true box, and C represents the minimum enclosing rectangular area of ​​the detection box and the predicted box.

8. The method according to claim 1, characterized in that: Obtaining the final YOLOv8 model involves the following steps: Use the pre-trained weights as the initial weights of the improved YOLOv8 network structure and configure the model's hyperparameters, including input image size, anchor box settings, and number of categories; Define the loss function and additional loss items, select the optimizer and set the learning rate; the loss function includes the generalized intersection-over-union loss function GioULoss and the focus loss function FocalLoss. The specific formula is: GioULoss=IoU-(C-Union) / C (5) Among them, C represents the minimum enclosing box of the predicted bounding box and the true bounding box; Union represents the union of the predicted bounding box and the true bounding box; pt represents the probability that the predicted category is a positive sample; represents the adjustment factor set by the hyperparameter, Build a data loader to load the preprocessed images and corresponding annotation information from the industrial parts image dataset; Iterate through the training set, perform weight training and parameter update on the improved YOLOv8 network structure, calculate the loss between the prediction result and the true annotation, and perform back propagation to update the weight; evaluate the performance of the improved YOLOv8 network structure on the validation set, and evaluate the weight, including calculating the accuracy, recall rate, and average precision mean; until the recognition rate reaches a certain threshold, the weight at this time is the final weight, and the final YOLOv8 model is obtained.

9. A storage medium, characterized in that: The storage medium stores instructions, and when a computer reads the instructions, the computer executes the industrial parts defect detection method based on the improved YOLOv8 model as described in any one of claims 1 to 8.

10. An electronic device, characterized in that: The invention comprises a processor and the storage medium as claimed in claim 9, wherein the processor executes instructions in the storage medium.

Citation Information

Patent Citations

  • Drug packaging aluminum foil surface defect detection method based on improved YOLOX

    CN116935208A

  • Water turbine top cover defect detection method based on improved YOLOv8 model

    CN117541538A

  • Lightweight up-sampling YOLOX broken gate detection model construction method and system

    CN117671452A

  • Aluminum profile surface defect detection method based on YOLOX-S network

    CN118115437A

  • Electronic component defect detection method based on improved YOLOv5 model

    CN118172318A

Cited By

  • Road surface well lid defect automatic detection method and system based on improved YOLOv8 model

    CN120013888A

  • Mechanical part defect detection method and system based on improved YOLOv12 model

    CN120279020A

  • Sub-cartridge case surface defect detection method and image training and reasoning integrated platform

    CN121304597A