A method for detecting rail bolt defects based on YOLOv8
Through the YOLOv8-based detection method, the one-dimensional convolutional neural network and the improved pyramid pooling structure are used to solve the problem of inefficiency of traditional track bolt detection methods, high-precision detection and real-time monitoring of track bolts are achieved, and the safety and reliability of railway operations are improved.
Patent Information
- Application Number
- CN202411822843.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-12
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2044-12-12
AI Technical Summary
The traditional rail bolt missing detection method is inefficient, has limited coverage, is susceptible to human factors and environmental interference, has low detection accuracy, and is highly labor and maintenance costs.
Using YOLOv8-based detection method, the data feedback from the laser sensor is analyzed through a one-dimensional convolutional neural network, and combined with the improved pyramid pooling structure and feature extraction network, high-precision detection of track bolts is achieved.
It improves detection efficiency, reduces dependence on manual inspection, realizes real-time monitoring of railway track status, promptly detects and warnings for potential problems, and improves the safety and reliability of railway operations.
Smart Images

Figure CN119273696B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of bolt defect detection, and in particular to a method for detecting rail bolt defects based on YOLOv8. Background Art
[0002] Bolt connection is a very common way of connecting workpieces and is widely used in aerospace, civil engineering, bridge engineering and other engineering fields. Compared with traditional riveting and welding connection methods, bolts have the advantages of low price, high reliability, easy installation and replacement, and strong bearing capacity. However, since bolted structures usually work under time-varying loads, the service bolts often loosen, causing insufficient preload, resulting in failure of the bolt structure, and loose bolts in key parts will directly lead to the collapse of the entire structure.
[0003] Traditional rail bolt missing detection mainly relies on manual inspection and simple mechanical or electronic detection methods. Workers check the bolt status along the rails visually and with hand tools, or use technologies such as mechanical probes, ultrasonic, magnetic induction and infrared sensors for detection. However, these methods are inefficient, have limited coverage, are easily affected by human factors and environmental interference, have low detection accuracy, and have high labor and maintenance costs. Summary of the invention
[0004] In view of the above-mentioned technical problems to be solved, the present invention provides a method for detecting rail bolt defects based on YOLOv8, which can improve detection efficiency, reduce dependence on manual detection, realize real-time monitoring of rail status, timely discover and warn of potential problems, and improve the safety and reliability of railway operations.
[0005] In order to solve the above technical problems, the technical solution proposed by the present invention is:
[0006] A method for detecting rail bolt defects based on YOLOv8, comprising the following steps:
[0007] Step S1, collecting rail bolt sample images, preprocessing the images, dividing the rail bolt sample images into three parts: a training set, a validation set and a test set, and expanding the image samples;
[0008] Step S2, input the expanded image into the improved YOLOv8 detection model; first perform multi-scale feature fusion on the input image, and obtain a multi-scale output rail bolt local feature map after fusion; then use the improved K-Means++ clustering method to cluster the object sizes in the rail bolt dataset to obtain the optimal prior frame size of the rail bolt dataset; then use the information of the prior frame to transform the center coordinates of the prediction frame using the sigmoid function based on the improved YOLOv8 detection model. x ,ty Mapped to between 0 and 1, and adding the grid unit coordinate information to obtain the final prediction box information; where t x ,t y Represents the center coordinate offset of the predicted box relative to the marked box. It improves the output of the YOLOv8 detection model. After being mapped by the sigmoid activation function, its range is limited to [0,1], representing the scaling information of the coordinate width and height of each grid unit. Finally, the loss function is used to calculate the difference between the predicted box and the real box.
[0009] As a further improvement of the above technical solution:
[0010] Preferably, in step S1, the image preprocessing process is:
[0011] S1-1, image brightness adjustment:
[0012] Adjust the brightness of the rail bolt sample image by:
[0013]
[0014] in, To adjust the track bolt image, is the original rail bolt image, is the brightness adjustment coefficient;
[0015] S1-2, image expansion processing:
[0016] The rail bolt samples after brightness adjustment are flipped 90° and 180° clockwise and counterclockwise to expand the samples;
[0017] S1-3, fuzzy processing:
[0018] The expanded image is blurred and Gaussian blur is used for the sample data. The mathematical expression of Gaussian blur is:
[0019]
[0020] in, is the standard deviation, r is the blur radius, and N is the normalization constant of the Gaussian distribution.
[0021] Preferably, the step S2 specifically includes the following contents:
[0022] S2-1, multi-scale feature fusion is performed on the input image; after the Darknet53 network output, the SPP network structure is added, and the feature map is subjected to the maximum pooling operation through three maximum pooling layers of different scales, and the multi-scale output rail bolt local feature map is fused with the input rail bolt global feature map;
[0023] S2-2, using the improved K-Means++ clustering method to cluster the object sizes in the rail bolt dataset to obtain the optimal prior box size of the rail bolt dataset;
[0024] S2-3, in the improved YOLOv8 detection model, the rail bolts are predicted; based on the improved YOLOv8 detection model, the output information includes the center offset coordinates of each prediction box ( ) and the width and height scaling values ( ), the position and size of the predicted box are obtained after decoding; the width of the prior box is used and height As a benchmark, the width and height are adjusted through exponential transformation to generate the actual size of the target ( );
[0025] S2-4, the loss function calculates the difference between the predicted box and the true box.
[0026] Preferably, the improved YOLOv8 detection model adopts a feature extraction network CSPDarknet53, adopts multi-size feature fusion, and uses logistic regression as a classification algorithm to detect the missing state of rail bolts. The feature extraction network CSPDarknet53 adjusts the size of the input feature map by adjusting the convolution step size, extracts features through the convolution kernel, and adjusts the size of the number of network channels.
[0027] Preferably, the feature extraction network CSPDarknet53 uses a residual block structure, which transmits the upper layer input X to the output through a shortcut connection, and the learning target is transformed into the difference F(X) between H(X) and X, where F(X) is the residual, and the formula is: H(X) = F(X) + X; when the accuracy of the model reaches saturation, the learning target is transformed into the learning of the identity mapping, and the result of F(X) is fitted to be close to 0.
[0028] Preferably, in S2-2, in the improved YOLOv8 detection model, the position of the rail bolt is determined by the prior frame and the output feature map; the distance data set between the data frames is divided; in the clustering process, the intersection-and-union ratio is used as the clustering basis; the intersection-and-union ratio formula is:
[0029]
[0030] Among them, A is the area of the predicted box, B is the area of the real box; A∩B represents the intersection area of the predicted box and the real box, indicating the overlapping part of the two boxes; A∪B represents the union area of the predicted box and the real box, indicating the total area covered by the two boxes;
[0031] The distance measurement between the prediction box and the sample annotation box is judged by IOU, and the formula is:
[0032]
[0033] Among them, P is the predicted prior box, G is the sample data box, and D represents the distance measure between the predicted box and the true box.
[0034] Preferably, in S2-3, the input rail bolt image is divided into S×S grid units during the prediction process, and a bounding box is predicted for each grid unit. The bounding box includes four parameters of position information (x, y, w, h). Each bounding box also includes information of confidence C of the predicted box. Each bounding box includes a set of category probabilities. In the rail bolt detection task, the dimension of the probability category is a, and the output dimension size is S×S×(b×(q+p+e)), where S is the number of grids, b is the number of prior boxes, q is the box information, p is the confidence, e is the number of object categories, and the confidence C formula is:
[0035]
[0036] in, Indicates i The grid cell j The confidence of the predicted box, is the probability of an object existing in the prediction box, Represents the intersection-over-union ratio between the predicted box and the true box;
[0037] The detection model based on YOLOv8 outputs prediction box information, including the center offset coordinates of each prediction box ( ), width and height scaling values ( ); The prediction box calculation process is as follows:
[0038]
[0039] in,( ) is the coordinate information of the corresponding grid unit in the entire image, ( ) is the center coordinate of the prediction box, ( ) is the size information of the model prediction box, , is the width and height of the prior box.
[0040] Preferably, the loss function in S2-4 consists of three parts: the loss of track bolt prediction frame coordinate information, the loss of target frame confidence, and the loss of track bolt classification;
[0041] The overall loss function calculation formula is:
[0042]
[0043] in, The prediction box coordinate information loss for the rail bolts, is the target box confidence loss, It is the rail bolt classification loss.
[0044] Preferably, the rail bolt prediction frame coordinate information loss Calculated by the formula:
[0045]
[0046] in, It is a coordinate loss function that measures the difference between the predicted box and the true box in terms of center position and size;
[0047] is a weight parameter used to balance the proportion of coordinate loss in the total loss, and is usually used to improve the accuracy of position prediction; 3 represents the three bounding boxes predicted by each grid cell; k is the size parameter of the grid, indicating the number of grid cells per row and column, indicating that the image is divided into k*k grid cells;
[0048] is an indicator variable, which takes the value of 1 when the j-th prior box of the i-th grid cell is responsible for predicting a target, otherwise it takes the value of 0;
[0049] , Represent the width and height of the real box respectively; ( , ) is the center coordinate of the real frame; ( ) is the center coordinate of the prediction box;
[0050] are the width and height of the prediction box respectively.
[0051] Preferably, the target box confidence loss Calculated by the following formula:
[0052]
[0053] Among them, 3 represents the 3 bounding boxes predicted by each grid cell;
[0054] k is the size parameter of the grid, which indicates the number of grid cells in each row and column, indicating that the image is divided into k*k grid cells;
[0055] is an indicator variable, which has a value of 1 when the j-th prediction box of the i-th grid cell contains the target, and 0 otherwise;
[0056] is an indicator variable, which has a value of 1 when the j-th prediction box of the i-th grid cell does not contain the target, and 0 otherwise;
[0057] is the prediction confidence of the jth prediction box of the i-th grid unit;
[0058] is the true confidence of the jth predicted box of the i-th grid unit, indicating whether the true box exists;
[0059] It is a weight parameter used to control the impact of the loss of the prediction box without the target on the total loss, and is usually used to reduce excessive attention to the background area.
[0060] Preferably, the rail bolt classification loss Calculated by the following formula:
[0061]
[0062] in, Indicates the first i The grid j Whether the prediction box detects rail bolts, its value is 1 when it is responsible for rail bolt detection, otherwise it is 0; represents the target category set, which in this formula refers to all possible categories; Represents a category, c belongs to a category in the category set; Represents the probability prediction value of the i-th prediction box belonging to category c; represents the true probability that the i-th prediction box belongs to category c, provided by the labeled data; if the box belongs to category c, then , otherwise 0.
[0063] Compared with the prior art, the method for detecting rail bolt defects based on YOLOv8 provided by the present invention has the following advantages:
[0064] (1) The method for detecting rail bolt defects based on YOLOv8 of the present invention analyzes the data fed back by the laser sensor through a one-dimensional convolutional neural network, effectively addresses the problems of nut height difference and data jump, and realizes high-precision detection of rail bolts, especially in the identification of linear areas and abnormal areas, with higher accuracy.
[0065] (2) The method for detecting rail bolt defects based on YOLOv8 of the present invention, YOLOv8 combined with an improved pyramid pooling structure and a feature extraction network, can adapt to complex construction environments and the influence of bulk rail bolts, ensuring that the rail bolts and the status of the bolts can still be accurately detected under conditions of large noise interference, and has strong adaptability to complex environments.
[0066] (3) The method for detecting rail bolt defects based on YOLOv8 of the present invention, combined with a convolutional neural network, can process the feedback distance data in real time, realize rapid positioning of the bolt area, reduce the dependence on traditional manual detection, and improve the detection efficiency.
[0067] (4) The method for detecting rail bolt defects based on YOLOv8 of the present invention combines geometric information with the image features detected by YOLOv8 to form a detection mechanism of multi-source information fusion, which can not only determine the bolt position, but also record the bolt defect situation, thereby improving the overall robustness of the system.
[0068] (5) The YOLOv8-based method for detecting rail bolt defects of the present invention uses the Adam optimization algorithm with a dynamic learning rate and a random deactivation strategy to improve the convergence speed and generalization ability of the model during the training process, and further enhances the adaptability to complex data scenarios.
[0069] (6) In the method for detecting rail bolt defects based on YOLOv8 of the present invention, the diversity of the sample set is expanded through data enhancement methods such as image brightness adjustment, blur processing and rotation in data preprocessing, so that the YOLOv8 model has higher stability and accuracy when detecting rail bolts. BRIEF DESCRIPTION OF THE DRAWINGS
[0070] Figure 1 It is a residual block structure diagram of the present invention.
[0071] Figure 2 It is a flow chart of the SPP structure of the present invention performing convolution operation on the input feature map and outputting it.
[0072] Figure 3 It is a work flow chart of the present invention. DETAILED DESCRIPTION
[0073] The specific embodiments of the present invention are described in detail below. It should be understood that the specific embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.
[0074] like Figure 3 As shown, the method for detecting rail bolt defects based on YOLOv8 of the present invention comprises the following steps:
[0075] Step S1, image preprocessing:
[0076] The rail bolt sample images are divided into three parts: training set, validation set and test set, and the image samples are expanded in the following way.
[0077] S1-1, image brightness adjustment:
[0078] Adjust the brightness of the rail bolt sample image by:
[0079]
[0080] in, To adjust the track bolt image, is the original rail bolt image, is the brightness adjustment factor.
[0081] S1-2, image expansion processing:
[0082] The rail bolt samples after brightness adjustment are flipped 90° and 180° clockwise and counterclockwise to achieve sample expansion.
[0083] S1-3, fuzzy processing:
[0084] The expanded image is blurred and Gaussian blur is used for the sample data. The mathematical expression of Gaussian blur is:
[0085]
[0086] in, is the standard deviation, r is the blur radius, and N is the normalization constant of the Gaussian distribution, which ensures that the sum of the Gaussian functions is 1, so that the brightness of the image remains unchanged and no information is lost due to blurring.
[0087] In fact, in the obtained rail bolt sample images, since they are images of a section of rails shot continuously, there may be cases where there are no rail bolts in the images, so it is necessary to remove the image data without rail bolts first.
[0088] In the process from the rail to the track bolt, the distance will continue to shorten. This segment of data is also the positioning segment data of the track bolt. Therefore, the complete length sample data within a fixed time is used as the input of the convolutional neural network to determine whether there is a bolt in this interval.
[0089] Furthermore, the convolutional neural network adopts a one-dimensional convolutional neural network, which judges the distance information fed back by the input rail bolts through a combination of multiple convolutional layers and pooling layers, a fully connected layer and an output layer, and infers whether there are rail bolts in the input data, thereby realizing the detection of whether the rail bolts exist.
[0090] Furthermore, the fully connected layer of the one-dimensional convolutional neural network is the last layer of the model, which is used to output the SoftMax layer of the classification probability of the data samples. The ones with higher probabilities are the model predictions.
[0091] The specific expression of the SoftMax function is shown in the following formula:
[0092]
[0093] In the formula, is the predicted probability, which represents the classification probability vector predicted by the model. Its size is 1*2, which means it contains the probability values of two classifications. 2 means that the model performs a binary classification task.
[0094] Represents the i-th classification score input to the SoftMax function, which is used to calculate the probability of the corresponding category;
[0095] Express Perform exponential operation, which is a step in the SoftMax function to increase the weight of larger scores and then calculate the classification probability;
[0096] It represents the summation operation after exponential operation of all input scores. The purpose of this step is to standardize all classification scores into a probability distribution, that is, the sum of the probabilities of all categories is 1.
[0097] The one-dimensional convolutional neural network uses the loss function to evaluate the difference between the predicted data results and the real data labels, providing an intuitive data basis for back propagation and the optimal network model. The loss function in this model is measured by the following formula:
[0098]
[0099] In the formula, f is the batch size of the dataset, y The output layer outputs a feature vector of 2, indicating the probability of the presence of rail bolts. is a binary variable indicating the presence or absence of rail bolts.
[0100] Whether there are rail bolts is a binary classification task. i =1, indicating that the category is the presence of rail bolts; when i =2 means the category is no rail bolts. For each sample, there is only one is 1, and the rest are 0.
[0101] During the back-propagation process, the previous gradient descent method updates the independent variable along the current gradient according to the current position of the independent variable. The whole process maintains a single learning rate to update the weight. The model adopts the Adam optimization method with dynamic learning rate, and a random inactivation strategy is adopted during the training process.
[0102] For example, the input feedback distance sample length of the one-dimensional convolutional neural network is 40, the convolution kernel size in the model is 1×7, and the same padding scheme is uniformly adopted. The number of convolution kernels in the first layer is 5, and the size of the first convolution output feature map is 5×1×40. After the maximum pooling layer, the output feature map size is 5×1×20. The number of convolution kernels in the second layer is 10, and the size of the second convolution output feature map is 10×1×20. After the maximum pooling, the output feature map dimension is 10×1×10. After the maximum pooling, the output feature map dimension of the third layer is 20×1×5. The output size of the fully connected layer 1 is 1×100, and the output size of the fully connected layer 2 is 1×50. The final output layer outputs the prediction result, and the output size is 2×1.
[0103] Step S2: perform rail bolt defect detection
[0104] According to the image processed in step S1, the image is input into the improved YOLOv8 detection model; first, multi-scale feature fusion is performed on the input image, and a multi-scale output rail bolt local feature map is obtained after fusion; then, the object sizes in the rail bolt dataset are clustered using the improved K-Means++ clustering method to obtain the optimal prior frame size of the rail bolt dataset; then, the information of the prior frame is used to transform the center coordinates of the prediction frame using the sigmoid function based on the improved YOLOv8 detection model. Map it to between 0 and 1, and add the grid unit coordinate information to obtain the final predicted box information; finally, use the loss function to calculate the difference between the predicted box and the true box.
[0105] In this embodiment, compared with the traditional YOLOv8 detection model, the improved YOLOv8 detection model adopts the feature extraction network CSPDarknet53, adopts multi-size feature fusion, and uses logistic regression as the classification algorithm to detect the missing of rail bolts. It optimizes the accuracy of target detection while taking into account real-time performance, and the accuracy and detection speed are greatly improved.
[0106] The feature extraction network CSPDarknet53 does not use the pooling layer to adjust the size of the feature map. Instead, it adjusts the size of the input feature map by adjusting the convolution step size. The model uses convolution layers to adjust the size of the feature map, and uses a large number of convolution kernels to achieve feature extraction and adjust the size of the number of network channels.
[0107] The feature extraction network CSPDarknet53 uses a residual block structure. The residual block structure transmits the upper layer input X to the output through shortcut connections. At the same time, the learning target is transformed into the difference F(X) between H(X) and X. F(X) is the residual, and the formula is: H(X) = F(X) + X; the residual block structure is as follows Figure 1 When the accuracy of the model reaches saturation, in order to ensure that the subsequent network layers will not affect the prediction accuracy of the model, the learning goal is to learn the identity mapping, that is, to fit the result of F(X) as close to 0 as possible.
[0108] The specific steps include:
[0109] S2-1, perform multi-scale feature fusion on the input image.
[0110] In this embodiment, the Darknet53 network layer is improved to extract deeper semantics of rail bolt detection features and realize multi-scale feature prediction. Since the size difference between the rail nut and the rail bolt as a whole is large in the input rail bolt image, after the Darknet53 network output, the Spatital Pyrmid Pooling (SPP) method is referenced to increase the SPP network structure and strengthen the network feature performance. Figure 2 As shown, the added SPP structure first performs a convolution operation on the input feature map.
[0111] The SPPF model has a smaller amount of calculation and faster operation speed, which can solve the problem of non-uniform input image size. The SPPF module extracts features at different scales through the maximum pooling operation. Specifically, it has four parallel branches:
[0112] The first branch: directly passes the input features to the output without any operation.
[0113] The second branch: perform a maximum pooling operation with a kernel size of 5×5 and obtain medium-scale features through downsampling.
[0114] The third branch: Use the maximum pooling operation with a kernel size of 9×9 to further extract larger-scale features.
[0115] The fourth branch: Use the maximum pooling operation with a kernel size of 13×13 to extract features of a larger scale.
[0116] The stride of all pooling operations is 1, which means that padding is performed during convolution operations to keep the feature map size unchanged. Finally, the feature maps of the four branches are concatenated to complete the fusion of features of different scales. This structure achieves efficient multi-scale information integration, which helps capture objects of different sizes in object detection tasks.
[0117] The feature map is subjected to maximum pooling operation through three maximum pooling layers of different scales to achieve the fusion of local and global features of the input rail bolt feature map.
[0118] The multi-scale output local feature map of rail bolts is fused with the input global feature map of rail bolts to enrich the expression ability of the feature map.
[0119] S2-2, the object sizes in the rail bolt dataset are clustered using the improved K-Means++ clustering method to obtain the optimal prior box size of the rail bolt dataset.
[0120] In the YOLOv8 detection model, the position of the rail bolts is confirmed by the prior frame and the output feature map. YOLOv8 uses K-Means clustering to classify the data frames in the data set. The classification is based on the distance between the data frames, which is a judgment indicator to divide the data set into K clusters; clustering is to achieve the maximum similarity between the prediction frames of different sizes and the real frames, that is, there must be a larger intersection-over-union (IOU) between the prediction frame and the real frame. In the YOLOv8 clustering process, the intersection-over-union ratio is used as the basis for clustering. The specific formula of the intersection-over-union ratio is as follows:
[0121]
[0122] Among them, A is the area of the predicted box, B is the area of the real box; A∩B represents the intersection area of the predicted box and the real box, which represents the overlapping part of the two boxes. A∪B represents the union area of the predicted box and the real box, which represents the total area covered by the two boxes.
[0123] The distance measurement between the prediction box and the sample annotation box can be judged by IOU. Intuitively, the larger the IOU, the more similar the prediction box is to the true box, and the more likely it is to be in the same cluster. Therefore, the IOU indicator is included in the distance measurement between the sample box and the prediction box. The specific formula is as follows:
[0124]
[0125] Among them, P is the predicted prior box, G is the sample data box, and D is the distance metric between the predicted box and the true box. It can be seen that the larger the IOU, the smaller the distance metric between the sample box and the predicted box.
[0126] Among them, the prior box is the initial box of the network, which is a fixed or limited number of boxes and is used to provide a preliminary positioning reference. The predicted prior box is the result of adjusting the prior box and is the transition product from the prior box to the predicted box. The predicted box is the result of the final model output, reflecting the prediction of the target position and size.
[0127] In this embodiment, the YOLOv8 detection model uses an improved K-Means++ clustering method to cluster the object sizes in the rail bolt dataset to obtain the optimal prior box size of the rail bolt dataset.
[0128] Compared with traditional K-Means clustering, the improved K-Means++ optimizes the selection of initial cluster centers, making the algorithm more stable and the results better. The steps to use the improved K-Means++ are as follows:
[0129] (1) Randomly select an initial box as the first prior box.
[0130] (2) Calculate the closest distance between each data frame and the current prior frame
[0131] (3) Determine the probability of each box being selected as the next prior box based on the squared distance ratio.
[0132] (4) Repeat this process until k prior boxes are selected.
[0133] Specifically, the IOU distance metric (D = 1 - IOU) is used instead of the Euclidean distance to make the clustering results more in line with the requirements of the target detection task.
[0134] Ensure that boxes of different sizes can be more accurately assigned to different clusters.
[0135] In this embodiment, the process of generating the cluster center of the rail bolt samples is as follows:
[0136] S2-2-1, randomly select a sample from the rail bolt samples as one of the initial prior boxes;
[0137] S2-2-2, calculating the shortest distance between each rail bolt sample and the selected initial prior frame;
[0138] S2-2-3, calculate the probability of each rail bolt sample point being selected as the prior frame, the greater the probability, the greater the chance of becoming the next initial prior frame;
[0139] S2-2-4, repeat S2-2-2 and S2-2-3 until k initial prior frames are determined, and the prior frame size of the rail bolt sample data is obtained through the K-Means++ clustering algorithm.
[0140] S2-3, predicting rail bolts in the YOLOv8 detection model.
[0141] In the YOLOv8 detection model, the input rail bolt image is divided into S× S grid cells during the prediction process. Each grid cell will predict a bounding box, which includes four parameters: position information (x, y, w, h). Each bounding box also contains information about the confidence C of the predicted box. Each bounding box includes a set of category probabilities. In the rail bolt detection task, rail bolts and nuts are predicted. The dimension of the probability category is a, so the output dimension size is S× S×(b×(q+p+e)). Among them, S is the number of grids, b is the number of prior boxes, q is the box information, p is the target confidence, e is the number of object categories, and the formula for the predicted box confidence C is as follows:
[0142]
[0143] in, Indicates i The grid cell j The confidence of the predicted box, is the probability of an object existing in the prediction box, represents the intersection-over-union ratio between the predicted box and the true box. p is the confidence that the target object exists in the predicted box.
[0144] C adds IOU, focusing on the size of the target within the prediction box, reflecting the accuracy of the predicted object position.
[0145] The YOLOv8-based rail bolt detection model finally outputs the prediction box information, including the center offset coordinates of each prediction box ( ), width and height scaling values ( ). The prediction box calculation process is as follows:
[0146]
[0147] in,( ) is the coordinate information of the corresponding grid unit in the entire image, ( ) is the center coordinate of the prediction box, ( ) is the size information of the model prediction box, , is the width and height of the prior box.
[0148] Based on the improved YOLOv8 rail bolt detection model, the model finally outputs the information including the center offset coordinates of each prediction box ( ) and the width and height scaling values ( ), the specific position and size of the prediction box are obtained after decoding. The calculation process of the prediction box is closely related to the size of the prior box. and height As a benchmark, the width and height are adjusted through exponential transformation to generate the actual size of the target ( ). In the process of predicting the center coordinates, the model first uses the Sigmoid function to convert the center offset value ( ) is mapped to the range of 000 to 111, which represents the offset ratio relative to the current grid cell. This offset ratio is then superimposed on the coordinates of the upper left corner of the grid cell. , thereby obtaining the center coordinates of the prediction box ( ). Combined with the calculation, the final prediction box information includes the center coordinates ( ) and width and height ( ) to achieve accurate positioning and size prediction of the target.
[0149] S2-4, loss function:
[0150] The loss function in the YOLOv8 detection model consists of three parts: the loss of the rail bolt prediction box coordinate information, the target box confidence loss, and the rail bolt classification loss.
[0151] The overall loss function calculation formula is as follows:
[0152]
[0153] in, The prediction box coordinate information loss for the rail bolts, is the target box confidence loss, It is the rail bolt classification loss.
[0154] Loss of coordinate information of rail bolt prediction frame Calculated by the following formula:
[0155]
[0156] in, It is a coordinate loss function that measures the difference between the predicted box and the true box in terms of center position and size;
[0157] is a weight parameter used to balance the proportion of coordinate loss in the total loss, and is usually used to improve the accuracy of position prediction;
[0158] 3 represents the three bounding boxes predicted for each grid cell; k is the size parameter of the grid, which represents the number of grid cells per row and column, indicating that the image is divided into k*k grid cells;
[0159] is an indicator variable, which takes the value of 1 when the j-th prior box of the i-th grid cell is responsible for predicting a target, otherwise it takes the value of 0;
[0160] , Represent the width and height of the real box respectively; ( , ) is the center coordinate of the real frame; ( ) is the center coordinate of the prediction box;
[0161] are the width and height of the prediction box respectively.
[0162] Object box confidence loss Calculated by the following formula:
[0163]
[0164] Among them, 3 represents the 3 bounding boxes predicted by each grid cell;
[0165] k is the size parameter of the grid, which indicates the number of grid cells in each row and column, indicating that the image is divided into k*k grid cells;
[0166] is an indicator variable, which has a value of 1 when the j-th prediction box of the i-th grid cell contains the target, and 0 otherwise;
[0167] is an indicator variable, which has a value of 1 when the j-th prediction box of the i-th grid cell does not contain the target, and 0 otherwise;
[0168] is the prediction confidence of the jth prediction box of the i-th grid unit;
[0169] is the true confidence of the jth predicted box of the i-th grid unit, indicating whether the true box exists;
[0170] It is a weight parameter used to control the impact of the loss of the prediction box without the target on the total loss, and is usually used to reduce excessive attention to the background area.
[0171] Rail bolt classification loss Calculated by the following formula:
[0172]
[0173] in, Indicates the first i The grid j Whether the prediction box detects rail bolts, its value is 1 when it is responsible for rail bolt detection, otherwise it is 0; represents the target category set, which in this formula refers to all possible categories; Represents a category, c belongs to a category in the category set; Represents the probability prediction value of the i-th prediction box belonging to category c; represents the true probability that the i-th prediction box belongs to category c, provided by the labeled data; if the box belongs to category c, then , otherwise 0.
[0174] Overall, It is used to calculate the coordinate difference between the predicted box and the real box. The mean square error (MSE) or squared difference loss is usually used to measure the predicted center coordinates ( ) and frame size ( ) is the deviation from the true box.
[0175] It is the confidence loss, usually calculated by cross entropy loss, which measures whether the predicted box contains the object. For boxes containing the target, the error between the predicted confidence and the true confidence is calculated. For boxes that do not contain the target, the loss function helps reduce the misjudgment of background areas.
[0176] It is the classification loss, usually cross entropy loss, which is used to calculate the difference between the predicted probability of the target category and the true category label.
[0177] The above implementation cases are only preferred embodiments of the present invention and are not intended to limit the present invention in any form. Although the present invention has been disclosed as above with preferred embodiments, they are not intended to limit the present invention. Therefore, any simple modification, equivalent changes and modifications made to the above embodiments according to the technical essence of the present invention without departing from the content of the technical solution of the present invention shall fall within the scope of protection of the technical solution of the present invention.
Claims
1. A method for detecting rail bolt defects based on YOLOv8, characterized in that: The steps include: Step S1, collecting rail bolt sample images, preprocessing the images, dividing the rail bolt sample images into three parts: a training set, a validation set and a test set, and expanding the image samples; Step S2, input the expanded image into the improved YOLOv8 detection model; first perform multi-scale feature fusion on the input image, and obtain a multi-scale output rail bolt local feature map after fusion; then use the improved K-Means++ clustering method to cluster the object sizes in the rail bolt dataset to obtain the optimal prior frame size of the rail bolt dataset; then use the information of the prior frame to transform the center coordinates of the prediction frame based on the improved YOLOv8 detection model using the sigmoid function Mapped to between 0 and 1, and adding the grid unit coordinate information to obtain the final prediction box information; where, Represents the center coordinate offset of the predicted box relative to the marked box; finally, the loss function is used to calculate the difference between the predicted box and the true box; The step S2 specifically includes the following contents: S2-1, multi-scale feature fusion is performed on the input image; after the Darknet53 network output, the SPP network structure is added, and the feature map is subjected to the maximum pooling operation through three maximum pooling layers of different scales, and the multi-scale output rail bolt local feature map is fused with the input rail bolt global feature map; S2-2, using the improved K-Means++ clustering method to cluster the object sizes in the rail bolt dataset, and obtain the optimal prior box size of the rail bolt dataset; S2-3, in the improved YOLOv8 detection model, the rail bolts are predicted; based on the improved YOLOv8 detection model, the output information includes the center offset coordinates of each prediction box ( ) and the aspect ratio ( ), the position and size of the predicted box are obtained after decoding; the width of the prior box is used and height As a benchmark, the width and height are adjusted through exponential transformation to generate the actual size of the target ( ); S2-4, the loss function calculates the difference between the predicted box and the true box; The improved YOLOv8 detection model adopts a feature extraction network CSPDarknet53, adopts multi-size feature fusion, and uses logistic regression as a classification algorithm to detect the missing of rail bolts. The feature extraction network CSPDarknet53 adjusts the size of the input feature map by adjusting the convolution step size, extracts features through the convolution kernel and adjusts the size of the number of network channels; the feature extraction network CSPDarknet53 uses a residual block structure, which transmits the upper layer input X to the output through a shortcut connection, and at the same time, the learning target is transformed into the difference F(X) between H(X) and X, where F(X) is the residual, and the formula is expressed as: H(X) = F(X) + X; when the accuracy of the model reaches saturation, the learning target is transformed into the learning of the identity mapping, and the result of F(X) is fitted to be close to 0.
2. The method for detecting rail bolt defects based on YOLOv8 according to claim 1, characterized in that: In step S1, the image preprocessing process is: S1-1, image brightness adjustment: Adjust the brightness of the rail bolt sample image by: ; in, To adjust the rear track bolt image, Original track bolt image, is the brightness adjustment coefficient; S1-2, image expansion processing: The rail bolt samples after brightness adjustment are flipped 90° and 180° clockwise and counterclockwise to expand the samples; S1-3, fuzzy processing: The expanded image is blurred and Gaussian blur is used for the sample data. The mathematical expression of Gaussian blur is: ; in, is the standard deviation, r is the blur radius, and N is the normalization constant of the Gaussian distribution.
3. The method for detecting rail bolt defects based on YOLOv8 according to claim 1, characterized in that: In S2-2, in the improved YOLOv8 detection model, the position of the rail bolt is determined by the prior frame and the output feature map; the distance data set between the data frames is divided; in the clustering process, the intersection-and-union ratio is used as the clustering basis; the intersection-and-union ratio formula is: ; Among them, A is the area of the predicted box, B is the area of the real box; A∩B represents the intersection area of the predicted box and the real box, indicating the overlapping part of the two boxes; A∪B represents the union area of the predicted box and the real box, indicating the total area covered by the two boxes; The distance measurement between the prediction box and the sample annotation box is judged by IOU, and the formula is: ; Among them, P is the predicted prior box, G is the sample data box, and D represents the distance measure between the predicted box and the true box.
4. The method for detecting rail bolt defects based on YOLOv8 according to claim 1, characterized in that: In S2-3, the input rail bolt image is divided into S×S grid units during the prediction process. Each grid unit predicts a bounding box, which includes four parameters of position information (x, y, w, h). Each bounding box also contains information about the confidence C of the predicted box. Each bounding box includes a set of category probabilities. In the rail bolt detection task, the dimension of the probability category is a, and the output dimension size is S×S×(b×(q+p+e)), where S is the number of grids, b is the number of prior boxes, q is the box information, p is the confidence, e is the number of object categories, and the confidence C formula is: ; in, Indicates i The grid cell j The confidence of the predicted box, is the probability of an object existing in the prediction box, Represents the intersection-over-union ratio between the predicted box and the true box; The detection model based on YOLOv8 outputs prediction box information, including the center offset coordinates of each prediction box ( ), width and height scaling values ( ); The prediction box calculation process is as follows: ; in,( ) is the coordinate information of the corresponding grid unit in the entire image, ( ) is the center coordinate of the prediction box, ( ) is the size information of the model prediction box, , is the width and height of the prior box.
5. The method for detecting rail bolt defects based on YOLOv8 according to claim 1, characterized in that: The loss function in S2-4 is composed of three parts: the loss of track bolt prediction frame coordinate information, the loss of target frame confidence, and the loss of track bolt classification; The overall loss function calculation formula is: ; in, The prediction box coordinate information loss for the rail bolts, is the target box confidence loss, It is the rail bolt classification loss.
6. The method for detecting rail bolt defects based on YOLOv8 according to claim 5, characterized in that: The rail bolt prediction frame coordinate information loss Calculated by the formula: ; in, It is a coordinate loss function that measures the difference between the predicted box and the true box in terms of center position and size; is a weight parameter used to balance the proportion of coordinate loss in the total loss and to improve the accuracy of position prediction; 3 indicates that each grid cell predicts three bounding boxes; k is the size parameter of the grid, indicating the number of grid cells in each row and column, indicating that the image is divided into k*k grid cells; is an indicator variable, which takes the value of 1 when the j-th prior box of the i-th grid cell is responsible for predicting a target, otherwise it takes the value of 0; , Represent the width and height of the real box respectively; ( , ) is the center coordinate of the real frame; is the center coordinate of the prediction box; are the width and height of the prediction box respectively.
7. The method for detecting rail bolt defects based on YOLOv8 according to claim 5, characterized in that: The target box confidence loss Calculated by the following formula: ; Among them, 3 represents the 3 bounding boxes predicted by each grid cell; k is the size parameter of the grid, which indicates the number of grid cells in each row and column, indicating that the image is divided into k*k grid cells; is an indicator variable, which has a value of 1 when the j-th prediction box of the i-th grid cell contains the target, and 0 otherwise; is an indicator variable, which has a value of 1 when the j-th prediction box of the i-th grid cell does not contain the target, and 0 otherwise; is the prediction confidence of the jth prediction box of the i-th grid unit; is the true confidence of the jth predicted box of the i-th grid unit, indicating whether the true box exists; is a weight parameter used to control the impact of the loss of the prediction box without the target on the total loss.
8. The method for detecting rail bolt defects based on YOLOv8 according to claim 5, characterized in that: The rail bolt classification loss Calculated by the following formula: ; in, Indicates the first i The grid j Whether the prediction box detects rail bolts, its value is 1 when it is responsible for rail bolt detection, otherwise it is 0; represents the target category set, which in this formula refers to all possible categories; Represents a category, c belongs to a category in the category set; Represents the probability prediction value of the i-th prediction box belonging to category c; represents the true probability that the i-th prediction box belongs to category c, provided by the labeled data; if the box belongs to category c, then , otherwise 0.
Citation Information
Patent Citations
Railway track defect detection method and system based on improved YOLOv5s algorithm
CN118115476A
Track bolt floating detection method and system based on 2D-3D structured light
CN118212200A