Track disease detection method based on improved YOLOv8 algorithm

By improving the YOLOv8 algorithm, combined with the anchor point fusion network, adaptive global modulation pyramid and channel self-attention mechanism, the problem of insufficient performance of track disease detection in complex scenes is solved, and detection results with high accuracy and robustness are achieved.

CN118865341APending Publication Date: 2024-10-29XIAN UNIV OF TECH
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410922842.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-10
Publication Date
2024-10-29

AI Technical Summary

Technical Problem

Existing track disease detection methods have insufficient detection performance under complex scenes and degraded conditions, making it difficult to meet the needs of practical applications.

Method used

The improved YOLOv8 algorithm is used to construct the anchor point fusion network module, adaptive global modulation pyramid module and channel self-attention mechanism module to improve the detection performance and adaptability of the model.

Benefits of technology

It significantly improves the accuracy and robustness of track disease detection, ensures efficient operation under complex environmental conditions, and enhances the model's ability to identify diverse track defect types.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118865341A_ABST
    Figure CN118865341A_ABST
Patent Text Reader

Abstract

The invention discloses an orbital disease detection method based on an improved YOLOv8 algorithm. The orbital disease detection method is specifically implemented according to the following steps: step 1, constructing a data set and an encoder; step 2, constructing an anchor point fusion network module; step 3, constructing a self-adaptive global modulation pyramid module; and step 4, constructing a channel self-attention mechanism module. The anchor point fusion network module, the self-adaptive global modulation pyramid module and the channel self-attention mechanism module are introduced, the comprehensive performance of the model is greatly improved, the detection precision is high, the detection speed is high, the robustness is good, and track disease detection requirements under complex scenes and degradation conditions can be effectively met.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of computer vision and image detection methods, and in particular relates to a track defect detection method based on an improved YOLOv8 algorithm. Background Art

[0002] Track surface defects include corrosion, cracks, falling off and pits, while track structural defects involve missing track fasteners, deformation of fasteners and other problems. If these defects are not detected and treated in time, they will have a serious impact on the safety and operation efficiency of the railway system. Track structural defect detection refers to the use of various technical means to identify and detect various defects in the railway track structure to ensure the safety and smooth operation of the railway system.

[0003] Traditional rail defect detection methods mainly rely on manual inspections and hand-designed features to detect defects. For example, defects are identified by features such as color, shape, and texture. However, these methods usually rely on manually extracted features, which can solve the problem of defect detection in simple cases, but in complex scenarios, the detection performance drops sharply and cannot meet actual needs.

[0004] With the development of deep learning technology, rail defect detection methods based on deep learning have been widely studied. These methods learn feature representation from a large amount of data through technologies such as convolutional neural networks, adaptively extract features that are effective for defect detection, and have higher detection accuracy compared to traditional methods. However, even the most advanced rail defect detection methods based on deep learning still have insufficient detection performance in various complex scenarios and degraded conditions, such as complex backgrounds, the size of defective targets, and different lighting conditions, making it difficult to meet the needs of practical applications. Summary of the invention

[0005] The purpose of the present invention is to provide a method based on improved YOLO v The track defect detection method based on 8 algorithms can accurately detect track defects in complex scenarios and degraded conditions.

[0006] The technical solution adopted by the present invention is based on improving YOLO v The track defect detection method based on the 8-algorithm is implemented in the following steps:

[0007] Step 1: Build the dataset and encoder;

[0008] Step 2, constructing an anchor fusion network module;

[0009] Step 3, construct an adaptive global modulation pyramid module;

[0010] Step 4: Build a channel self-attention mechanism module.

[0011] The present invention is also characterized in that:

[0012] Step 1 is implemented as follows:

[0013] Step 1.1, collect sample images of track defects;

[0014] Step 1.2, annotate and classify the sample images collected in step 1.1, determine the location and bounding box of the disease, and assign corresponding labels to each disease category.

[0015] Step 1.3, divide all sample images and their annotated files into training set, validation set and test set in proportion.

[0016] Step 1.4, use improved YOLO v 8 models, load pre-trained weights, and build encoders;

[0017] In step 1.5, the dataset image resolution is adjusted to 640×640 and input into the encoder.

[0018] Step 2 is implemented as follows:

[0019] Step 2.1, based on the convolution and cutting functions, construct a feature channel segmentation module;

[0020] Step 2.2, build the anchor attention module;

[0021] Step 2.3, build the network fusion module.

[0022] Step 2.1 is implemented as follows:

[0023] Step 2.1.1, assuming an input tensor f with size B×N×C, divide the tensor evenly into two equal parts along the channel dimension by using the cutting function, the dimension of each part will be The premise is that C is divisible by 2. If C is an odd number, then the sizes of the two parts will be and To ensure that all channels are included, assuming that the split tensor is V, the calculation formula is shown in formula (1):

[0024] V = f.chunk(2, 1)(1)

[0025] Where, V array is the result after cutting, f is the input tensor, chunk(2,1) is the cutting function, 2 in the cutting function means cutting into two parts, and 1 means cutting along the channel latitude;

[0026] Step 2.1.2, take the tensor obtained in step 2.1.1 as input, and guide it through the convolution layer with n×n convolution kernel and stride 1, and obtain two new tensors, denoted as y[0] and y[1], which provide feature representation for further processing of the network. The calculation formula is shown as follows:

[0027] y[0]=C v1 (V1) (2)

[0028] y[1]=C v1 (V2) (3)

[0029] In the formula, y[0], y[1] are the outputs after cutting and convolution, C v1 (V1), C v1 (V2) is the convolution operation, V1 and V2 are the outputs of step 2.1.1.

[0030] Step 2.2 is implemented in series through pooling, convolution and activation function operations, which are implemented in the following steps:

[0031] Step 2.2.1, construct average pooling, the convolution kernel is 1×1 convolution operation, and the calculation formula is shown in formula (4):

[0032]

[0033] In the formula, To get the result after flat pooling and convolution, Conv 1×1 () is the convolution operation, P avg () is average pooling, y[1] is the output of step 2.1.2;

[0034] Step 2.2.2, construct horizontal convolutional layer and vertical convolutional layer. The convolution kernel of horizontal convolutional layer is 11 in horizontal direction and 1 in vertical direction. The convolution kernel of vertical convolutional layer is 1 in horizontal direction and 11 in vertical direction. The calculation formula is as follows:

[0035]

[0036] f h =h_conv h×1 (f w ) (6)

[0037] Where w_conv 1×v () is the horizontal convolution with a convolution kernel of 1×11, h_conv h×1 () is a vertical convolution with a convolution kernel of 11×1, f w is the result of horizontal convolution, f h is the result of vertical convolution;

[0038] Step 2.2.3, construct activation function and convolution operation to generate dynamic attention weights to strengthen the key areas in the image. The calculation formula is shown in formula (7):

[0039] f ca =Sigmoid(Conv(f h )) (7)

[0040] In the formula, Sigmoid is the activation function, Conv() is the convolution with a convolution kernel of 1×1, and f ca To generate dynamic attention weights;

[0041] In step 2.3, the output y[0] obtained by the segmentation in step 2.1.2 is reintegrated with y[1] after being processed by the anchor attention module in step 2.2. The specific implementation is as follows:

[0042] Step 2.3.1, construct anchor feature sequence E n , n∈{1, 2, 3..n}, the segmentation output y[0] of step 2.1.2, after the anchor feature sequence E n , and obtain high-level feature representation, and gradually refine these features through repeated application. The calculation formula is shown in formula (8):

[0043]

[0044] Where Ca() is the anchor attention module, For the sum operation, E n is the obtained anchor feature sequence;

[0045] Step 2.3.2, build a fusion module, fuse the output of step 2.3.1 with the output y[1] obtained by segmentation in step 2.1.2 in the channel dimension, and then use a 1×1 convolution operation to adjust the feature map to ensure that it is more efficient in the spatial dimension. The calculation formula is shown in formula (9):

[0046] f out =Conv 1×1 (Cat(y[1],E n )) (9)

[0047] In the formula, Cat() is the Concatenate link function, and the features are concatenated in the channel dimension.

[0048] Step 3 is implemented as follows:

[0049] Step 3.1, construct an adaptive global modulation module;

[0050] Step 3.2: construct a multi-scale feature pyramid fusion module to pool and fuse the features of receptive fields of different sizes.

[0051] Step 3.1 is implemented as follows:

[0052] Step 3.1.1, guide the fusion between corresponding pixels through non-local inter-group modulation to reduce the semantic difference between cross-scale features;

[0053] Step 3.1.2, the connection between local features and global context is enhanced through the context aggregation module to improve the network's ability to understand features.

[0054] Step 3.1.1 is implemented as follows:

[0055] Step 3.1.1.1, input feature C i , the background information of the extracted features and the target texture information of the features are obtained through average pooling Pavg and maximum pooling Pmax in the channel dimension, and then further spliced ​​to obtain the required spatial feature distribution map. The calculation formula is shown in formula (10):

[0056] C1=Cat(Pmax(C i ), Pavg(C i )) (10)

[0057] In the formula, Cat() is the Concatenate link function, Pavg() is the average pooling operation, Pmax() is the maximum pooling operation, and C1 is C i The result of concatenating average pooling and max pooling;

[0058] In step 3.1.1.2, after maximum pooling and average pooling, the output results are passed through convolution and tanh() functions to adjust the response strength of these features to better extract the required spatial feature distribution map. The calculation formula is shown in formula (11):

[0059] C out =tanh(Conv 3×3 (C1)) (11)

[0060] In the formula, tanh() is the tanh activation function, Conv 3×3 is a convolution with a convolution kernel of 3×3, C out It is the result of non-local inter-group modulation by C1.

[0061] Step 3.1.2 is implemented as follows:

[0062] Step 3.1.2.1, assuming the input tensor is f a, an average pooling operation is applied to reduce the spatial dimension of the input feature. Subsequently, the feature channel is further compressed through a 1x1 convolution layer while keeping the spatial dimension unchanged. The multi-dimensional feature map after convolution is flattened in the spatial dimension and then transposed to match the computational requirements of the attention mechanism. Through the activation function Softmax processing, an attention matrix A is generated to adjust the weights between different feature channels. The calculation formula is shown in formula (12):

[0063] A=Softmax(Conv1d(Flatten(Conv2d(Pavg(f a )))) (12)

[0064] In the formula, Pavg() is the average pooling operation, Conv2d() is the convolution in two-dimensional space, which is the first convolution, Flatten() is the flattening operation, Conv1d() is the one-dimensional convolution, which is the transposition operation, and Softmax() is the activation function;

[0065] Step 3.1.2.2, construct a learnable matrix parameter B, and set the initial value to a small initial value a i , after initialization, matrix addition is performed with the attention matrix A. Each element of B is a parameter of the model, which is optimized through the training process. The addition of A and B combines dynamic attention and static parameter attention to enhance the model's expressiveness, adaptability, and generalization capabilities. The calculation formula is shown below:

[0066]

[0067]

[0068] In the formula, the B matrix is ​​the initialization learnable matrix, The operation is matrix addition of A and B;

[0069] Step 3.1.2.3, use the obtained attention matrix B to input tensor f b After weighting, the weighted tensor is further transformed and feature extracted through a series of convolutional layers and activation functions. The calculation formula is shown in formula (13):

[0070] f out =f b ⊙Softmax(Rule(Conv(MatMul(f b ,C)))) (15)

[0071] In the formula, MatMul() function is the matrix weighting operation, matrix dot multiplication operation Rule() is the activation function, Rule() is the rule activation function, Softmax() is the Softmax activation function, ⊙ is the matrix multiplication operation, and f out is the output;

[0072] Step 3.2 is as follows:

[0073] The input feature map is downsampled through maximum pooling, and an adaptive global modulation module is introduced to intelligently adjust and optimize features of different scales. The calculation formula is shown in the following formula:

[0074] C(f)=Ag(Pmax(f)) (16)

[0075] F=Conv(Cat(C(f),C(C(f)),C(C(C(f))))) (17)

[0076] Wherein, Ag() function is the adaptive global modulation module in step 3.1, Pmax() is the maximum pooling operation, Cat() is the linking operation, and F is the result of the feature being downsampled three times and subjected to the adaptive global modulation module and finally convolution modulation.

[0077] Step 4 is implemented according to the following steps:

[0078] Step 4.1, assuming the input tensor is f c , rearrange it, merge the channel dimension c and the spatial dimension of the feature map to form a new shape, and then transpose the rearranged feature map to obtain a tensor with a shape of (batch_size, height*width, c). The calculation formula is shown in formula (18):

[0079] F1=bmm(f c .view(B, C, HW), f c .view(B, C, HW) T ) (18)

[0080] Where view() is a rearrangement operation, T is a transpose operation, bmm() function is a matrix multiplication operation, which is used to calculate the attention weights between channels of the feature map, B is the batch size, C is the number of channels, and HW is the feature map height*width;

[0081] Step 4.2, take the output of step 4.1 as input, normalize F1, convert the attention weight matrix into a probability distribution, so that the importance of each channel is properly represented, rearrange the original feature map, and change the shape to (batch_size, c, height*width). Perform matrix multiplication on the normalized feature map and the rearranged feature map to obtain the weighted feature representation, and then restore the weighted feature to the original feature. Finally, scale the feature map and establish a residual connection with the original feature map to retain the information of the original feature map. The learned scaling factor gamma further enhances the feature expression ability. The calculation formula is shown below:

[0082] F2=bmm(softmax(F1),f.view(B,C,HW)) (19)

[0083]

[0084] In the formula, view() is a rearrangement operation, bmm() function is a matrix multiplication operation, gamma() function is a scaling function, which generates a learnable scaling induction, B is the batch size, C is the number of channels, H is the feature map height, W is the feature map width, is matrix addition.

[0085] The beneficial effects of the present invention are:

[0086] The present invention is based on improving YOLO v The track defect detection method of the 8-algorithm introduces the anchor fusion network module, the adaptive global modulation pyramid module and the channel self-attention mechanism module, which greatly improves the comprehensive performance of the model; the anchor attention mechanism significantly enhances the model's ability to capture key information in the image, ensuring accurate identification of track defects; the adaptive global modulation module further enhances the feature expression ability through the aggregation of contextual information, making it more adaptable to diverse track defect types; and in the Neck part of the network, the channel self-attention mechanism module is added, which optimizes the feature expression by dynamically adjusting the feature weights, and improves the flexibility and adaptability of the model. The present invention not only significantly improves the accuracy and robustness of detection, but also ensures the efficient operation of the model under complex environmental conditions. BRIEF DESCRIPTION OF THE DRAWINGS

[0087] Figure 1 It is an overall model framework diagram of the track defect detection method based on the improved YOLOv8 algorithm of the present invention;

[0088] Figure 2 It is a network architecture diagram of the anchor fusion network module in step 2 of the track defect detection method based on the improved YOLOv8 algorithm of the present invention;

[0089] Figure 3 It is a network architecture diagram of the adaptive global modulation pyramid module in step 3 of the track defect detection method based on the improved YOLOv8 algorithm of the present invention;

[0090] Figure 4 This is a network architecture diagram of the channel self-attention mechanism module in step 4 of the track defect detection method based on the improved YOLOv8 algorithm of the present invention. DETAILED DESCRIPTION

[0091] The present invention is described in detail below with reference to the accompanying drawings and specific embodiments.

[0092] Example 1

[0093] The present invention is based on a track defect detection method based on an improved YOLOv8 algorithm, and is specifically implemented in the following steps:

[0094] Step 1: Build the dataset and encoder;

[0095] Step 1 is implemented as follows:

[0096] Step 1.1, collect thousands of sample images of track defects;

[0097] Step 1.2, annotate and classify the sample images collected in step 1.1 on the Roboflow website, and use the image annotation tool to annotate the sample images of track diseases. The annotation process includes determining the location and bounding box of the disease, and assigning corresponding labels to each disease category;

[0098] Step 1.3, divide all sample images and their annotated files into training set, validation set and test set in proportion.

[0099] Step 1.4, use the improved YOLOv8 model to build an encoder. The constructed network structure is as follows: Figure 1 As shown;

[0100] Step 1.5, adjust the dataset image resolution to 640×640 and input it into the encoder;

[0101] Step 2: construct the anchor fusion network module, such as Figure 2 The CAC2F module in the middle shows the anchor fusion network module;

[0102] Step 3, construct an adaptive global modulation pyramid module;

[0103] Step 4: Construct a channel self-attention mechanism module, such as Figure 4 CAM module shown.

[0104] Example 2

[0105] The present invention is based on improving YOLO v The track defect detection method of the 8 algorithm, wherein step 2 is specifically implemented according to the following steps:

[0106] Step 2.1, construct a feature channel segmentation module, the model can process these features separately, so that the model can learn a more fine-grained feature representation;

[0107] Step 2.1 is implemented as follows:

[0108] Step 2.1.1, assuming an input tensor f with size B×N×C, divide the tensor evenly into two equal parts along the channel dimension (C dimension) by using the cutting function. The dimension of each part will be The premise is that C is divisible by 2. If C is an odd number, then the sizes of the two parts will be and To ensure that all channels are included, assuming that the split tensor is V, the calculation formula is shown in formula (1):

[0109] V = f.chunk(2, 1)(1)

[0110] Where, V array is the result after cutting, f is the input tensor, chunk(2,1) is the cutting function, 2 in the cutting function means cutting into two parts, and 1 means cutting along the channel latitude;

[0111] Step 2.1.2: Take the tensor obtained in step 2.1.1 as input and guide it through a convolution layer with an n×n convolution kernel and a step size of 1. After this convolution process, two new tensors are obtained, denoted as y[0] and y[1] respectively. These tensors represent the output after the convolution operation and provide feature representation for further processing of the network. The calculation formulas are shown in equations (2) and (3):

[0112] y[0]=C v1 (V1) (2)

[0113] y[1]=C v1 (V2) (3)

[0114] In the formula, y[0], y[1] are the outputs after cutting and convolution, C v1 (V1), C v1 (V2) is the convolution operation, V1 and V2 are the outputs of step 2.1.1;

[0115] Step 2.2: Build an anchor attention module to enhance the model’s ability to focus on key information and improve the accuracy of feature recognition.

[0116] Step 2.2 is implemented in series through pooling, convolution, and activation function operations to capture the contextual relationship between distant pixels in the image, enhance the central features, and improve the model's sensitivity and understanding of global contextual information. The specific implementation steps are as follows:

[0117] Step 2.2.1, construct average pooling, the convolution kernel is 1×1 convolution operation, and the calculation formula is shown in formula (4):

[0118]

[0119] In the formula, To get the result after flat pooling and convolution, Conv 1×1 () is the convolution operation, P avg () is average pooling, y[1] is the output of step 2.1.2;

[0120] Step 2.2.2, construct horizontal convolution layers and vertical convolution layers. The convolution kernel of the horizontal convolution layer is 11 in the horizontal direction and 1 in the vertical direction. The convolution kernel of the vertical convolution layer is 1 in the horizontal direction and 11 in the vertical direction. By constructing horizontal and vertical convolution layers, the model's ability to capture image features is improved while maintaining computational efficiency. The calculation formula is shown below:

[0121]

[0122] f h =h_cOnv h×1 (f w ) (6)

[0123] Where w_conv 1×v () is the horizontal convolution with a convolution kernel of 1×11, h_conv h×1 () is a vertical convolution with a convolution kernel of 11×1, f w is the result of horizontal convolution, f h is the result of vertical convolution;

[0124] Step 2.2.3, construct activation function and convolution operation to generate dynamic attention weights, strengthen the key areas in the image, and suppress the less important parts. The calculation formula is shown in formula (7):

[0125] f ca =Sigmoid(Conv(f h )) (7)

[0126] In the formula, Sigmoid is the activation function, Conv() is the convolution with a convolution kernel of 1×1, and f ca To generate dynamic attention weights.

[0127] Step 2.3, build a network fusion module to efficiently integrate features at different levels and optimize their performance;

[0128] In step 2.3, the output y[0] obtained by the segmentation in step 2.1.2 is reintegrated with y[1] after being processed by the anchor attention module in step 2.2. This promotes the effective interaction of features at different levels and enhances the network's ability to express complex information. The specific implementation steps are as follows:

[0129] Step 2.3.1, construct anchor feature sequence E n , n∈{1, 2, 3..n}, the segmentation output y[0] of step 2.1.2, after the anchor feature sequence E n , and obtain high-level feature representation, and gradually refine these features through repeated application. The calculation formula is shown in formula (8):

[0130]

[0131] Where Ca() is the anchor attention module, For the sum operation, E n is the obtained anchor feature sequence;

[0132] Step 2.3.2, build a fusion module, fuse the output of step 2.3.1 with the output y[1] obtained by segmentation in step 2.1.2 in the channel dimension, and then use a 1×1 convolution operation to adjust the feature map to ensure that it is more efficient in the spatial dimension. The calculation formula is shown in formula (9):

[0133] f out =Conv 1×1 (Cat(y[1],E n )) (9)

[0134] In the formula, Cat() is the Concatenate link function, and the features are concatenated in the channel dimension.

[0135] Example 3

[0136] The present invention is based on a track defect detection method based on an improved YOLOv8 algorithm, wherein step 3 is specifically implemented according to the following steps:

[0137] Step 3.1, construct an adaptive global modulation module, enhance local features through non-local inter-group modulation, and further enhance feature representation through context aggregation, such as Figure 3 As shown in the AGM module;

[0138] Step 3.1 is implemented as follows:

[0139] Step 3.1.1, guide the fusion between corresponding pixels through non-local inter-group modulation to reduce the semantic difference between cross-scale features;

[0140] Step 3.1.1 is implemented as follows:

[0141] Step 3.1.1.1, input feature C i , the background information of the extracted features and the target texture information of the features are obtained through average pooling Pavg and maximum pooling Pmax in the channel dimension, and then further spliced ​​to obtain the required spatial feature distribution map. The calculation formula is shown in formula (10):

[0142] C1=Cat(Pmax(C i ), Pavg(C i )) (10)

[0143] In the formula, Cat() is the Concatenate link function, Pavg() is the average pooling operation, Pmax() is the maximum pooling operation, and C1 is C i The result of concatenating average pooling and max pooling;

[0144] In step 3.1.1.2, after maximum pooling and average pooling, the output results are passed through convolution and tanh() functions to adjust the response strength of these features to better extract the required spatial feature distribution map. The calculation formula is shown in formula (11):

[0145] C out =tanh(Conv 3×3 (C1)) (11)

[0146] In the formula, tanh() is the tanh activation function, Conv 3×3 is a convolution with a convolution kernel of 3×3, C out It is the result of non-local inter-group modulation by C1.

[0147] Step 3.1.2: Enhance the connection between local features and global context through the context aggregation module to improve the network's ability to understand features;

[0148] Step 3.1.2 is implemented as follows:

[0149] Step 3.1.2.1, assuming the input tensor is f a, an average pooling operation is applied to reduce the spatial dimension of the input feature. Subsequently, the feature channel is further compressed through a 1x1 convolution layer while keeping the spatial dimension unchanged. The multi-dimensional feature map after convolution is flattened in the spatial dimension and then transposed to match the computational requirements of the attention mechanism. Through the activation function Softmax processing, an attention matrix A is generated to adjust the weights between different feature channels. The calculation formula is shown in formula (12):

[0150] A=Softmax(Conv1d(Flatten(Conv2d(Pavg(f a )))) (12)

[0151] In the formula, Pavg() is the average pooling operation, Conv2d() is the convolution in two-dimensional space, which is the first convolution, Flatten() is the flattening operation, Conv1d() is the one-dimensional convolution, which is the transposition operation, and Softmax() is the activation function;

[0152] Step 3.1.2.2, construct a learnable matrix parameter B, and set the initial value to a small initial value a i , after initialization, matrix addition is performed with the attention matrix A. Each element of B is a parameter of the model, which is optimized through the training process so that it can learn how to allocate attention between feature channels to enhance important features and suppress unimportant features. The addition of A and B combines dynamic attention with static parameter attention to enhance the model's expressiveness, adaptability, and generalization capabilities. The calculation formula is shown below:

[0153]

[0154]

[0155] In the formula, the B matrix is ​​the initialization learnable matrix, The operation is matrix addition of A and B;

[0156] Step 3.1.2.3, use the obtained attention matrix B to input tensor f b The weighted tensor is then further transformed and feature extracted through a series of convolutional layers and activation functions. The calculation formula is shown in formula (15):

[0157] f out =f b ⊙Softmax(Rule(Conv(MatMul(f b ,C)))) (15)

[0158] In the formula, MatMul() function is the matrix weighting operation, matrix dot multiplication operation Rule() is the activation function, Rule() is the rule activation function, Softmax() is the Softmax activation function, ⊙ is the matrix multiplication operation, and f out is the output.

[0159] Step 3.2, construct a multi-scale feature pyramid fusion module to pool and fuse the features of receptive fields of different sizes;

[0160] Step 3.2 is as follows:

[0161] The input feature map is downsampled through maximum pooling to achieve feature downsampling. At the same time, an adaptive global modulation module is introduced to intelligently adjust and optimize features of different scales. Through this combination, a multi-dimensional feature pyramid is constructed. The calculation formula is shown in the following formula:

[0162] C(f)=Ag(Pmax(f)) (16)

[0163] F=Conv(Cat(C(f),C(C(f)),C(C(C(f))))) (17)

[0164] Wherein, Ag() function is the adaptive global modulation module in step 3.1, Pmax() is the maximum pooling operation, Cat() is the linking operation, and F is the result of the feature being downsampled three times and subjected to the adaptive global modulation module and finally convolution modulation.

[0165] Example 4

[0166] The present invention is based on a track defect detection method based on an improved YOLOv8 algorithm, wherein step 4 is specifically implemented according to the following steps:

[0167] Step 4.1, assuming the input tensor is f c , and rearrange them for subsequent matrix operations. The channel dimension c and spatial dimension (height height and width width) of the feature map are merged to form a new shape (batch_size, c, height*width). Then, the rearranged feature map is transposed to obtain a tensor of shape (batch_size, height*width, c). This step is to prepare for matrix multiplication and then calculate the attention weights between channels. The calculation formula is shown in formula (18):

[0168] F1=bmm(f c .view(B, C, HW), f c .view(B, C, HW) T ) (18)

[0169] Where view() is a rearrangement operation, T is a transpose operation, bmm() function is a matrix multiplication operation, which is used to calculate the attention weights between channels of the feature map, B is the batch size, C is the number of channels, and HW is the feature map height*width;

[0170] Step 4.2, take the output of step 4.1 as input, normalize F1, convert the attention weight matrix into a probability distribution, so that the importance of each channel is properly represented, rearrange the original feature map, and the shape becomes (batch_size, c, height*width). This step is to merge the spatial dimensions of the feature map to facilitate matrix multiplication with the normalized attention weight matrix, perform matrix multiplication on the normalized feature map and the rearranged feature map to obtain a weighted feature representation, and then restore the weighted feature to the original feature. Finally, scale the feature map and establish a residual connection with the original feature map to retain the information of the original feature map. The feature expression ability is further enhanced by the learned scaling factor gamma. The calculation formula is shown below:

[0171] F2=bmm(softmax(F1),f.view(B,C,HW)) (19)

[0172]

[0173] In the formula, view() is a rearrangement operation, bmm() function is a matrix multiplication operation, gamma() function is a scaling function, which generates a learnable scaling induction, B is the batch size, C is the number of channels, H is the feature map height, W is the feature map width, is matrix addition.

[0174] The experimental results are shown in Table 1 below, which clearly demonstrates the significant advantage of the network model trained by the method proposed in the present invention in terms of accuracy. On the two track disease datasets RIV and DET, the evaluation index of the model surpasses the existing methods. The results of the method proposed in the present invention are compared with those of the existing methods, and the results in bold are the best results.

[0175] Table 1

[0176]

Claims

1. Track defect detection method based on improved YOLOv8 algorithm, It is characterized in that Follow the steps below to implement it: Step 1: Build the dataset and encoder; Step 2, constructing an anchor fusion network module; Step 3, construct an adaptive global modulation pyramid module; Step 4: Build a channel self-attention mechanism module.

2. According to the track defect detection method based on the improved YOLOv8 algorithm according to claim 1, It is characterized in that The step 1 is specifically implemented according to the following steps: Step 1.1, collect sample images of track defects; Step 1.2, annotate and classify the sample images collected in step 1.1, determine the location and bounding box of the disease, and assign corresponding labels to each disease category; Step 1.3, divide all sample images and their annotated files into training set, validation set and test set in proportion; Step 1.4, use the improved YOLOv8 model, load the pre-trained weights, and build the encoder; In step 1.5, the dataset image resolution is adjusted to 640×640 and input into the encoder.

3. According to the track defect detection method based on the improved YOLOv8 algorithm according to claim 1, It is characterized in that The step 2 is specifically implemented according to the following steps: Step 2.1, based on the convolution and cutting functions, construct a feature channel segmentation module; Step 2.2, build the anchor attention module; Step 2.3, build the network fusion module.

4. The track defect detection method based on the improved YOLOv8 algorithm according to claim 3, It is characterized in that The step 2.1 is specifically implemented according to the following steps: Step 2.1.1, assuming an input tensor f with size B×N×C, divide the tensor evenly into two equal parts along the channel dimension by using the cutting function, the dimension of each part will be The premise is that C is divisible by 2. If C is an odd number, then the sizes of the two parts will be and To ensure that all channels are included, assuming that the split tensor is V, the calculation formula is shown in formula (1): V = f.chunk(2,1) (1) In the formula, V array is the result after cutting, f is the input tensor, chunk(2,1) is the cutting function, 2 in the cutting function means cutting into two parts, and 1 means cutting along the channel latitude; Step 2.1.2, take the tensor obtained in step 2.1.1 as input, and guide it through the convolution layer with n×n convolution kernel and stride 1, and obtain two new tensors, denoted as y[0] and y[1], which provide feature representation for further processing of the network. The calculation formula is shown as follows: y[0]=C v1 (V 1 ) (2) y[1]=C v1 (V 2 ) (3) In the formula, y[0], y[1] are the outputs after cutting and convolution, C v1 (V 1 ), C v1 (V 2 ) is the convolution operation, V 1 , V 2 Output from step 2.1.

1.

5. According to claim 3, the track defect detection method based on the improved YOLOv8 algorithm, It is characterized in that The step 2.2 is implemented in series by pooling, convolution and activation function operations, and is specifically implemented in the following steps: Step 2.2.1, construct average pooling, the convolution kernel is 1×1 convolution operation, and the calculation formula is shown in formula (4): In the formula, To get the result after flat pooling and convolution, Conv 1×1 () is the convolution operation, P avg () is average pooling, y[1] is the output of step 2.1.2; Step 2.2.2, construct horizontal convolutional layer and vertical convolutional layer. The convolution kernel of horizontal convolutional layer is 11 in horizontal direction and 1 in vertical direction. The convolution kernel of vertical convolutional layer is 1 in horizontal direction and 11 in vertical direction. The calculation formula is as follows: f h =h_conv h×1 (f w ) (6) Where w_conv 1×v () is the horizontal convolution with a convolution kernel of 1×11, h_conv h×1 () is a vertical convolution with a convolution kernel of 11×1, f w is the result of horizontal convolution, f h is the result of vertical convolution; Step 2.2.3, construct activation function and convolution operation to generate dynamic attention weights to strengthen the key areas in the image. The calculation formula is shown in formula (7): f ca =Simoid(Conv(f h )) (7) In the formula, Sigmoid is the activation function, Conv() is the convolution with a convolution kernel of 1×1, and f ca To generate dynamic attention weights; In step 2.3, the output y[0] obtained by the segmentation in step 2.1.2 is reintegrated with y[1] after being processed by the anchor attention module in step 2.2, which is specifically implemented in the following steps: Step 2.3.1, construct anchor feature sequence E n ,n∈{1,2,3..n}, the segmentation output y[0] of step 2.1.2, after the anchor feature sequence E n , and obtain high-level feature representation, and gradually refine these features through repeated application. The calculation formula is shown in formula (8): Where Ca() is the anchor attention module, For the sum operation, E n is the obtained anchor feature sequence; Step 2.3.2, build a fusion module, fuse the output of step 2.3.1 with the output y[1] obtained by segmentation in step 2.1.2 in the channel dimension, and then use a 1×1 convolution operation to adjust the feature map to ensure that it is more efficient in the spatial dimension. The calculation formula is shown in formula (9): f out =Conv 1×1 (Cat(y[1],E n )) (9) In the formula, Cat() is the Concatenate link function, and the features are concatenated in the channel dimension.

6. The track defect detection method based on the improved YOLOv8 algorithm according to claim 1, It is characterized in that The step 3 is specifically implemented according to the following steps: Step 3.1, construct an adaptive global modulation module; Step 3.2: construct a multi-scale feature pyramid fusion module to pool and fuse the features of receptive fields of different sizes.

7. The track defect detection method based on the improved YOLOv8 algorithm according to claim 6, It is characterized in that The step 3.1 is specifically implemented according to the following steps: Step 3.1.1, guide the fusion between corresponding pixels through non-local inter-group modulation to reduce the semantic difference between cross-scale features; Step 3.1.2, the connection between local features and global context is enhanced through the context aggregation module to improve the network's ability to understand features.

8. The track defect detection method based on the improved YOLOv8 algorithm according to claim 7, It is characterized in that The step 3.1.1 is specifically implemented according to the following steps: Step 3.1.1.1, input feature C i , the background information of the extracted features and the target texture information of the features are obtained through average pooling Pavg and maximum pooling Pmax in the channel dimension, and then further spliced ​​to obtain the required spatial feature distribution map. The calculation formula is shown in formula (10): C 1 =Cat(Pmax(C i ), Pavg(C i )) (10) In the formula, Cat() is the Concatenate link function, Pavg() is the average pooling operation, Pmax() is the maximum pooling operation, and C 1 C i The result of concatenating average pooling and max pooling; In step 3.1.1.2, after maximum pooling and average pooling, the output results are passed through convolution and tanh() functions to adjust the response strength of these features to better extract the required spatial feature distribution map. The calculation formula is shown in formula (11): C out =tanh(Conv 3×3 (C 1 )) (11) In the formula, tanh() is the tanh activation function, Conv 3×3 is a convolution with a convolution kernel of 3×3, C out For C 1 Results of non-local inter-group modulation.

9. The track defect detection method based on the improved YOLOv8 algorithm according to claim 6, It is characterized in that The step 3.1.2 is specifically implemented according to the following steps: Step 3.1.2.1, assuming the input tensor is f a , an average pooling operation is applied to reduce the spatial dimension of the input feature. Subsequently, the feature channel is further compressed through a 1x1 convolution layer while keeping the spatial dimension unchanged. The multi-dimensional feature map after convolution is flattened in the spatial dimension and then transposed to match the computational requirements of the attention mechanism. Through the activation function Softmax processing, an attention matrix A is generated to adjust the weights between different feature channels. The calculation formula is shown in formula (12): A=Softmax(Conv1d(Flatten(Conv2d(Pavg(f a )))) (12) In the formula, Pavg() is the average pooling operation, Conv2d() is the convolution in two-dimensional space, which is the first convolution, Flatten() is the flattening operation, Conv1d() is the one-dimensional convolution, which is the transposition operation, and Softmax() is the activation function; Step 3.1.2.2, construct a learnable matrix parameter B, and set the initial value to a small initial value a i , after initialization, matrix addition is performed with the attention matrix A. Each element of B is a parameter of the model, which is optimized through the training process. The addition of A and B combines dynamic attention and static parameter attention to enhance the model's expressiveness, adaptability, and generalization capabilities. The calculation formula is shown below: In the formula, the B matrix is ​​the initialization learnable matrix, The operation is matrix addition of A and B; Step 3.1.2.3, use the obtained attention matrix B to input tensor f b After weighting, the weighted tensor is further transformed and features are extracted through a series of convolutional layers and activation functions. The calculation formula is shown in formula (15): f out =f b ⊙Softmax(Rule(Conv(MatMul(f b ,C)))) (15) In the formula, MatMul() function is the matrix weighting operation, matrix dot multiplication operation Rule() is the activation function, Rule() is the rule activation function, Softmax() is the Softmax activation function, ⊙ is the matrix multiplication operation, and f out is the output; Step 3.2 is as follows: The input feature map is downsampled through maximum pooling, and an adaptive global modulation module is introduced to intelligently adjust and optimize features of different scales. The calculation formula is shown in the following formula: C(f)=Ag(Pmax(f)) (16) F=Conv(Cat(C(f),C(C(f)),C(C(C(f))))) (17) Wherein, Ag() function is the adaptive global modulation module in step 3.1, Pmax() is the maximum pooling operation, Cat() is the linking operation, and F is the result of the feature being downsampled three times and subjected to the adaptive global modulation module and finally convolution modulation.

10. The track defect detection method based on the improved YOLOv8 algorithm according to claim 1, It is characterized in that The step 4 is specifically implemented according to the following steps: Step 4.1, assuming the input tensor is f c , rearrange it, merge the channel dimension c and the spatial dimension of the feature map to form a new shape, and then transpose the rearranged feature map to obtain a tensor with a shape of (batch_size, height*width, c). The calculation formula is shown in formula (18): F 1 =bmm(f c .view(B,C,HW),f c .view(B,C,HW) T ) (18) Where view() is a rearrangement operation, T is a transpose operation, bmm() function is a matrix multiplication operation, which is used to calculate the attention weights between channels of the feature map, B is the batch size, C is the number of channels, and HW is the feature map height*width; Step 4.2: Take the output of step 4.1 as input and perform 1 Normalization is performed to convert the attention weight matrix into a probability distribution so that the importance of each channel is properly represented. The original feature map is rearranged and the shape becomes (batch_size, C, height*width). The normalized feature map and the rearranged feature map are matrix multiplied to obtain a weighted feature representation. The weighted feature is then restored to the original feature. Finally, the feature map is scaled and a residual connection is established with the original feature map to retain the information of the original feature map. The learned scaling factor gamma further enhances the feature expression capability. The calculation formula is shown below: F 2 =bmm(softmax(F 1 ),f.view(B,C,HW)) (19) In the formula, view() is a rearrangement operation, bmm() function is a matrix multiplication operation, gamma() function is a scaling function, which generates a learnable scaling induction, B is the batch size, C is the number of channels, H is the feature map height, W is the feature map width, is matrix addition.

Citation Information

Cited By

  • Global and local feature fusion pseudo label refining method based on attention mechanism

    CN119649179A