Track disease multi-scale lightweight detection method based on improved YOLOv12 algorithm
By improving the YOLOv12 algorithm and introducing the lightweight GhostNet module, multi-scale feature fusion, and channel attention mechanism, the insufficient performance of track defect detection in complex scenarios is solved, and high-precision, real-time, lightweight detection is achieved, which is suitable for resource-constrained vehicle-mounted and mobile devices.
Patent Information
- Application Number
- CN202510816479.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-18
- Publication Date
- 2025-09-19
AI Technical Summary
Existing rail defect detection methods have insufficient detection performance in complex scenarios, especially small-sized defect targets are easily missed. In addition, the increased model depth leads to slower inference speed, making it difficult to run in real time on vehicle-mounted or on-site equipment.
Based on the improved YOLOv12 algorithm, a lightweight GhostNet module, a multi-scale feature fusion mechanism, and a channel attention mechanism are introduced to build a lightweight detection framework. Through lightweight feature extraction, multi-scale feature fusion, and channel attention enhancement of the backbone network, the detection performance and deployment efficiency are improved.
It significantly improves the model's detection performance and deployment efficiency in complex track scenarios, enhances the ability to detect tiny track disease targets, and ensures the efficient operation of the model in resource-constrained scenarios.
Smart Images

Figure CN120673043A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of computer vision and image detection methods, and specifically relates to a multi-scale lightweight detection method for track defects based on an improved YOLOv12 algorithm. Background Art
[0002] During the long-term operation of urban rail transit lines, various defects often appear on the track structure and surface, such as cracks, missing edges, rust, and foreign objects dropped on the rails. If these defects are not discovered and addressed in a timely manner, they will seriously affect the safety and efficiency of rail transit operations.
[0003] Traditional rail defect detection methods primarily rely on manual inspections and hand-crafted features. For example, defects are identified using features such as color, shape, and texture. However, these methods typically rely on manually extracted features, which can solve defect detection problems in simple scenarios. However, in complex scenarios, detection performance deteriorates dramatically, failing to meet practical needs.
[0004] In recent years, the development of deep learning technology has provided new ideas for the automatic detection of track defects. Object detection algorithms based on convolutional neural networks (such as the two-stage detector Faster R-CNN and the single-stage detector YOLO series) have been introduced into the field of track defect detection. By training the model on a large amount of labeled data, these methods can automatically learn and extract features that are helpful for defect identification, significantly improving detection accuracy compared to traditional methods. However, even the more advanced detection models currently available still have shortcomings in complex track scenarios: small-sized defect targets are easily missed in situations with complex backgrounds and uneven lighting; at the same time, increasing the model depth and number of parameters to improve accuracy will slow down the inference speed, making it difficult to run in real time on vehicle-mounted or on-site equipment. Therefore, there is an urgent need for an improved track defect detection algorithm that can minimize the amount of computation while ensuring model accuracy, so as to meet the requirements of urban rail transit scenarios for real-time detection of multi-scale defects. Summary of the Invention
[0005] The purpose of this invention is to provide a multi-scale lightweight detection method for track defects based on an improved YOLOv12 algorithm, which can achieve high-precision and real-time detection of track defects in complex scenarios of rail transit.
[0006] The technical solution adopted by the present invention is a multi-scale lightweight detection method for track defects based on an improved YOLOv12 algorithm, which is specifically implemented in the following steps:
[0007] Step 1: Build a track disease dataset and model encoder;
[0008] Step 2: Build a lightweight YOLOv12 convolutional neural network structure;
[0009] Step 3: Construct a multi-scale feature fusion mechanism;
[0010] Step 4: Build a channel attention mechanism module.
[0011] The present invention is also characterized in that:
[0012] Step 1 is implemented as follows:
[0013] Step 1 is implemented as follows:
[0014] Step 1.1: Collect sample images of different types of track defects, including cracks, missing edges, rust, and foreign matter intrusion;
[0015] Step 1.2: Label and classify the sample images in step 1.1, determine the precise location and category of the disease in each image, and assign a corresponding label to each disease target;
[0016] Step 1.3: Divide all labeled samples into training set, validation set, and test set in proportion for model training and evaluation;
[0017] In step 1.4, we load the pre-trained weight parameters based on the improved YOLOv12 model and build the model encoder to accelerate convergence by leveraging the common features learned by the pre-trained model.
[0018] In step 1.5, the sample images are uniformly resized to a predetermined input resolution of 640 × 640 pixels and fed into the encoder for feature extraction.
[0019] Step 2 is implemented as follows:
[0020] Step 2.1: Introduce the lightweight GhostNet module to improve the backbone network of the YOLOv12 model;
[0021] Step 2.2, applying a lightweight transformation operation to the feature map obtained in step 2.1 to generate a ghost feature map;
[0022] In step 2.3, the intrinsic convolution features generated in step 2.1 and the ghost features generated in step 2.2 are concatenated and fused in the channel dimension, and then the concatenated fusion features are compressed and linearly transformed through convolution.
[0023] Step 2.1 is implemented as follows:
[0024] In step 2.1.1, assume an input tensor X with dimensions B×C×H×W, where B represents the batch size, C represents the number of channels of the input feature map, and H and W represent the height and width of the input feature map, respectively. Use the standard convolution operation to extract the main feature map X', as shown in formula (1):
[0025] X'=σ(BN(Conv k×k (X))) (1)
[0026] Where, Conv k×k represents the standard convolution operation with a convolution kernel size of k×k, BN is the batch normalization operation, and σ is the activation function;
[0027] Step 2.1.2, after obtaining the main feature map X′ in step 2.1.1, in order to further generate more feature expressions and reduce computational overhead, a lightweight linear transformation function is introduced to generate a set of ghost feature maps. Let the transformation function be Φ i (·), then the ghost feature map The generation formula is as follows:
[0028]
[0029] Among them, s represents the number of linear transformations, Φ i (·) Use channel-by-channel convolution for lightweight operations;
[0030] Perform splicing operations on all generated ghost feature maps to obtain the final ghost feature map x g , which is calculated as follows:
[0031]
[0032] Where Concat represents the concatenation operation in the channel dimension.
[0033] Step 2.2 is implemented as follows:
[0034] In step 2.2.1, the main feature map X' obtained in step 2.1.1 is used as input and sent to the lightweight linear transformation layer in the Ghost module for context supplementation operation. Let the lightweight convolution kernel be W g , then the feature mapping process can be expressed as:
[0035] X ghost =σ(BN(W g *X′)) (4)
[0036] In the formula, * represents the convolution operation; BN is the batch normalization operation; σ is the nonlinear activation function; X ghost The enhanced ghost feature map output in step 2.2;
[0037] Step 2.2.2, perform spatial position alignment and shape adjustment on the generated ghost feature map. If the main feature map X' is aligned with the ghost feature map X ghost If there is inconsistency in spatial dimensions or channel dimensions, zero padding, upsampling, or 1×1 convolution can be used to match channels to ensure that they can be spliced with the main feature map;
[0038] Step 2.3 is implemented as follows:
[0039] Step 2.3.1: Substitute the main feature map X obtained in step 2.1.1 into the ghost feature map X generated in step 2.2. ghost Splicing is performed in the channel dimension to obtain the fused feature map F, and the calculation formula is shown in formula (5):
[0040] F=Concat(X′,X ghost ) (5)
[0041] Where Concat represents the channel dimension concatenation operation;
[0042] Step 2.3.2: In order to match the number of input channels of the subsequent structure of YOLOv12, the concatenated fusion feature F is compressed using 1×1 convolution, and normalized and activated at the same time to obtain the final feature map F. out , the calculation formula is shown in formula (6):
[0043] F out =σ(BN(Conv 1×1 (F))) (6)
[0044] Where, Conv 1×1 represents the channel compression convolution kernel; BN is the batch normalization operation; σ is the nonlinear activation function; F out Output tensor for the final compressed fusion feature.
[0045] Step 3 is implemented as follows:
[0046] Step 3.1, construct a multi-scale feature extraction path;
[0047] In step 3.2, feature compression and nonlinear mapping are performed on the fused feature map.
[0048] Step 3.1 is implemented as follows:
[0049] Step 3.1.1, extract multi-scale sub-feature maps
[0050] Assume the input feature map is Sub-feature maps of different resolutions are extracted through multiple maximum pooling operations. The calculation formula is shown in formula (7):
[0051] F1=F in ,F2=MaxPool(F1),F3=MaxPool(F2) (7)
[0052] Where F1, F2, and F3 represent the feature maps of 1×, 2×, and 4× downsampling scales, respectively; MaxPool represents the maximum pooling operation with a step size of 2, which extracts semantic information with a larger receptive field;
[0053] Step 3.1.2: Scale alignment and semantic compensation of sub-feature maps
[0054] F2 and F3 are upsampled to the same spatial size as F1 using bilinear interpolation, and the channel dimensions are unified through 1×1 convolution. The calculation formula is shown in formula (8):
[0055] F'2=Conv 1×1 (Upsample(F2)),F'3=Conv 1×1 (Upsample(Upsample(F3))) (8)
[0056] Where Upsample( ) is a bilinear upsampling operation, Conv 1×1 Used for channel compression and feature shaping.
[0057] Step 3.1.3: Construct a multi-scale pyramid structure with channel fusion. Concatenate the feature maps of the three scales in the channel dimension to construct a multi-scale semantic fusion feature map F fused , the calculation formula is shown in formula (9):
[0058] F fused =Concat(F1,F′2,F′3) (9)
[0059] Where Concat represents the channel dimension concatenation operation;
[0060] In order to improve the local area response capability, a multi-branch convolution path is introduced after fusion, and 3×3 and 5×5 convolutions are connected in parallel and then added as a context compensation module.
[0061] Step 3.2 is as follows: After multi-scale feature fusion, the number of channels will increase significantly. To avoid information redundancy and improve model efficiency, 1×1 convolution is introduced for channel compression, and normalization and activation functions are introduced to improve nonlinear expression capabilities. The calculation formula is shown below:
[0062] F out =σ(BN(Conv 1×1 (F fused ))) (10)
[0063] Where, Conv 1×1 Compress feature channels to ensure network depth and efficiency; BN is batch normalization operation; σ is nonlinear activation function; F out The fused multi-scale feature map is output and fed into the subsequent decoder.
[0064] Step 4 is implemented as follows:
[0065] Step 4.1, rearrange the feature map and calculate the channel weight;
[0066] Step 4.2: Construct the channel attention response map and enhance the original feature expression.
[0067] Step 4.1 transforms the input feature map into channel and spatial dimensions to calculate the correlation between channels and generate a channel attention matrix. This is done by following the steps below:
[0068] Step 4.1.1, assuming the input feature map is First, reshape it into a two-dimensional tensor for channel correlation modeling. The dimensionality transformation process is as follows:
[0069]
[0070] Where, Reshape() means flattening the spatial dimension; Transpose(F r ) represents the transposition operation, which is used for subsequent correlation calculation between channels;
[0071] Step 4.1.2: Calculate the channel attention matrix by multiplying FrF_rFr and its transpose FtF_tFt to obtain the inter-channel correlation matrix AAA, which is used to model the relationship between channels. The calculation formula is as follows:
[0072]
[0073] In the formula, the Softmax operation is used to normalize the correlation matrix so that each behavior of the attention matrix is a probability distribution;
[0074] In step 4.2, after obtaining the channel attention matrix, it is applied to the original feature map to achieve channel-level feature reweighting and expression enhancement. The specific implementation is as follows:
[0075] Step 4.2.1: Perform weighted fusion of the attention matrix A and the input feature map through matrix multiplication to obtain the attention response map F. a , the calculation formula is as follows:
[0076] F a =A·F r (14)
[0077] Then F a By reshaping back to the original four-dimensional shape:
[0078]
[0079] Step 4.2.2, construct residual connection and introduce learnable scaling factor. In order to enhance the stability and expression flexibility of the model, the residual connection structure is introduced and the learnable scaling factor γ is added. Finally, the feature map F is output. out , the calculation formula is as follows:
[0080] F out =γ·F′ a +F (16)
[0081] Where γ is a learnable parameter initialized to 0 and automatically adjusted through backpropagation; F is the original input feature map in step 4.1. This structure can retain the original information while strengthening the expression of key channels.
[0082] The beneficial effects of the present invention are:
[0083] This paper proposes a lightweight, multi-scale rail defect detection method based on an improved YOLOv12 algorithm. It introduces a lightweight GhostNet module, a multi-scale feature fusion mechanism, and a channel attention mechanism module, significantly improving the model's detection performance and deployment efficiency in complex rail scenarios. The GhostNet module constructs an efficient feature extraction path within the YOLOv12 backbone network, collaboratively generating redundant feature maps through primary convolution and linear transformation, effectively reducing the model's parameter count and computational complexity while retaining its ability to model target structural information. The multi-scale feature fusion mechanism constructs a cross-scale semantic information transfer structure. By upsampling, aligning, and fusing different downsampled feature maps, the model possesses a stronger receptive field and scale invariance, enhancing its ability to detect small rail defect targets. The channel attention mechanism module constructs a global correlation matrix between channels and adaptively adjusts the importance weights of each channel, strengthening the characteristic response of the defect target and suppressing redundant activation of irrelevant interference areas. The various modules jointly construct a lightweight target detection framework that combines detection accuracy, computational efficiency, and robustness. This not only improves the overall accuracy and real-time performance of track defect detection, but also ensures the efficient operation of the model in resource-constrained scenarios such as mobile terminals and vehicle-mounted terminals. BRIEF DESCRIPTION OF THE DRAWINGS
[0084] Figure 1 This is the overall network structure framework diagram of the multi-scale lightweight detection method for track defects based on the improved YOLOv12 algorithm of the present invention;
[0085] Figure 22 is a schematic diagram of the structure of the Ghost lightweight convolution module used in the backbone network in step 2 of the multi-scale lightweight detection method for track defects based on the improved YOLOv12 algorithm of the present invention;
[0086] Figure 3 3 is a schematic diagram of the pyramid structure of the multi-scale feature fusion module proposed in step 3 of the multi-scale lightweight detection method for track defects based on the improved YOLOv12 algorithm of the present invention;
[0087] Figure 4 This is a structural diagram of the channel attention mechanism module introduced in step 4 of the multi-scale lightweight detection method for track defects based on the improved YOLOv12 algorithm of the present invention. DETAILED DESCRIPTION
[0088] The present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0089] The present invention is based on a multi-scale lightweight detection method for track defects using an improved YOLOv12 algorithm, and is specifically implemented in the following steps:
[0090] Step 1: Build a track disease dataset and model encoder;
[0091] Step 2: Build a lightweight YOLOv12 convolutional neural network structure;
[0092] Step 3: Construct a multi-scale feature fusion mechanism;
[0093] Step 4: Build a channel attention mechanism module, such as Figure 4 CAMSA module shown.
[0094] Example 1
[0095] The present invention is based on a multi-scale lightweight detection method for track defects using an improved YOLOv12 algorithm, wherein step 1 is specifically implemented according to the following steps:
[0096] Step 1.1: Collect sample images of different types of track defects, including cracks, missing edges, rust, and foreign matter intrusion;
[0097] Step 1.2: Label and classify the sample images in step 1.1, determine the precise location and category of the disease in each image, and assign a corresponding label to each disease target;
[0098] Step 1.3: Divide all labeled samples into training set, validation set, and test set in proportion for model training and evaluation;
[0099] In step 1.4, we load the pre-trained weight parameters based on the improved YOLOv12 model and build the model encoder to accelerate convergence by leveraging the common features learned by the pre-trained model.
[0100] In step 1.5, the sample images are uniformly resized to a predetermined input resolution of 640 × 640 pixels and fed into the encoder for feature extraction.
[0101] Example 2
[0102] The present invention is based on a multi-scale lightweight detection method for track defects using an improved YOLOv12 algorithm, wherein step 2 is specifically implemented according to the following steps:
[0103] Step 2.1, introduce the lightweight GhostNet module to improve the backbone network of the YOLOv12 model. The constructed network structure is shown in the following figure: Figure 1 As shown;
[0104] Step 2.2, applying a lightweight transformation operation to the feature map obtained in step 2.1 to generate a ghost feature map;
[0105] In step 2.3, the intrinsic convolutional features generated in step 2.1 are concatenated with the ghost features generated in step 2.2 in the channel dimension, and then the concatenated fusion features are subjected to channel compression and linear transformation through convolution to restore the feature dimension and distribution consistent with the original YOLOv12 model output.
[0106] Example 3
[0107] The present invention is based on a multi-scale lightweight detection method for track defects using an improved YOLOv12 algorithm, wherein step 2.1 is specifically implemented according to the following steps:
[0108] In step 2.1.1, assume an input tensor X with dimensions B×C×H×W, where B represents the batch size, C represents the number of channels of the input feature map, and H and W represent the height and width of the input feature map, respectively. Use the standard convolution operation to extract the main feature map X', as shown in formula (1):
[0109] X'=σ(BN(Conv k×k (X))) (1)
[0110] Where, Conv k×k represents the standard convolution operation with a convolution kernel size of k×k, BN is the batch normalization operation, and σ is the activation function;
[0111] Step 2.1.2, after obtaining the main feature map X′ in step 2.1.1, in order to further generate more feature expressions and reduce computational overhead, a lightweight linear transformation function is introduced to generate a set of “ghost” feature maps. Let the transformation function be Φi (·), then the ghost feature map The generation formula is as follows:
[0112]
[0113] Among them, s represents the number of linear transformations, Φ i (·) Use channel-by-channel convolution for lightweight operations;
[0114] Perform splicing operations on all generated ghost feature maps to obtain the final ghost feature map X g ,like Figure 2 As shown in the GhostEnhance module, its calculation formula is as follows:
[0115]
[0116] Where Concat represents the concatenation operation in the channel dimension.
[0117] Step 2.2 is implemented as follows:
[0118] In step 2.2.1, the main feature map X' obtained in step 2.1.1 is used as input and sent to the lightweight linear transformation layer in the Ghost module for context supplementation operation. Let the lightweight convolution kernel be W g , then the feature mapping process can be expressed as:
[0119] X ghost =σ(BN(W g *X′)) (4)
[0120] In the formula, * represents the convolution operation; BN is the batch normalization operation; σ is the nonlinear activation function; X ghost The enhanced ghost feature map output in step 2.2;
[0121] Step 2.2.2, perform spatial position alignment and shape adjustment on the generated ghost feature map. If the main feature map X' is aligned with the ghost feature map X ghost If there is inconsistency in spatial dimensions or channel dimensions, channel matching can be performed through zero padding, upsampling, or 1×1 convolution to ensure that it can be spliced with the main feature map.
[0122] Step 2.3 is implemented as follows:
[0123] Step 2.3.1: Substitute the main feature map X obtained in step 2.1.1 into the ghost feature map X generated in step 2.2. ghost Splicing is performed in the channel dimension to obtain the fused feature map F, and the calculation formula is shown in formula (5):
[0124] F=Concat(X′,X ghost) (5)
[0125] Where Concat represents the channel dimension concatenation operation;
[0126] Step 2.3.2: In order to match the number of input channels of the subsequent structure of YOLOv12, the concatenated fusion feature F is compressed using 1×1 convolution, and normalized and activated at the same time to obtain the final feature map F. out , the calculation formula is shown in formula (6):
[0127] F out =σ(BN(Conv 1×1 (F))) (6)
[0128] Where, Conv 1×1 represents the channel compression convolution kernel; BN is the batch normalization operation; σ is the nonlinear activation function; F out Output tensor for the final compressed fusion feature.
[0129] Example 4
[0130] The present invention is based on a multi-scale lightweight detection method for track defects using an improved YOLOv12 algorithm, wherein step 3 is specifically implemented as follows:
[0131] Step 3.1, construct a multi-scale feature extraction path;
[0132] Sub-feature maps of multiple scales are derived from the feature map output by the backbone network, and a bottom-up pyramid semantic information expression path is constructed through cross-layer connections and structural alignment, such as Figure 3 As shown in the MSFusion module, the specific implementation steps are as follows:
[0133] Step 3.1.1, extract multi-scale sub-feature maps
[0134] Assume the input feature map is Sub-feature maps of different resolutions are extracted through multiple maximum pooling operations. The calculation formula is shown in formula (7):
[0135] F1=F in ,F2=MaxPool(F1),F3=MaxPool(F2) (7)
[0136] Where F1, F2, and F3 represent the feature maps of 1×, 2×, and 4× downsampling scales, respectively; MaxPool represents the maximum pooling operation with a step size of 2, which extracts semantic information with a larger receptive field;
[0137] Step 3.1.2: Scale alignment and semantic compensation of sub-feature maps
[0138] F2 and F3 are upsampled to the same spatial size as F1 using bilinear interpolation, and the channel dimensions are unified through 1×1 convolution. The calculation formula is shown in formula (8):
[0139] F'2=Conv 1×1 (Upsample(F2)),F'3=Conv 1×1 (Upsample(Upsample(F3))) (8)
[0140] Where Upsample( ) is a bilinear upsampling operation, Conv 1×1 Used for channel compression and feature shaping;
[0141] Step 3.1.3: Construct a multi-scale pyramid structure with channel fusion, concatenate the feature maps of the three scales in the channel dimension, and construct a multi-scale semantic fusion feature map F fused , the calculation formula is shown in formula (9):
[0142] F fused =Concat(F1,F′2,F′3) (9)
[0143] Where Concat represents the channel dimension concatenation operation;
[0144] In order to improve the local area response capability, a multi-branch convolution path is introduced after fusion, and 3×3 and 5×5 convolutions are connected in parallel and then added as a context compensation module;
[0145] Step 3.2: perform feature compression and nonlinear mapping on the fused feature map;
[0146] Step 3.2 is as follows: After multi-scale feature fusion, the number of channels will increase significantly. To avoid information redundancy and improve model efficiency, 1×1 convolution is introduced for channel compression, and normalization and activation functions are introduced to improve nonlinear expression capabilities. The calculation formula is shown below:
[0147] F out =σ(BN(Conv 1×1 (F fused ))) (10)
[0148] Where, Conv 1×1 Compress feature channels to ensure network depth and efficiency; BN is batch normalization operation; σ is nonlinear activation function; F out The fused multi-scale feature map is output and fed into the subsequent decoder.
[0149] Example 5
[0150] The present invention is based on a multi-scale lightweight detection method for track defects using an improved YOLOv12 algorithm, wherein step 4 is specifically implemented as follows:
[0151] Step 4.1, rearrange the feature map and calculate the channel weight;
[0152] Step 4.1 transforms the input feature map into channel and spatial dimensions to calculate the correlation between channels and generate a channel attention matrix. This is done by following the steps below:
[0153] Step 4.1.1, assuming the input feature map is First, reshape it into a two-dimensional tensor for channel correlation modeling. The dimensionality transformation process is as follows:
[0154]
[0155] Where, Reshape() means flattening the spatial dimension; Transpose(F r ) represents the transposition operation, which is used for subsequent correlation calculation between channels;
[0156] Step 4.1.2: Calculate the channel attention matrix by multiplying FrF_rFr and its transpose FtF_tFt to obtain the inter-channel correlation matrix AAA, which is used to model the relationship between channels. The calculation formula is as follows:
[0157]
[0158] In the formula, the Softmax operation is used to normalize the correlation matrix so that each behavior of the attention matrix is a probability distribution;
[0159] Step 4.2: construct the channel attention response map and enhance the original feature expression;
[0160] In step 4.2, after obtaining the channel attention matrix, it is applied to the original feature map to achieve channel-level feature reweighting and expression enhancement. The specific implementation is as follows:
[0161] Step 4.2.1: Perform weighted fusion of the attention matrix A and the input feature map through matrix multiplication to obtain the attention response map F. a , the calculation formula is as follows:
[0162] F a =A·F r (14)
[0163] Then F a By reshaping back to the original four-dimensional shape:
[0164]
[0165] Step 4.2.2, construct residual connection and introduce learnable scaling factor. In order to enhance the stability and expression flexibility of the model, the residual connection structure is introduced and the learnable scaling factor γ is added. Finally, the feature map F is output. out , the calculation formula is as follows:
[0166] F out =γ·F a ′+F (16)
[0167] Where γ is a learnable parameter initialized to 0 and automatically adjusted through backpropagation; F is the original input feature map in step 4.1. This structure can retain the original information while strengthening the expression of key channels.
[0168] Example 6
[0169] The experimental results, shown in Table 1 below, demonstrate the combined advantages of the proposed lightweight, multi-scale, attention-enhanced detection method for track defects, using the improved YOLOv12 algorithm. On the RIV and DET track defect datasets, the proposed model outperformed mainstream object detection algorithms in metrics such as map and map50. While maintaining extremely low parameter count and computational complexity, the model achieved comprehensive improvements in accuracy, making it particularly suitable for edge computing or embedded track monitoring terminals. The bolded sections in the table represent the best results for each metric.
[0170] Table 1
[0171]
[0172] Based on the improved YOLOv12 algorithm, this paper proposes a lightweight multi-scale target detection method for track defects, constructing a lightweight target detection framework that combines detection accuracy, computational efficiency, and robustness. This not only improves the overall accuracy and real-time performance of track defect detection, but also ensures the efficient operation of the model in resource-constrained scenarios such as mobile terminals and vehicle-mounted terminals.
Claims
1. A multi-scale lightweight detection method for track defects based on the improved YOLOv12 algorithm, characterized by: Please follow the steps below to implement it: Step 1: Build a track disease dataset and model encoder; Step 2: Build a lightweight YOLOv12 convolutional neural network structure; Step 3: Construct a multi-scale feature fusion mechanism; Step 4: Build a channel attention mechanism module.
2. The multi-scale lightweight detection method for track defects based on the improved YOLOv12 algorithm according to claim 1 is characterized in that: The step 1 is specifically implemented according to the following steps: Step 1.1: Collect sample images of different types of track defects, including cracks, missing edges, rust, and foreign matter intrusion; Step 1.2: Label and classify the sample images in step 1.1, determine the precise location and category of the disease in each image, and assign a corresponding label to each disease target; Step 1.3: Divide all labeled samples into training set, validation set, and test set in proportion for model training and evaluation; In step 1.4, we load the pre-trained weight parameters based on the improved YOLOv12 model and build the model encoder to accelerate convergence by leveraging the common features learned by the pre-trained model. In step 1.5, the sample images are uniformly resized to a predetermined input resolution of 640 × 640 pixels and fed into the encoder for feature extraction.
3. The multi-scale lightweight detection method for track defects based on the improved YOLOv12 algorithm according to claim 1 is characterized in that: The step 2 is specifically implemented according to the following steps: Step 2.1: Introduce the lightweight GhostNet module to improve the backbone network of the YOLOv12 model; Step 2.2, applying a lightweight transformation operation to the feature map obtained in step 2.1 to generate a ghost feature map; In step 2.3, the intrinsic convolution features generated in step 2.1 and the ghost features generated in step 2.2 are concatenated and fused in the channel dimension, and then the concatenated fusion features are compressed and linearly transformed through convolution.
4. The multi-scale lightweight detection method for track defects based on the improved YOLOv12 algorithm according to claim 3 is characterized in that: The step 2.1 is specifically implemented according to the following steps: In step 2.1.1, assume an input tensor X with dimensions B×C×H×W, where B represents the batch size, C represents the number of channels of the input feature map, and H and W represent the height and width of the input feature map, respectively. Use the standard convolution operation to extract the main feature map X', as shown in formula (1): X'=σ(BN(Conv k×k (X))) (1) Where, Conv k×k represents the standard convolution operation with a convolution kernel size of k×k, BN is the batch normalization operation, and σ is the activation function; Step 2.1.2, after obtaining the main feature map X′ in step 2.1.1, in order to further generate more feature expressions and reduce computational overhead, a lightweight linear transformation function is introduced to generate a set of ghost feature maps. Let the transformation function be Φ i (·), then the ghost feature map The generation formula is as follows: Among them, s represents the number of linear transformations, Φ i (·) Use channel-by-channel convolution for lightweight operations; Perform splicing operations on all generated ghost feature maps to obtain the final ghost feature map X g , which is calculated as follows: Where Concat represents the concatenation operation in the channel dimension.
5. The multi-scale lightweight detection method for track defects based on the improved YOLOv12 algorithm according to claim 3 is characterized in that: The step 2.2 is specifically implemented as follows: In step 2.2.1, the main feature map X' obtained in step 2.1.1 is used as input and sent to the lightweight linear transformation layer in the Ghost module for context supplementation operation. Let the lightweight convolution kernel be W g , then the feature mapping process can be expressed as: X ghost =σ(BN(W g *X′)) (4) In the formula, * represents the convolution operation; BN is the batch normalization operation; σ is the nonlinear activation function; X ghost The enhanced ghost feature map output in step 2.2; Step 2.2.2, perform spatial position alignment and shape adjustment on the generated ghost feature map. If the main feature map X' is aligned with the ghost feature map X ghost If there is inconsistency in spatial dimensions or channel dimensions, zero padding, upsampling, or 1×1 convolution can be used to match channels to ensure that they can be spliced with the main feature map; Step 2.3 is implemented as follows: Step 2.3.1: Substitute the main feature map X′ obtained in step 2.1.1 into the ghost feature map X generated in step 2.
2. ghost Splicing is performed in the channel dimension to obtain the fused feature map F, and the calculation formula is shown in formula (5): F=Concat(X′,X ghost ) (5) Where Concat represents the channel dimension concatenation operation; Step 2.3.2: In order to match the number of input channels of the subsequent structure of YOLOv12, the concatenated fusion feature F is compressed using 1×1 convolution, and normalized and activated at the same time to obtain the final feature map F. out , the calculation formula is shown in formula (6): F out =σ(BN(Conv 1×1 (F))) (6) Where, Conv 1×1 represents the channel compression convolution kernel; BN is the batch normalization operation; σ is the nonlinear activation function; F out Output tensor for the final compressed fusion feature.
6. The multi-scale lightweight detection method for track defects based on the improved YOLOv12 algorithm according to claim 1 is characterized in that: The step 3 is specifically implemented as follows: Step 3.1, construct a multi-scale feature extraction path; In step 3.2, feature compression and nonlinear mapping are performed on the fused feature map.
7. The multi-scale lightweight detection method for track defects based on the improved YOLOv12 algorithm according to claim 6 is characterized in that: The step 3.1 is specifically implemented as follows: Step 3.1.1, extract multi-scale sub-feature maps Assume the input feature map is Sub-feature maps of different resolutions are extracted through multiple maximum pooling operations. The calculation formula is shown in formula (7): <h2 style=";text-align:left;direction:ltr">F1=F<h2 style=";text-align:left;direction:ltr"> in <h2 style=";text-align:left;direction:ltr"> ,F2=MaxPool(F1),F3=MaxPool(F2) (7) Where F1, F2, and F3 represent the feature maps of 1×, 2×, and 4× downsampling scales, respectively; MaxPool represents the maximum pooling operation with a step size of 2, which extracts semantic information with a larger receptive field; Step 3.1.2: Scale alignment and semantic compensation of sub-feature maps F2 and F3 are upsampled to the same spatial size as F1 using bilinear interpolation, and the channel dimensions are unified through 1×1 convolution. The calculation formula is shown in formula (8): F'2=Conv 1×1 (Upsample(F2)),F'3=Conv 1×1 (Upsample(Upsample(F3))) (8) Where Upsample() is a bilinear upsampling operation, Conv 1×1 Used for channel compression and feature shaping; Step 3.1.3: Construct a multi-scale pyramid structure with channel fusion, concatenate the feature maps of the three scales in the channel dimension, and construct a multi-scale semantic fusion feature map F fused , the calculation formula is shown in formula (9): F fused =Concat(F1,F2′,F3′) (9) Where Concat represents the channel dimension concatenation operation; In order to improve the local area response capability, a multi-branch convolution path is introduced after fusion, and 3×3 and 5×5 convolutions are connected in parallel and then added as a context compensation module.
8. The multi-scale lightweight detection method for track defects based on the improved YOLOv12 algorithm according to claim 6 is characterized in that: The specific step 3.2 is as follows: After the fusion of multi-scale features, the number of channels will increase significantly. In order to avoid information redundancy and improve model efficiency, 1×1 convolution is introduced for channel compression, and normalization and activation functions are introduced to improve nonlinear expression capabilities. The calculation formula is shown below: F out =σ(BN(Conv 1×1 (F fused ))) (10) Where, Conv 1×1 Compress feature channels to ensure network depth and efficiency; BN is batch normalization operation; σ is nonlinear activation function; F out The fused multi-scale feature map is output and fed into the subsequent decoder.
9. The multi-scale lightweight detection method for track defects based on the improved YOLOv12 algorithm according to claim 1 is characterized in that: The step 4 is specifically implemented according to the following steps: Step 4.1, rearrange the feature map and calculate the channel weight; Step 4.2: Construct the channel attention response map and enhance the original feature expression.
10. The multi-scale lightweight detection method for track defects based on the improved YOLOv12 algorithm according to claim 1 is characterized in that: Step 4.1 transforms the input feature map into channel dimensions and spatial dimensions to calculate the correlation between channels and generate a channel attention matrix. The specific implementation is as follows: Step 4.1.1, assuming the input feature map is First, reshape it into a two-dimensional tensor for channel correlation modeling. The dimensionality transformation process is as follows: Where, Reshape() means flattening the spatial dimension; Transpose(F r ) represents the transposition operation, which is used for subsequent correlation calculation between channels; Step 4.1.2: Calculate the channel attention matrix by multiplying FrF_rFr and its transpose FtF_tFt to obtain the inter-channel correlation matrix AAA, which is used to model the relationship between channels. The calculation formula is as follows: In the formula, the Softmax operation is used to normalize the correlation matrix so that each behavior of the attention matrix is a probability distribution; In step 4.2, after obtaining the channel attention matrix, it is applied to the original feature map to achieve channel-level feature reweighting and expression enhancement. The specific implementation is as follows: Step 4.2.1: Perform weighted fusion of the attention matrix A and the input feature map through matrix multiplication to obtain the attention response map F. a , the calculation formula is as follows: F a =A·F r (14) Then F a By reshaping back to the original four-dimensional shape: Step 4.2.2, construct residual connection and introduce learnable scaling factor. In order to enhance the stability and expression flexibility of the model, the residual connection structure is introduced and the learnable scaling factor γ is added. Finally, the feature map F is output. out , the calculation formula is as follows: F out =γ·F a ′+F (16) Where γ is a learnable parameter initialized to 0 and automatically adjusted through backpropagation; F is the original input feature map in step 4.
1. This structure can retain the original information while strengthening the expression of key channels.