Bearing outer ring surface defect detection method based on improved YOLOv8n

By introducing attention mechanism, downsampling module and feature extraction fusion module into the YOLOv8n model, the existing models have solved the problems of insufficient accuracy, large calculation amount, and insufficient complex defect recognition capabilities when detecting surface defects of the bearing outer ring, and achieved more efficient and accurate defect detection.

CN119579553APending Publication Date: 2025-03-07HARBIN UNIV OF SCI & TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411675553.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-21
Publication Date
2025-03-07

AI Technical Summary

Technical Problem

When detecting surface defects of the bearing outer ring, the existing YOLOv8n model lacks detection accuracy, large calculation amount, and insufficient ability to identify complex defects.

Method used

By introducing attention mechanism, downsampling module and feature extraction fusion module, the YOLOv8n model is improved, the detection accuracy is improved, the model complexity and calculation amount is reduced, and the ability to identify complex defects is enhanced.

Benefits of technology

It improves the accuracy and speed of surface defect detection of bearing outer ring surface, reduces the complexity and calculation amount of the model, and enhances the ability to identify complex defects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119579553A_ABST
    Figure CN119579553A_ABST
Patent Text Reader

Abstract

The invention discloses a bearing outer ring surface defect detection method based on improved YOLOv8n, and belongs to the field of target detection. The method sequentially comprises the following steps: step a, acquiring an image of surface defects of the bearing outer ring, wherein the defects comprise grooves, scratches, scratches and stains; b, preprocessing the surface defect image of the bearing outer ring, and constructing a complete data set; c, improving the YOLOv8n model, and introducing an attention module, a sampling module and a feature extraction fusion module; d, an improved YOLOv8n model is trained; step e, outputting an improved YOLOv8n optimal model; step f, testing the improved YOLOv8n optimal model; experimental results show that by introducing the attention mechanism, the down-sampling module and the feature extraction and fusion module, the detection precision is improved, the complexity of the model is reduced, the operation speed is improved, and meanwhile the capacity of the model for recognizing complex defects is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention discloses a bearing outer ring surface defect detection method based on improved YOLOv8n and belongs to the field of target detection. Background Art

[0002] Bearings are an important component in modern mechanical equipment and are widely used in the field of industrial production. Their quality directly affects the stability and safety of equipment and instruments. In the production process, the shortcomings and limitations of existing technology and working conditions will affect the quality of bearing products. Among them, surface defects on the outer ring of the bearing are the most intuitive manifestation of product quality, including scratches, grooves, abrasions and stains.

[0003] Early defect detection uses visual methods, which can detect product quality problems to a certain extent, but are highly subjective and inefficient, and cannot meet the needs of high-precision and real-time monitoring. With the development of computer vision and artificial intelligence technology, more technical means are provided for bearing outer ring surface defect detection.

[0004] The deep learning-based target detection algorithm automatically discovers the features required for detecting and classifying targets by using convolutional neural networks (CNN) to learn features. At the same time, the convolutional neural network converts the original input information into more abstract and higher-dimensional features. This high-dimensional feature has powerful feature expression ability and generalization, so it performs well in complex scenarios and can meet most application needs in the industry.

[0005] Object detection algorithms based on deep learning can be roughly divided into two categories according to the characteristics of their algorithm flow: two-stage object detection algorithms and single-stage object detection algorithms. The two-stage object detection algorithm represented by R-CNN has high detection accuracy, but the defect of slow detection speed restricts its wide application in industry. The single-stage object detection algorithm represented by YOLOv8n not only has the characteristics of high detection accuracy, but also fast detection speed, so it has been widely used in the industry. If YOLOv8n's unique network architecture and powerful performance are used to detect surface defects of bearing outer rings, it will be beneficial to enrich detection methods and improve detection accuracy and speed.

[0006] However, although YOLOv8n performs well in many detection fields, it still has the following limitations if it is directly applied to identify surface defects on the outer ring of a bearing:

[0007] First, there are many types of surface defects on the outer ring of the bearing, and the detection accuracy needs to be further improved;

[0008] Second, the existing YOLOv8n model is too complex, requires large amounts of computation, and its computational speed needs to be further improved;

[0009] Third, there may be multiple defects on the surface of the bearing outer ring at the same time, and the algorithm's ability to identify complex defects needs to be improved. Summary of the invention

[0010] In view of the limitations of directly applying the existing YOLOv8n model to the surface defect detection of the bearing outer ring, the present invention proposes a bearing outer ring surface defect detection method based on improved YOLOv8n. The model introduces an attention mechanism, a downsampling module and a feature extraction fusion module. While improving the detection accuracy, it reduces the complexity of the model, increases the calculation speed, and also improves the model's ability to identify complex defects.

[0011] The object of the present invention is achieved in that:

[0012] The bearing outer ring surface defect detection method based on improved YOLOv8n includes the following steps:

[0013] Step a: Under laboratory conditions, collect images of surface defects on the outer ring of the bearing, wherein the defects include grooves, abrasions, scratches and stains;

[0014] Step b, preprocessing the surface defect image of the bearing outer ring and constructing a complete data set;

[0015] Step c, improve the YOLOv8n model, introduce the attention module, sampling module and feature extraction fusion module;

[0016] Step d, inputting the data set described in step b into the improved YOLOv8n model for training;

[0017] Step e: output the improved YOLOv8n optimal model. The indicators after training include defect category, number of defect images, number of defect rectangles, precision, R recall, mAP50, mAP50-95, parameter amount and calculation amount.

[0018] Step f: Use the test set to test the improved YOLOv8n optimal model to verify the accuracy of the improved YOLOv8n optimal model in detecting surface defects of the bearing outer ring. The test content includes defect location, defect type and confidence.

[0019] The above-mentioned bearing outer ring surface defect detection method based on improved YOLOv8n, step b specifically includes:

[0020] Step b1, image noise addition: In order to increase the diversity of training data and improve the generalization ability of the model, the OpenCV library is used to add salt and pepper noise to some bearing outer ring surface defect images;

[0021] Step b2, defect type classification: the bearing outer ring surface defect image before and after noise addition is classified into four categories: groove, abrasion, scratch and stain according to the defect type;

[0022] Step b3, image annotation: Use the labelimg image annotation tool to annotate the defect area of ​​the bearing outer ring surface defect image before and after noise addition, and segment the defect area;

[0023] Step b4, dividing the data set: all labeled bearing outer ring surface defect images are divided into a training set, a validation set and a test set according to a ratio of 7:2:1.

[0024] In the above-mentioned bearing outer ring surface defect detection method based on improved YOLOv8n, step c specifically includes:

[0025] Step c1, environment configuration: Use Miniconda3 to build a virtual environment on the Pycharm platform and use the YOLOv8n model source code;

[0026] Step c2, data input: input the data set described in step b into the YOLOv8n model source code, obtain the bearing outer ring surface defect image, the bearing outer ring surface defect image label, the YOLOv8n network structure model configuration file and the YOLOv8n network structure model pre-training weight;

[0027] Step c3, setting hyperparameters: setting the optimal hyperparameter combination of learning rate, number of iterations, number of batch samples, image size, number of image channels and learning rate momentum;

[0028] Step c4, model setting: Improve the YOLOv8n model source code, specifically including:

[0029] Step c4-1, introduce the attention module;

[0030] Step c4-2, using a downsampling module;

[0031] Step c4-3: Use feature extraction and fusion module.

[0032] Step c4-1 specifically includes:

[0033] Step c4-1-1, module composition: the attention module consists of a channel attention module and a spatial attention module;

[0034] Step c4-1-2, module addition: Add the attention module before the SPPF module in the backbone, and set the input and output channels to 1024 and the convolution kernel to 7;

[0035] The following steps describe the process of processing the feature map through the channel attention module:

[0036] Step c4-1-3, input the feature map, perform global maximum pooling and global average pooling operations on each channel at the same time, obtain the maximum eigenvalue and average eigenvalue on each channel, and generate two vectors containing the number of channels, which respectively represent the global maximum feature and average feature of each channel;

[0037] Specifically, let the intermediate feature map be F, with a size of C×H×W, where C is the number of channels, H is the height, and W is the width, expressed as: F∈R C×H×W ; After global maximum pooling and global average pooling, two C-dimensional pooling feature maps F are obtained c avg and F c max , the formula is:

[0038] F c avg =AvgPool(F)

[0039] F c max =MaxPool(F)

[0040] Step c4-1-4, F c avg and F c max They are input into the shared fully connected layer MLP respectively, and the global maximum feature vector and the average feature vector are intersected to obtain the final attention weight vectors F1 and F2. The formula is:

[0041] F1=MLP(F c avg )

[0042] F2=MLP(F c max )

[0043] Both F1 and F2 are feature maps of size C×1×1;

[0044] Step c4-1-5, add F1 and F2 according to the corresponding elements, the formula is:

[0045] F3=F1+F2

[0046] Get the attention-weighted channel feature map F3;

[0047] Step c4-1-6: Use the Sigmoid activation function σ to process the channel feature map F3 obtained in step c4-1-5 to obtain the final channel attention map Mc (F), the size is C×1×1, and the formula is:

[0048] M c (F) = σ(F3)

[0049] The channel attention map M c (F) is between 0 and 1;

[0050] Step c4-1-7: The feature map M obtained in step c4-1-6 c (F) is multiplied by the feature map F to obtain the feature map F' after channel attention refinement. The formula is:

[0051]

[0052] in, Indicates the multiplication of corresponding elements;

[0053] The following steps are the process of the feature map processed by the channel attention module entering the spatial attention module:

[0054] Step c4-1-8: Perform maximum pooling and average pooling operations on the feature map F' obtained in step c4-1-7 along the channel direction to obtain two-dimensional feature maps F4 and F5. The formula is:

[0055] F4=AvgPool(F')

[0056] F5=MaxPool(F')

[0057] The sizes of F4 and F5 are both 1×H×W;

[0058] Step c4-1-9: Concatenate F4 and F5 obtained in step c4-1-8 in the channel dimension to obtain a feature map of size 2×H×W, and perform a 7×7 convolution operation on the concatenated result, compress the number of channels to 1, and obtain a feature map F6 of size 1×H×W. The formula is:

[0059] F6=f 7×7 ([F4; F5])

[0060] Among them, f 7×7 represents a 7×7 convolution operation, and [F4; F5] represents the concatenation of F4 and F5;

[0061] Step c4-1-10: Use the Sigmoid activation function σ to process the feature map F6 obtained in step c4-1-9 to obtain the feature map M s (F'), the formula is:

[0062] M s(F') = σ(F6)

[0063] The channel attention map M s (F') lies between 0 and 1;

[0064] Step c4-1-11: The feature map M obtained in step c4-1-10 s (F') is multiplied by the feature map F' to obtain the final output F' feature map after processing by the attention module. The formula is:

[0065]

[0066] in, Represents the multiplication of corresponding elements.

[0067] Step c4-2 specifically includes:

[0068] Step c4-2-1, module replacement: Use the downsampling module to replace some Conv modules of the backbone and all Conv modules of the head in YOLOv8n; the sampling module consists of 1 average pooling block, 1 segmentation module, 1 maximum pooling module, 2 convolution modules and 1 splicing module;

[0069] Step c4-2-2, feature map A enters the avgpool layer, the convolution kernel size of the avgpool layer is 2×2, and the step size is 1, so as to extract the information features of feature map A;

[0070] Step c4-2-3, input the information features obtained in step c4-2-2 into the dimension segmentation module, halve the number of channels of the feature map along the channel direction, and divide it into two feature maps A1 and A2 with the same number of channels; feature map A1 enters the convolution block conv1 with a convolution kernel of 3×3, a step size of 2, and a padding of 1, extracts useful information from the feature map A1, and obtains feature map A3;

[0071] Step c4-2-4, feature map A2 enters the maxpool layer, the convolution kernel size of the maxpool layer is 3×3, the step size is 2, and the padding is 1. Feature extraction is performed on feature map A2, and the extracted feature map is input into the convolution block conv2 with a convolution kernel of 1×1, a step size of 1, and a padding of 0 to further extract useful information in the feature map to obtain feature map A4;

[0072] Step c4-2-5, concatenate feature map A4 and feature map A3 through the concat module to obtain feature map B, and use average pooling and maximum pooling to optimize the number of parameters in the input convolution layer to reduce the complexity of the model.

[0073] Step c4-3 specifically includes: replacing all C2f modules in the backbone and head parts of YOLOv8n with feature extraction fusion modules; the feature extraction fusion module simply replaces the Bottleneck in the C2f module with a CIB structure; the CIB module structure includes three 3×3 depth convolutions and two 1×1 point convolutions.

[0074] The above-mentioned bearing outer ring surface defect detection method based on improved YOLOv8n, step d specifically includes:

[0075] Step d1, model training: During the training process, iterative training is performed, and the model is validated on the validation set to evaluate the accuracy and recall of the model;

[0076] Step d2, learning rate adjustment: dynamically adjust the learning rate according to the verification results;

[0077] Step d3, training completed: When the training reaches the preset number of iterations or the performance on the validation set cannot be improved any further, the network model training is completed.

[0078] The beneficial effects of the bearing outer ring surface defect detection method based on improved YOLOv8n of the present invention are:

[0079] First, by introducing the attention mechanism, the channel attention module and the spatial attention module further enhance the feature expression ability of the model, and by emphasizing important features and suppressing unimportant features, the accuracy of bearing outer ring surface defect detection is improved;

[0080] Second, by using the downsampling module, due to the lightweight design of the downsampling module, the average pooling and maximum pooling are used to optimize the number of parameters in the input convolution layer, thereby reducing the number of parameters, further reducing the complexity of the model, making the model lightweight, and improving the operation speed;

[0081] Third, by using the feature extraction fusion module, the unique CIB structure of this feature extraction fusion module combines deep convolution and point convolution, thereby effectively improving the feature extraction and expression capabilities of the model, and on the basis of introducing the attention mechanism, greatly improving the model's ability to recognize complex defects. BRIEF DESCRIPTION OF THE DRAWINGS

[0082] Figure 1 It is a flow chart of a bearing outer ring surface defect detection method based on improved YOLOv8n of the present invention;

[0083] Figure 2 This is a basic example diagram for defect image acquisition;

[0084] Figure 3 This is the bearing defect map with salt and pepper noise added;

[0085] Figure 4 This is an example image of defect annotation using labelimg;

[0086] Figure 5 This is the network structure diagram of YOLOv8n;

[0087] Figure 6 It is the network structure diagram of the improved YOLOv8n;

[0088] Figure 7 It is the attention module structure;

[0089] Figure 8 It is the downsampling module structure;

[0090] Fig. 9 It is the feature extraction and fusion module structure;

[0091] Fig.10 It is the CIB module structure diagram;

[0092] Fig.11 This is the training result diagram of YOLOv8n;

[0093] Fig.12 This is the training result diagram of improved YOLOv8n;

[0094] Fig.13 It is the time result of improving YOLOv8n model and YOLOv8n model defect prediction;

[0095] Fig.14 To improve the YOLOv8n model and the defect recognition prediction map of the YOLOv8n model; DETAILED DESCRIPTION

[0096] The specific implementation modes of the present invention are further described in detail below with reference to the accompanying drawings.

[0097] The bearing outer ring surface defect detection method based on improved YOLOv8n in this specific implementation manner, the method flow chart is as follows Figure 1 As shown, the following steps are included:

[0098] Step a: Under laboratory conditions, collect images of surface defects on the outer ring of the bearing, wherein the defects include grooves, abrasions, scratches and stains;

[0099] Step a1, placing the bearing to be tested, and adjusting the placement position and style of the bearing to be tested on the test platform;

[0100] Step a2, adjusting the camera position angle and parameters so that the bearing to be tested appears within the lens;

[0101] Step a3, adjusting the position, intensity and angle of the light source;

[0102] Step a4: take photos.

[0103] In this specific implementation, part of the data is a public data set on the Internet, and the other part of the data is data taken under laboratory conditions. The basic example of image acquisition is as follows: Figure 2 As shown, by continuously adjusting the placement and style of the bearings to be tested on the test platform, the diversity of the defect data set can be increased, making it more in line with the actual situation of bearing detection in the actual factory environment.

[0104] Step b, preprocessing the surface defect image of the bearing outer ring and constructing a complete data set;

[0105] Step b1, image noise addition: In order to increase the diversity of training data and improve the generalization ability of the model, the OpenCV library is used to add salt and pepper noise to some bearing outer ring surface defect images;

[0106] Step b2, defect type classification: the bearing outer ring surface defect image before and after noise addition is classified into four categories: groove, abrasion, scratch and stain according to the defect type;

[0107] Step b3, image annotation: Use the labelimg image annotation tool to annotate the defect area of ​​the bearing outer ring surface defect image before and after noise addition, and segment the defect area;

[0108] Step b4, dividing the data set: all labeled bearing outer ring surface defect images are divided into a training set, a validation set and a test set according to a ratio of 7:2:1.

[0109] In this specific embodiment, Figure 3 As shown in the figure, the np.random.randint function in the OpenCV library is used to add salt and pepper noise to some defective images to increase the diversity of training data and simulate the acquisition of images in actual complex environments; Figure 4 As shown in the figure, labelimg is used to annotate the bearing defect images. A total of 6849 defect images of four types of defects, namely grooves, abrasions, scratches and stains, are divided into 4794 images of training set, 1369 images of validation set and 686 images of test set in a ratio of 7:2:1. Some images contain more than one type of defect. Among them, the four types of defects, grooves, abrasions, scratches and stains, are classified and annotated in detail, and the labels are 0: groove; 1: scrape; 2: scratches; 3: strains. This can improve the detection accuracy of surface defects on the outer ring of the bearing.

[0110] Step c: Improve the YOLOv8n model by introducing the attention module, sampling module and feature extraction fusion module. Figure 6 As shown:

[0111] Step c1, environment configuration: Use Miniconda3 to build a virtual environment on the Pycharm platform and use the YOLOv8n model source code;

[0112] Step c2, data input: input the data set described in step b into the YOLOv8n model source code, obtain the bearing outer ring surface defect image, the bearing outer ring surface defect image label, the YOLOv8n network structure model configuration file and the YOLOv8n network structure model pre-training weight;

[0113] Step c3, setting hyperparameters: setting the optimal hyperparameter combination of learning rate, number of iterations, number of batch samples, image size, number of image channels and learning rate momentum;

[0114] Step c4, model setting: Improve the YOLOv8n model source code, specifically including:

[0115] Step c4-1, introduce the attention module, such as Figure 7 As shown;

[0116] Step c4-2, using a downsampling module, such as Figure 8 As shown;

[0117] Step c4-3, using feature extraction fusion module, such as Fig. 9 shown.

[0118] Step c4-1 specifically includes:

[0119] Step c4-1-1, module composition: the attention module consists of a channel attention module and a spatial attention module;

[0120] Step c4-1-2, module addition: Add the attention module before the SPPF module in the backbone, and set the input and output channels to 1024 and the convolution kernel to 7;

[0121] The following steps describe the process of processing the feature map through the channel attention module:

[0122] Step c4-1-3, input the feature map, perform global maximum pooling and global average pooling operations on each channel at the same time, obtain the maximum eigenvalue and average eigenvalue on each channel, and generate two vectors containing the number of channels, which respectively represent the global maximum feature and average feature of each channel;

[0123] Specifically, let the intermediate feature map be F, with a size of C×H×W, where C is the number of channels, H is the height, and W is the width, expressed as: F∈R C×H×W ; After global maximum pooling and global average pooling, two C-dimensional pooling feature maps F are obtained c avg and F c max , the formula is:

[0124] F c avg =AvgPool(F)

[0125] F c max =MaxPool(F)

[0126] Step c4-1-4, F c avg and F c max They are input into the shared fully connected layer MLP respectively, and the global maximum feature vector and the average feature vector are intersected to obtain the final attention weight vectors F1 and F2. The formula is:

[0127] F1=MLP(F c avg )

[0128] F2=MLP(F c max )

[0129] Both F1 and F2 are feature maps of size C×1×1;

[0130] Step c4-1-5, add F1 and F2 according to the corresponding elements, the formula is:

[0131] F3=F1+F2

[0132] Get the attention-weighted channel feature map F3;

[0133] Step c4-1-6: Use the Sigmoid activation function σ to process the channel feature map F3 obtained in step c4-1-5 to obtain the final channel attention map M c (F), the size is C×1×1, and the formula is:

[0134] M c (F) = σ(F3)

[0135] The channel attention map M c (F) is between 0 and 1;

[0136] Step c4-1-7: The feature map M obtained in step c4-1-6c (F) is multiplied by the feature map F to obtain the feature map F' after channel attention refinement. The formula is:

[0137]

[0138] in, Indicates the multiplication of corresponding elements;

[0139] The following steps are the process of the feature map processed by the channel attention module entering the spatial attention module:

[0140] Step c4-1-8: Perform maximum pooling and average pooling operations on the feature map F' obtained in step c4-1-7 along the channel direction to obtain two-dimensional feature maps F4 and F5. The formula is:

[0141] F4=AvgPool(F')

[0142] F5=MaxPool(F')

[0143] The sizes of F4 and F5 are both 1×H×W;

[0144] Step c4-1-9: Concatenate F4 and F5 obtained in step c4-1-8 in the channel dimension to obtain a feature map of size 2×H×W, and perform a 7×7 convolution operation on the concatenated result, compress the number of channels to 1, and obtain a feature map F6 of size 1×H×W. The formula is:

[0145] F6=f 7×7 ([F4; F5])

[0146] Among them, f 7×7 represents a 7×7 convolution operation, and [F4; F5] represents the concatenation of F4 and F5;

[0147] Step c4-1-10: Use the Sigmoid activation function σ to process the feature map F6 obtained in step c4-1-9 to obtain the feature map M s (F'), the formula is:

[0148] M s (F') = σ(F6)

[0149] The channel attention map M s (F') lies between 0 and 1;

[0150] Step c4-1-11: The feature map M obtained in step c4-1-10 s (F') is multiplied by the feature map F' to obtain the final output F' feature map after processing by the attention module. The formula is:

[0151]

[0152] in, Represents the multiplication of corresponding elements.

[0153] Step c4-2 specifically includes:

[0154] Step c4-2-1, module replacement: Use the downsampling module to replace some Conv modules of the backbone and all Conv modules of the head in YOLOv8n; the sampling module consists of 1 average pooling block, 1 segmentation module, 1 maximum pooling module, 2 convolution modules and 1 splicing module, such as Figure 8 As shown;

[0155] Step c4-2-2, feature map A enters the avgpool layer, the convolution kernel size of the avgpool layer is 2×2, and the step size is 1, so as to extract the information features of feature map A;

[0156] Step c4-2-3, input the information features obtained in step c4-2-2 into the dimension segmentation module, halve the number of channels of the feature map along the channel direction, and divide it into two feature maps A1 and A2 with the same number of channels; feature map A1 enters the convolution block conv1 with a convolution kernel of 3×3, a step size of 2, and a padding of 1, extracts useful information from the feature map A1, and obtains feature map A3;

[0157] Step c4-2-4, feature map A2 enters the maxpool layer, the convolution kernel size of the maxpool layer is 3×3, the step size is 2, and the padding is 1. Feature extraction is performed on feature map A2, and the extracted feature map is input into the convolution block conv2 with a convolution kernel of 1×1, a step size of 1, and a padding of 0 to further extract useful information in the feature map to obtain feature map A4;

[0158] Step c4-2-5, concatenate feature map A4 and feature map A3 through the concat module to obtain feature map B, and use average pooling and maximum pooling to optimize the number of parameters in the input convolution layer to reduce the complexity of the model.

[0159] Step c4-3 specifically includes: replacing all C2f modules in the backbone and head parts of YOLOv8n with feature extraction and fusion modules; the feature extraction and fusion module simply replaces the Bottleneck in the C2f module with the CIB structure, such as Fig. 9 As shown; the CIB module structure includes three 3×3 depth convolutions and two 1×1 point convolutions, as shown Fig.10 shown.

[0160] Step d, inputting the data set described in step b into the improved YOLOv8n model for training;

[0161] Step d1, model training: During the training process, iterative training is performed, and the model is validated on the validation set to evaluate the accuracy and recall of the model;

[0162] Step d2, learning rate adjustment: dynamically adjust the learning rate according to the verification results;

[0163] Step d3, training completed: When the training reaches the preset number of iterations or the performance on the validation set cannot be improved any further, the network model training is completed.

[0164] In this specific implementation, when configuring the environment, the network structure model of YOLOv8n is downloaded from GitHub, and then a virtual environment is built using Miniconda3 on the Pycharm platform. The following dependent libraries are made according to the libraries required by the YOLOv8n source code: matplotlib=3.9.2, numpy=1.26.4, opencv-python=3.10.0.84, pillow=10.4.0, pip=24.2, requests=2.32.3, scipy=1.14.1, torch=2.3.1+cu121, torchaudio=2.3.1+cu121, torchvision=0.18.1+cu121, ultralytics=8.2.86. Improved YOLOv8n model structure and YOLOv8n model structure Figure 5 and Figure 6 As shown in the figure, the constructed data set is input into the improved YOLOv8n model with set hyperparameters and the YOLOv8n model for training. The configuration used is: CPU: AMD Ryzen7 7840H, CPU main frequency: 3.80GHZ, memory: 16G, GPU: NVIDIA GeForce RTX 4060, video memory: 8188MB GDDR6. The deep learning framework is PyTorch, and the development environment is PyTorch2.3.1, Python3.10, Cuda12.1. The set hyperparameters include: learning rate lr=0.01, batch size Batchsize=50, iteration number Epoch=100, image channel number Channels=3, image crop size Cropsize=640×640, learning rate momentum momentum=0.937.

[0165] Step e, output the training results of the optimal model of the improved YOLOv8n model, including defect category (Class), number of defect images (Images), number of defect rectangle boxes (Instances), precision (Box(p), R recall rate, mAP50 and mAP50-95, parameter amount (Parameters) and calculation amount (GFLOPs);

[0166] In this specific implementation, the improved YOLOv8n model and the YOLOv8n model are trained, and the training results are as follows: Fig.11 , Fig.12 As shown in the figure, including defect category (Class), number of defect images (Images), defect rectangle box (Instances), precision (Box(p), recall rate, mAP50 and mAP50-95, parameter amount (Parameters) and computational amount (GFLOPs); from the training results, it can be seen that the improved YOLOv8n model is compared with the YOLOv8n model: the precision (Box(p) is improved by 0.4%, the recall rate R is improved by 0.5%, the mAP50 is improved by 1%, and the mAP50-95 is improved by 0.4%. It can be seen that the improved YOLOv8n model has higher accuracy in identifying surface defects of the outer ring of the bearing; the number of parameters of the model is reduced by about 33%, and the computational amount of the model is reduced by about 30.9%. It can be seen that the improved YOLOv8n model is lighter and less complex, so that the model can minimize the computational amount and storage requirements while ensuring the performance of the model on resource-constrained devices, thereby improving the energy efficiency of the model.

[0167] Step f: Use the test set to test the improved YOLOv8n optimal model to verify the accuracy of the improved YOLOv8n optimal model in detecting surface defects of the bearing outer ring. The test content includes defect location, defect type and confidence.

[0168] In order to verify the superiority of the method of the present invention, the test results of the improved YOLOv8n model and the YOLOv8n model are compared: Fig.13As shown, first calculate the FPS of each prediction image of the improved YOLOv8n model and the YOLOv8n model, and then take the average respectively, so as to obtain the FPS of the improved YOLOv8n model and the FPS of the YOLOv8n model. Obviously, the improved YOLOv8n model has a faster detection speed. FPS represents the number of image frames processed in one second, which is an indicator to measure the speed of image processing or model inference. Its calculation formula is given in the figure, where preprocess represents the image preprocessing time, inference represents the inference time, which refers to the time from the image input model after preprocessing to the model output result, and postprocess represents the post-processing time. Fig.14 As shown, a1, b1, c1, d1, e1, and f1 are the prediction graphs of the YOLOv8n model, and a2, b2, c2, d2, e2, and f2 are the prediction graphs of the improved YOLOv8n model. Fig.14 It can be seen that by comparing the prediction images a1 and a2, b1 and b2, c1 and c2, d1 and d2, it is obvious that the improved YOLOv8n model has better detection results, higher confidence, and higher defect recognition accuracy; by comparing the prediction images e1 and e2, f1 and f2, since the two predicted images contain multiple defects including minor defects, some defects are not recognized after recognition by the YOLOv8n model, while the improved YOLOv8n model can accurately identify all defects. Obviously, the improved YOLOv8n model performs better when dealing with multiple types of defects and minor defects, and can better accurately locate and classify defects.

Claims

1. A bearing outer ring surface defect detection method based on improved YOLOv8n, characterized in that: The following steps are involved: Step a: Under laboratory conditions, collect images of surface defects on the outer ring of the bearing, wherein the defects include grooves, abrasions, scratches and stains; Step b, preprocessing the surface defect image of the bearing outer ring and constructing a complete data set; Step c, improve the YOLOv8n model, introduce the attention module, sampling module and feature extraction fusion module; Step d, inputting the data set described in step b into the improved YOLOv8n model for training; Step e: output the improved YOLOv8n optimal model. The indicators after training include defect category, number of defect images, number of defect rectangles, precision, R recall, mAP50, mAP50-95, parameter amount and calculation amount. Step f: Use the test set to test the improved YOLOv8n optimal model to verify the accuracy of the improved YOLOv8n optimal model in detecting surface defects of the bearing outer ring. The test content includes defect location, defect type and confidence.

2. The bearing outer ring surface defect detection method based on improved YOLOv8n according to claim 1 is characterized in that: Step b specifically includes: Step b1, image noise addition: In order to increase the diversity of training data and improve the generalization ability of the model, the OpenCV library is used to add salt and pepper noise to some bearing outer ring surface defect images; Step b2, defect type classification: the bearing outer ring surface defect image before and after noise addition is classified into four categories: groove, abrasion, scratch and stain according to the defect type; Step b3, image annotation: Use the labelimg image annotation tool to annotate the defect area of ​​the bearing outer ring surface defect image before and after noise addition, and segment the defect area; Step b4, dividing the data set: all labeled bearing outer ring surface defect images are divided into a training set, a validation set and a test set according to a ratio of 7:2:

1.

3. The bearing outer ring surface defect detection method based on improved YOLOv8n according to claim 1 is characterized in that: Step c specifically includes: Step c1, environment configuration: Use Miniconda3 to build a virtual environment on the Pycharm platform and use the YOLOv8n model source code; Step c2, data input: input the data set described in step b into the YOLOv8n model source code, obtain the bearing outer ring surface defect image, the bearing outer ring surface defect image label, the YOLOv8n network structure model configuration file and the YOLOv8n network structure model pre-training weight; Step c3, setting hyperparameters: setting the optimal hyperparameter combination of learning rate, number of iterations, number of batch samples, image size, number of image channels and learning rate momentum; Step c4, model setting: Improve the YOLOv8n model source code, specifically including: Step c4-1, introduce the attention module; Step c4-2, using a downsampling module; Step c4-3: Use feature extraction and fusion module.

4. The bearing outer ring surface defect detection method based on improved YOLOv8n according to claim 3 is characterized in that: Step c4-1 specifically includes: Step c4-1-1, module composition: the attention module consists of a channel attention module and a spatial attention module; Step c4-1-2, module addition: Add the attention module before the SPPF module in the backbone, and set the input and output channels to 1024 and the convolution kernel to 7; The following steps describe the process of processing the feature map through the channel attention module: Step c4-1-3, input the feature map, perform global maximum pooling and global average pooling operations on each channel at the same time, obtain the maximum eigenvalue and average eigenvalue on each channel, and generate two vectors containing the number of channels, which respectively represent the global maximum feature and average feature of each channel; Specifically, let the intermediate feature map be F, with a size of C×H×W, where C is the number of channels, H is the height, and W is the width, expressed as: F∈R C×H×W ; After global maximum pooling and global average pooling, two C-dimensional pooling feature maps F are obtained c avg and F c max , the formula is: F c avg =AvgPool(F) F c max =MaxPool(F) Step c4-1-4, F c avg and F c max They are input into the shared fully connected layer MLP respectively, and the global maximum feature vector and the average feature vector are intersected to obtain the final attention weight vectors F1 and F2. The formula is: F1=MLP(F c avg ) F2=MLP(F c max ) Both F1 and F2 are feature maps of size C×1×1; Step c4-1-5, add F1 and F2 according to the corresponding elements, the formula is: F3=F1+F2 Get the attention-weighted channel feature map F3; Step c4-1-6: Use the Sigmoid activation function σ to process the channel feature map F3 obtained in step c4-1-5 to obtain the final channel attention map M c (F), the size is C×1×1, and the formula is: M c (F)=σ(F3) The channel attention map M c (F) is between 0 and 1; Step c4-1-7: The feature map M obtained in step c4-1-6 c (F) is multiplied by the feature map F to obtain the feature map F' after channel attention refinement. The formula is: in, Indicates the multiplication of corresponding elements; The following steps are the process of the feature map processed by the channel attention module entering the spatial attention module: Step c4-1-8: Perform maximum pooling and average pooling operations on the feature map F' obtained in step c4-1-7 along the channel direction to obtain two-dimensional feature maps F4 and F5. The formula is: F4=AvgPool(F') F5=MaxPool(F') The sizes of F4 and F5 are both 1×H×W; Step c4-1-9: Concatenate F4 and F5 obtained in step c4-1-8 in the channel dimension to obtain a feature map of size 2×H×W, and perform a 7×7 convolution operation on the concatenated result, compress the number of channels to 1, and obtain a feature map F6 of size 1×H×W. The formula is: F6=f 7×7 ([F4;F5]) Among them, f 7×7 represents a 7×7 convolution operation, and [F4; F5] represents the concatenation of F4 and F5; Step c4-1-10: Use the Sigmoid activation function σ to process the feature map F6 obtained in step c4-1-9 to obtain the feature map M s (F'), the formula is: M s (F')=σ(F6) The channel attention map M s (F') lies between 0 and 1; Step c4-1-11: The feature map M obtained in step c4-1-10 s (F') is multiplied by the feature map F' to obtain the final output F' feature map after processing by the attention module. The formula is: in, Represents the multiplication of corresponding elements.

5. The bearing outer ring surface defect detection method based on improved YOLOv8n according to claim 3 is characterized in that: Step c4-2 specifically includes: Step c4-2-1, module replacement: Use the downsampling module to replace some Conv modules of the backbone and all Conv modules of the head in YOLOv8n; the sampling module consists of 1 average pooling block, 1 segmentation module, 1 maximum pooling module, 2 convolution modules and 1 splicing module; Step c4-2-2, feature map A enters the avgpool layer, the convolution kernel size of the avgpool layer is 2×2, and the step size is 1, so as to extract the information features of feature map A; Step c4-2-3, input the information features obtained in step c4-2-2 into the dimension segmentation module, halve the number of channels of the feature map along the channel direction, and divide it into two feature maps A1 and A2 with the same number of channels; feature map A1 enters the convolution block conv1 with a convolution kernel of 3×3, a step size of 2, and a padding of 1, extracts useful information from the feature map A1, and obtains feature map A3; Step c4-2-4, feature map A2 enters the maxpool layer, the convolution kernel size of the maxpool layer is 3×3, the step size is 2, and the padding is 1. Feature extraction is performed on feature map A2, and the extracted feature map is input into the convolution block conv2 with a convolution kernel of 1×1, a step size of 1, and a padding of 0 to further extract useful information in the feature map to obtain feature map A4; Step c4-2-5, concatenate feature map A4 and feature map A3 through the concat module to obtain feature map B, and use average pooling and maximum pooling to optimize the number of parameters in the input convolution layer to reduce the complexity of the model.

6. The bearing outer ring surface defect detection method based on improved YOLOv8n according to claim 3 is characterized in that: Step c4-3 specifically includes: replacing all C2f modules in the backbone and head parts of YOLOv8n with feature extraction fusion modules; the feature extraction fusion module simply replaces the Bottleneck in the C2f module with a CIB structure; the CIB module structure includes three 3×3 depth convolutions and two 1×1 point convolutions.

7. The bearing outer ring surface defect detection method based on improved YOLOv8n according to claim 1 is characterized in that: Step d specifically includes: Step d1, model training: During the training process, iterative training is performed, and the model is validated on the validation set to evaluate the accuracy and recall of the model; Step d2, learning rate adjustment: dynamically adjust the learning rate according to the verification results; Step d3, training completed: When the training reaches the preset number of iterations or the performance on the validation set cannot be improved any further, the network model training is completed.