A railway track disease detection method and system based on coordinate attention

By optimizing the backbone network and feature fusion mechanism of the railway track defect detection model, and combining multi-scale convolutional attention and perceptual loss function, the problems of insufficient lightweighting and interference resistance in complex backgrounds in existing technologies are solved, and efficient and real-time railway track defect detection is achieved.

CN122156182APending Publication Date: 2026-06-05NAT ENG LAB FOR HIGH SPEED RAILWAY CONSTR +2

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
NAT ENG LAB FOR HIGH SPEED RAILWAY CONSTR
Filing Date
2026-04-08
Publication Date
2026-06-05

AI Technical Summary

Technical Problem

Existing railway track defect detection technologies suffer from insufficient lightweight design, weak multi-scale defect identification capabilities, poor anti-interference capabilities in complex backgrounds, and insufficient fine-grained feature capture, making it difficult to achieve efficient and real-time railway track defect detection.

Method used

We employ a lightweight backbone network based on FasterNet, combined with the MSCAM multi-scale convolutional attention module and the CoordAtt coordinate attention module. Through adaptive pyramid scaling and Mosaic data augmentation, we optimize feature extraction and fusion, and introduce a perceptual loss function to improve the model's multi-scale disease identification accuracy and anti-interference ability in complex backgrounds.

Benefits of technology

It significantly improves the lightweight and real-time performance of railway track defect detection, enhances the accuracy of small-scale defect identification, reduces the false detection rate, strengthens the robustness of the model in complex scenarios, and meets the real-time detection needs of edge devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122156182A_ABST
    Figure CN122156182A_ABST
Patent Text Reader

Abstract

The application discloses a railway track disease detection method based on coordinate attention, comprising the following steps: acquiring a railway track image, performing adaptive pyramid scaling and normalization processing, and expanding a data set based on a Mosaic data enhancement method; adopting a lightweight backbone network based on FasterNet to extract multi-scale features of the railway track image; strengthening disease area related channel features based on an MSCAM multi-scale convolution attention module; connecting a coordinate attention CoordAtt module after the output of the MSCAM multi-scale convolution attention module to form a fused feature enhancement module, and obtaining disease area related channel features after association; fusing a perception loss on the basis of an original loss function of YOLOv8 to form a joint loss function, optimizing disease texture alignment in a deep disease area feature space, and forming enhanced features; inputting the features into a detection head to output disease categories, a bounding box and a confidence, and completing railway track disease detection. The application also discloses a system, an electronic device and a computer readable storage medium.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of railway track defect detection technology, specifically to a railway track defect detection method and system based on coordinate attention. Background Technology

[0002] With the widespread application of high-speed and heavy-haul railways, real-time detection of surface defects on railway tracks has become increasingly critical. Rails are subjected to repeated train loads, weather changes, and track wear over long periods, making them prone to cracks, spalling, corrosion, and other defects. Failure to detect and repair these defects in a timely manner can lead to major safety accidents such as train derailments and track breaks.

[0003] Currently, railway track defect detection mainly relies on three types of technical methods: manual visual inspection, non-destructive testing such as ultrasonic, eddy current, and magnetic flux leakage, and traditional deep learning detection models. Among them, manual visual inspection depends on personnel experience, is easily affected by fatigue and subjective factors, has low efficiency and a high rate of missed detection; non-destructive testing equipment such as ultrasonic, eddy current, and magnetic flux leakage is expensive and time-consuming, making it difficult to meet the needs of long-term continuous real-time monitoring; traditional deep learning detection models have limitations in multi-scale targets, small defects and complex background scenarios, and it is difficult to balance detection accuracy and real-time performance.

[0004] Furthermore, machine vision and deep learning technologies, with their advantages of high efficiency, low cost, and strong integrability, have become the core development direction for railway track defect detection. The technology closely related to this invention is mainly railway track defect target detection technology based on the YOLO series models. The YOLO series models are widely used in the field of target detection due to their fast detection speed and high accuracy. However, there is insufficient dedicated optimization for railway track defect detection, and they still face problems such as weak small defect recognition ability, poor anti-interference in complex backgrounds, and a large number of model parameters. Specifically, existing YOLO-based railway track defect detection technologies mostly directly use basic models such as YOLOv8n. This technology uses YOLOv8n as the basic detection model, and the overall process includes five stages: image input, feature extraction, feature fusion, detection head inference, and result output. The specific implementation methods of the latter four stages include:

[0005] (1) Feature extraction: The backbone network composed of traditional C2f modules is used to extract multi-scale features of railway track images through continuous convolution and pooling operations, without introducing lightweight design or attention mechanism;

[0006] (2) Feature fusion: Multi-scale feature aggregation was performed using the SPPF module. Feature fusion was achieved only through simple channel splicing and upsampling, without optimizing the fusion weights for the scale differences of railway track defects.

[0007] (3) Loss function: The default joint loss function of YOLOv8 is used, which is the weighted sum of classification loss, bounding box regression loss and distribution focus loss. The formula is as follows:

[0008] In the formula: , , These are the weighting coefficients for the three types of loss. For classifying losses, For bounding box regression loss, For distribution focus loss;

[0009] (4) Inference output: Perform bounding box prediction and category determination on the fused feature map, and output the location, category and confidence information of the disease.

[0010] In summary, existing railway track defect detection technologies suffer from several prominent problems: traditional detection methods are inefficient and costly, failing to meet the needs of large-scale, rapid inspections along high-density railway lines; traditional YOLO models have a large number of parameters, making real-time inference difficult on resource-constrained equipment; small-scale defect features are not obvious and are easily interfered with by complex backgrounds, leading to high rates of missed and false detections; the models lack adaptability to complex textures and noise on railway track surfaces, and their robustness needs improvement, primarily in the following aspects:

[0011] (1) Existing YOLO models use traditional backbone networks, which have a large number of parameters and computational load. Even the lightweight version still cannot meet the requirements of large-scale real-time detection when processing high-speed acquired railway track images. In addition, some models sacrifice feature representation ability in pursuit of speed.

[0012] (2) There is little information on small-scale defects such as microcracks and fine corrosion spots in railway tracks. The feature extraction network of the traditional YOLO model is not good at capturing small target features and the multi-scale fusion mechanism is not perfect, resulting in a high rate of missed detection of small defects and generally low mAP values.

[0013] (3) The surface texture of railway tracks is complex and there is noise such as oil stains and rust. Traditional models lack an effective attention guidance mechanism, cannot accurately focus on the diseased area, are easily affected by background interference, and have a high false detection rate.

[0014] (4) The loss function of the existing model mainly optimizes the classification accuracy and bounding box regression accuracy, but it does not adequately constrain fine-grained features such as disease texture and edges, resulting in limited ability of the model to distinguish similar diseases from noise and poor detection robustness.

[0015] In accordance with the overall requirements of the intelligent transformation of railway operation and maintenance, railway track defect detection technology is developing towards "lightweight, multi-scale, high precision, and real-time." Future trends mainly focus on the following aspects: optimizing model structure to improve feature representation capabilities while reducing the number of parameters and computational load, adapting to resource-constrained edge computing scenarios; introducing attention mechanisms and multi-scale feature fusion technology to enhance the identification ability of small defects and narrow cracks; combining optimization methods such as perceptual loss to improve the robustness of the model under complex textures and noise interference; and achieving deep integration of the model and detection equipment to meet the real-time detection needs of high-speed railways. Therefore, the railway industry needs a lightweight, high-precision, and real-time railway track defect detection technology capable of accurately identifying various railway track defects, especially small-scale defects, in complex scenarios, while meeting the deployment requirements of edge equipment. This technology can significantly improve railway track inspection efficiency, reduce operation and maintenance costs, and ensure the safety and economy of railway transportation, possessing broad market application prospects. Summary of the Invention

[0016] The purpose of this invention is to overcome the shortcomings of existing technologies and provide a railway track defect detection method and system based on coordinate attention. Addressing the problems of insufficient lightweight design, weak multi-scale defect recognition capability, poor anti-interference performance in complex backgrounds, and insufficient fine-grained feature capture in existing YOLO-based railway track defect detection technologies, this invention focuses on solving the following four key technical challenges: First, how to optimize the model backbone network to reduce the number of parameters and computational load while ensuring feature representation capability, enabling real-time inference on resource-constrained devices; Second, how to design an effective multi-scale feature fusion and attention mechanism to enhance feature extraction for small-scale defects and improve the accuracy of multi-scale defect recognition; Third, how to suppress background interference such as railway track surface texture and noise through the attention mechanism, accurately focusing on defect areas and reducing false detection rates; and Fourth, how to introduce perceptual loss to align fine-grained features such as defect textures and edges in the deep feature space, improving the model's robustness in recognizing complex-shaped defects.

[0017] The first aspect of this invention is to provide a railway track defect detection method based on coordinate attention, comprising:

[0018] S1, acquire railway track images, perform adaptive pyramid scaling and normalization processing on the railway track images, and expand the dataset based on the Mosaic data augmentation method;

[0019] S2 employs a lightweight backbone network based on FasterNet to extract multi-scale features from the railway track image through grouped convolution and depthwise separable convolution.

[0020] S3, based on the MSCAM multi-scale convolutional attention module, enhances the relevant channel features of the diseased area and suppresses background interference;

[0021] S4, after the output of the MSCAM multi-scale convolutional attention module, the coordinate attention CoordAtt module is connected to form a fused feature enhancement module, thereby further strengthening the spatial-channel association of the disease area based on the feature enhancement module, and obtaining the associated channel features of the disease area.

[0022] S5, on the basis of the original loss function of YOLOv8, the perceptual loss is fused to form a joint loss function. The joint loss function is used to optimize the disease texture alignment in the feature space of deep disease areas to form enhanced features.

[0023] S6. Input the enhanced features into the detection head and output the defect category, bounding box and confidence level to complete the railway track defect detection.

[0024] Preferably, S1 includes:

[0025] S11, acquire railway track image;

[0026] S12, Construct a lightweight backbone network model based on FasterNet, and set the training and inference parameters for the model. The training parameters of the model are set as follows: epoch=300, batch size=16. The inference parameters of the model are set as follows: SGD optimizer, initial learning rate lr0=0.01, learning rate decay factor lrf=0.01, warm-up epoch=3.0.

[0027] S13, perform adaptive pyramid scaling and normalization processing on the railway track image, wherein the confidence threshold is adjusted according to the actual scene and is set to 0.5 by default;

[0028] S14, set the mosaic iteration count to 10, and expand the dataset based on the Mosaic data augmentation method.

[0029] Preferably, the lightweight backbone network based on FasterNet uses FasterNet as its backbone network. The network structure of the lightweight backbone network based on FasterNet consists of an embedding layer, multiple FasterNet Blocks, and a merging layer, forming a four-stage feature pyramid. Through the coordinated operation of partial convolution and pointwise convolution, spatial convolution is performed only on a subset of the input channels, while the remaining channels are identically mapped. The FasterNet Block of the lightweight backbone network adopts a T-shaped convolution structure, containing one partial convolution layer and two pointwise convolution layers, forming an inverted residual structure. The embedding layer uses 4×4 convolution, and the merging layer uses 2×2 convolution, progressively downsampling and expanding the number of channels.

[0030] Preferably, the MSCAM multi-scale convolutional attention module is a serial MSCAM module, comprising a CAB channel attention block, a SAB spatial attention block, and an MSCB multi-scale convolutional block. The CAB channel attention block enhances disease-related channel features, the SAB spatial attention block focuses on the spatial region of the disease, and the MSCB multi-scale convolutional block extracts and fuses multi-scale features through parallel convolutional kernels of different sizes, while introducing channel shuffling to promote information exchange. The CAB channel attention block generates a channel weight map through adaptive max pooling, average pooling, and 1×1 convolution. The SAB spatial attention block generates a spatial weight map through channel-dimensional pooling and 7×7 convolution. The MSCB multi-scale convolutional block uses 1×1, 3×3, and 5×5 parallel depthwise separable convolutions, fuses features through channel shuffling and 1×1 convolution, and adds residual connections. This module is integrated into the feature extraction stage to enhance multi-scale disease features and suppress background interference.

[0031] Preferably, in step S4, the MSCAM module outputs features that are compressed by average pooling along the x and y axes. Then, a spatial weight map is generated through splicing, convolution, and separation operations. This map is then multiplied element-wise with the original feature map to achieve feature weighting. This module is integrated into the feature extraction stage to synergistically enhance multi-scale features and spatial positioning accuracy.

[0032] Preferably, the CoordAtt module enhances the interaction between space and channel by embedding position information into the channel attention. Specific operations include:

[0033] S41, perform feature compression, including: average pooling the output feature map of the MSCAM multi-scale convolutional attention module along the x-axis and y-axis respectively to obtain two 1D feature maps, capturing the dependencies across spatial dimensions;

[0034] S42, performing feature fusion and transformation, including: concatenating two 1D feature maps to perform the feature fusion, compressing the channel dimension through 1×1 convolution, and performing the transformation through batch normalization and non-linear activation function to obtain the fused feature map, thereby enhancing feature representation;

[0035] S43, perform feature separation and generate weights, including: separating the fused feature map into two 1D feature maps with the same number of input channels, and generating a spatial weight map through the Sigmoid activation function;

[0036] S44, Perform feature weighting, including: multiplying the generated spatial weight map element by element with the original input feature map to achieve precise focusing on the diseased area;

[0037] The calculation formula for the CoordAtt module is shown in equation (4).

[0038] (4);

[0039] in, , These are average pooling operations along the x-axis and y-axis, respectively. For feature separation operation, This is element-wise multiplication.

[0040] Preferably, the total loss value of the original YOLOv8 loss function As shown in equation (5), the following calculation is obtained: (5);

[0041] in, This represents the total loss value of the original loss function, which is the weighted sum of the classification loss, bounding box loss, and distribution loss. The smaller the total loss value, the more accurate the model prediction. This represents the classification loss, used to measure the error of the model in predicting the target class; The weight coefficients representing the classification loss are hyperparameters used to adjust the importance of the classification loss in the total loss. The bounding box loss measures the overlap error between the model's predicted target box and the ground truth box. The weight coefficients representing the bounding box loss are hyperparameters, and their values ​​range from... Larger; This represents the distributed loss, used to optimize the prediction accuracy of bounding box coordinates for anchor-free designs in the YOLO series, thereby making coordinate prediction more accurate. The weighting coefficients represent the distributed loss and are hyperparameters used to adjust the contribution of the distributed loss.

[0042] The perceptual loss employs RoIAlign-based technology to sample prediction boxes on deep feature maps of the backbone network. With real frame The corresponding feature regions are obtained by calculating the Euclidean distance between them in the deep feature space; the perceptual loss is obtained. The calculation formula is shown in equation (6): (6);

[0043] in, For deep feature mapping function, and For the width and height of the feature patch, Representing the prediction box respectively or real frame The corresponding feature regions have their x and y coordinates in the deep feature space;

[0044] The joint loss function The calculation formula is shown in equation (7):

[0045] (7);

[0046] in, The perceptual loss weights are used to balance the detection task and the feature alignment task.

[0047] A second aspect of the present invention provides a railway track defect detection system based on coordinate attention, for implementing the method of the first aspect, comprising:

[0048] The image acquisition module (101) is used to acquire railway track images, perform adaptive pyramid scaling and normalization processing on the railway track images, and expand the dataset based on the Mosaic data augmentation method;

[0049] The multi-scale feature extraction module (102) is used to extract multi-scale features of the railway track image by using a lightweight backbone network based on FasterNet through grouped convolution and depthwise separable convolution.

[0050] The feature enhancement module (103) is used to enhance the relevant channel features of the disease area based on the MSCAM multi-scale convolutional attention module and suppress background interference;

[0051] The feature fusion enhancement module (104) is used to connect the coordinate attention CoordAtt module after the output of the MSCAM multi-scale convolutional attention module to form a fused feature enhancement module, thereby further strengthening the spatial-channel association of the disease area based on the feature enhancement module and obtaining the associated channel features of the disease area.

[0052] The joint loss function module (105) is used to fuse perceptual loss on the basis of the original loss function of YOLOv8 to form a joint loss function. The joint loss function is used to optimize the alignment of disease texture in the feature space of deep disease area to form enhanced features.

[0053] The track defect detection module (106) is used to input the enhanced features into the detection head, output the defect category, bounding box and confidence level, and complete the railway track defect detection.

[0054] A third aspect of the present invention provides an electronic device including a processor and a memory, the memory storing a plurality of instructions, the processor being configured to read the instructions and execute the method as described in the first aspect.

[0055] A fourth aspect of the present invention provides a computer-readable storage medium storing a plurality of instructions which can be read by a processor and executed as described in the first aspect.

[0056] The beneficial effects of the method and system of the present invention are as follows:

[0057] (1) Significantly improved lightweighting and real-time performance. In the existing technology, the traditional YOLO model uses a conventional backbone network, which has a large number of parameters and computational redundancy, and the inference frame rate is difficult to meet the real-time detection requirements of edge devices. The present invention uses the FasterNet lightweight backbone network, which reduces computational redundancy through partial convolution and pointwise convolution. While ensuring feature representation ability, it significantly improves real-time performance and is suitable for resource-constrained edge computing scenarios.

[0058] (2) The accuracy of multi-scale disease identification is greatly improved. In the existing technology, the traditional YOLO model lacks an effective multi-scale feature fusion and attention mechanism, and has a weak ability to identify small-scale diseases. This invention introduces the MSCAM multi-scale convolutional attention module to strengthen multi-scale feature extraction and disease region focusing, significantly improve the accuracy of small-scale disease identification, and solve the problem of imbalance in multi-scale target detection.

[0059] (3) Stronger anti-interference capability against complex backgrounds. In the existing technology, traditional models are not good at suppressing background interference such as railway track surface texture and noise, which easily leads to false detection and missed detection. The MSCAM module of the present invention accurately focuses on the defect area through the synergistic effect of channel attention and spatial attention, effectively suppressing background interference. At the same time, the perceptual loss strengthens fine-grained feature constraints, improves the model's adaptability to complex scenes, and significantly reduces the false detection rate.

[0060] (4) The model has better robustness. In the existing technology, the traditional loss function only focuses on classification and bounding box regression, which is insufficient for constraining the fine-grained features of the disease. The model has poor robustness under complex textures and noise interference. The present invention integrates perceptual loss and aligns the fine-grained features such as disease texture and edges in the deep feature space, so that the model can accurately distinguish between disease and noise and maintain stable detection performance under different lighting and complex texture scenes, and the robustness is significantly improved. Attached Figure Description

[0061] To more clearly illustrate the technical solutions in the specific embodiments or related technologies of the present invention, the drawings used in the description of the specific embodiments or related technologies will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0062] Figure 1 This is a flowchart of a railway track defect detection method based on coordinate attention according to an embodiment of the present invention;

[0063] Figure 2 This is a schematic diagram of the railway track defect detection system based on coordinate attention provided in an embodiment of the present invention.

[0064] Figure 3 This is a schematic diagram illustrating the relationship between the railway track defect detection method and system based on coordinate attention provided in an embodiment of the present invention.

[0065] Figure 4 This is a structural diagram of an electronic device provided according to an embodiment of the present invention. Detailed Implementation

[0066] The technical solution of the present invention will now be clearly and completely described with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0067] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0068] In the description of this invention, it should be noted that, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances.

[0069] The overall objective of this embodiment is to provide a railway track defect detection method based on FasterNet-MSCAM-YOLO. Through in-depth optimization of the YOLO model, it achieves lightweight, high-precision, and real-time detection of railway track defects.

[0070] Specific technical objectives include: First, optimizing the model backbone network to significantly reduce the number of parameters and meet the deployment requirements of edge devices; Second, strengthening the extraction of small disease features through multi-scale convolutional attention modules; Third, suppressing background interference to control the false detection rate at a low level and improve the model's adaptability under different lighting and noise conditions; and Fourth, improving the model's ability to recognize disease textures and edges through perceptual loss optimization, and accurately distinguishing diseases from noise.

[0071] Example 1

[0072] like Figure 1 As shown, this embodiment provides a railway track defect detection method based on coordinate attention, including:

[0073] S1, acquire railway track images, perform adaptive pyramid scaling and normalization processing on the railway track images, and expand the dataset based on the Mosaic data augmentation method;

[0074] In a preferred embodiment, S1 includes:

[0075] S11, acquire railway track image;

[0076] S12, Construct a lightweight backbone network model based on FasterNet, and set the training and inference parameters for the model. The training parameters are set as follows: epoch=300, batch size=16, SGD optimizer, initial learning rate lr0=0.01, and learning rate decay factor. Warm-up epoch = 3.0;

[0077] S13, perform adaptive pyramid scaling and normalization processing on the railway track image, wherein the confidence threshold is adjusted according to the actual scene and is set to 0.5 by default.

[0078] The confidence threshold (default 0.5) is a filtering parameter used in the image preprocessing stage. In the adaptive pyramid scaling and normalization process, it mainly serves two core functions: the first is the effective region filtering function, which assigns a "confidence score" (0~1) to the track areas (such as rails, sleepers, and fasteners) in the railway track image after preliminary detection, retaining only areas with a score ≥ the threshold (default 0.5) as effective target areas, and filtering out background noise (such as weeds, gravel, billboards, and other irrelevant areas beside the track); the second is the adaptive scaling trigger function, which dynamically adjusts the pyramid scaling level according to the confidence score - for the core track areas with high confidence (such as ≥0.8), higher resolution scaling is used (preserving details); for areas with medium confidence (0.5~0.8), basic resolution scaling is used; for areas with confidence below the threshold, fine scaling is skipped directly, and only normalization is performed. Its technical functions (railway scene adaptation) include: (1) reducing invalid calculation costs: the background ratio in railway track images is high (such as the sky and mountains of the track in the field). By filtering low confidence background areas with a default threshold of 0.5, redundant scaling / normalization processing of irrelevant areas is avoided, and the preprocessing efficiency is improved; (2) ensuring the accuracy of key areas: the confidence scores of core detection targets such as track fasteners and cracks are usually high. Threshold screening can prioritize the scaling accuracy of these areas, providing high-quality image data for subsequent defect detection and track status analysis; (3) adapting to the flexibility of actual scenes: the noise level of images in different scenes (such as high-speed rail track / ordinary rail track, daytime / nighttime, sunny / rainy days) is different. For example, the confidence of the track area in rainy day images is easy to be low, so the threshold can be lowered to 0.3; the background noise in the strong light scene at night is high, so the threshold can be raised to 0.7 to ensure that the preprocessing effect is adapted to the on-site environment.

[0079] S14, set the mosaic iteration count to 10, and expand the dataset based on the Mosaic data augmentation method.

[0080] The number of mosaic iterations is the execution control parameter for Mosaic data augmentation. The core functions include: First, the augmentation number control function, which defines the number of loop executions for Mosaic augmentation (10 times in this case). Each iteration randomly selects 4 different railway track images, cropping and stitching them into a new "mosaic image". Second, the dataset expansion scale function, where the number of iterations directly determines the size of the expanded dataset. If the original railway track dataset has N images, 10 iterations can generate 10×N augmented images (this needs to be combined with deduplication logic, and the actual expansion scale is about 8 to 10 times). The technical role of the number of mosaic iterations (for railway scene adaptation) includes: (1) Expanding the small sample dataset: The samples of railway track defects (such as rail cracks and missing fasteners) are usually scarce. 10 iterations can quickly expand the number of defect samples, solve the problem of "imbalanced samples" during model training, and improve the model's ability to detect rare defects; (2) Improving the model's generalization: Each mosaic stitching will randomly combine different track scenes (such as different sections, different lighting, and different defect types). 10 iterations can cover more combination patterns of track images, allowing the model to learn more comprehensive track features and avoid overfitting (such as only recognizing cracks in a certain section and not being able to recognize other sections); (3) Balancing the enhancement effect and computational cost: The number of iterations is not necessarily better the more there are - too few iterations (such as <5) will result in insufficient enhancement effect, and too many iterations (such as >20) will lead to data redundancy and double the training time; setting it to 10 iterations is the "optimal value for cost-effectiveness" in railway track scenes: it ensures that the dataset is expanded to a sufficient scale, while controlling the time cost of preprocessing and training, which meets the efficiency requirements for engineering implementation.

[0081] The settings of these two parameters are both centered around the "engineering implementation of railway track image processing": the confidence threshold focuses on "preprocessing accuracy + efficiency", and the number of mosaic iterations focuses on "dataset quality + training effect", ultimately serving to improve model performance for core tasks such as railway track defect detection and condition analysis.

[0082] S2 employs a lightweight backbone network based on FasterNet to extract multi-scale features from the railway track image through grouped convolution and depthwise separable convolution.

[0083] In a preferred embodiment, the lightweight backbone network based on FasterNet uses FasterNet as its backbone network. The network structure of this lightweight backbone network consists of an embedding layer, multiple FasterNetBlocks, and a merging layer, forming a four-stage feature pyramid. Through the coordinated operation of partial convolution and pointwise convolution, spatial convolution is performed only on a subset of the input channels, while the remaining channels are mapped identically, reducing computational redundancy. The FasterNet Block of the lightweight backbone network adopts a "T"-shaped convolutional structure, containing one partial convolutional layer (PConv layer) and two pointwise convolutional layers (PWConv layers), forming an inverted residual structure. An identity shortcut ensures stable gradient propagation, while the four-stage feature pyramid is constructed through the embedding and merging layers. The embedding layer uses 4×4 convolution (stride 4), and the merging layer uses 2×2 convolution (stride 2), constructing the four-stage feature pyramid, progressively downsampling and expanding the number of channels. The coordinated operation of partial and pointwise convolution reduces computational redundancy, achieving lightweight feature extraction.

[0084] By employing a lightweight backbone network based on FasterNet, multi-scale features of the railway track images are extracted through grouped convolution and depthwise separable convolution. This significantly reduces the number of model parameters and computational load while ensuring feature representation capabilities, providing support for real-time inference. The inference frame rate is increased to 142 FPS, meeting the real-time detection requirements of edge devices and solving the problem of balancing lightweight and real-time performance in traditional models.

[0085] S3, based on the MSCAM multi-scale convolutional attention module, enhances the relevant channel features of the diseased area and suppresses background interference;

[0086] In a preferred embodiment, the MSCAM multi-scale convolutional attention module is a serial MSCAM module, comprising a CAB channel attention block, a SAB spatial attention block, and an MSCB multi-scale convolutional block. The CAB channel attention block is used to enhance disease-related channel features, the SAB spatial attention block is used to focus on disease spatial regions, and the MSCB multi-scale convolutional block is used to extract and fuse multi-scale features through parallel convolutional kernels of different sizes, while also introducing channel shuffling to promote information exchange.

[0087] In this embodiment, the design of the MSCAM multi-scale convolutional attention module includes: MSCAM sequentially concatenating CAB channel attention blocks, SAB spatial attention blocks, and MSCB multi-scale convolutional blocks. The CAB channel attention block generates channel weight maps through adaptive max pooling, average pooling, and 1×1 convolution; the SAB spatial attention block generates spatial weight maps through channel-dimensional pooling and 7×7 convolution; the MSCB multi-scale convolutional block uses 1×1, 3×3, and 5×5 parallel depthwise separable convolutions, fuses features through channel shuffling and 1×1 convolution, and adds residual connections; this module is integrated into the feature extraction stage to enhance multi-scale disease features and suppress background interference.

[0088] The structure and operation are as follows:

[0089] The CAB channel attention block is used to perform adaptive max pooling and average pooling on the input feature map to generate channel-level descriptors. Then, it is compressed through two 1×1 convolution layers and the channel dimension is restored through the Sigmoid activation function to generate channel weight maps. Strengthen the characteristics of channels related to the diseased area; wherein, the calculation formula of the CAB channel attention block is shown in formula (1):

[0090] (1)

[0091] in, The Sigmoid activation function is used. These are max pooling and average pooling operations, respectively.

[0092] SAB spatial attention blocks are used to process the CAB output feature map along the recovered channel dimension. After performing max pooling and average pooling to obtain a single-channel spatial descriptor, a 7×7 convolution is used to capture spatial dependencies and generate a spatial weight map. Thus, the focus is on the diseased area; the calculation formula for the SAB spatial attention block is shown in formula (2):

[0093] (2);

[0094] in, , These are the max pooling and average pooling operations for the channel dimension, respectively.

[0095] The MSCB multi-scale convolutional blocks employ parallel depthwise separable convolutions of 1×1, 3×3, and 5×5. Multi-scale features are extracted, and cross-group information exchange is promoted by introducing channel shuffling. The features are then fused by 1×1 convolution and residual connections are added. And obtain and fuse the extracted and fused multi-scale features. The calculation formula for the MSCB multi-scale convolutional block is shown in equation (3):

[0096] (3);

[0097] in, For batch normalization, Shuffling operation for the channel.

[0098] The MSCAM multi-scale convolutional attention module in step S3 is used to enhance the feature extraction of small-scale diseases, strengthen the expression of multi-scale disease features, suppress background interference, and improve the ability to identify small diseases, effectively solving the problems of weak multi-scale disease identification ability and poor anti-interference in complex backgrounds.

[0099] S4, after the output of the MSCAM multi-scale convolutional attention module, the coordinate attention CoordAtt module is connected to form a fused feature enhancement module, thereby further strengthening the spatial-channel association of the disease area based on the feature enhancement module, and obtaining the associated channel features of the disease area.

[0100] In this embodiment, the MSCAM module outputs features that are compressed by average pooling along the x and y axes. Then, a spatial weight map is generated through splicing, convolution, and separation operations. This map is then multiplied element-wise with the original feature map to achieve feature weighting. This module is integrated into the feature extraction stage to synergistically enhance multi-scale features and spatial positioning accuracy.

[0101] In a preferred embodiment, in step S4, the CoordAtt module enhances the interaction between space and channel by embedding position information into the channel attention. The specific operation is as follows:

[0102] S41, perform feature compression, including: average pooling the output feature map of the MSCAM multi-scale convolutional attention module along the x-axis and y-axis respectively to obtain two 1D feature maps, capturing the dependencies across spatial dimensions;

[0103] S42, performing feature fusion and transformation, including: concatenating two 1D feature maps to perform the feature fusion, compressing the channel dimension through 1×1 convolution, and performing the transformation through batch normalization and non-linear activation function to obtain the fused feature map, thereby enhancing feature representation;

[0104] S43, perform feature separation and generate weights, including: separating the fused feature map into two 1D feature maps with the same number of input channels, and generating a spatial weight map through the Sigmoid activation function;

[0105] S44, Perform feature weighting, including: multiplying the generated spatial weight map element by element with the original input feature map to achieve precise focusing on the diseased area;

[0106] The calculation formula for the CoordAtt module is shown in equation (4):

[0107] (4);

[0108] in, , These are average pooling operations along the x-axis and y-axis, respectively. For feature separation operation, This is element-wise multiplication.

[0109] The implementation of step S4 can further improve the model's spatial positioning accuracy for small-scale diseases, enhance the ability to distinguish features in complex backgrounds, and reduce the false detection rate.

[0110] In a preferred embodiment, S4 includes: following the MSCAM multi-scale convolutional attention module, a coordinate attention CoordAtt module is connected in series. By compressing, fusing and generating weights along the coordinate axes, the spatial-channel association of the disease area is strengthened, making up for the shortcomings of the single attention mechanism in spatial positioning. This improves the accuracy of small-scale disease positioning by associating the relevant channel features of the disease area, accurately focusing on the spatial location of the disease, further suppressing background interference such as track surface texture and noise, and improving the mAP value of small-scale disease identification by more than 3%, thus significantly enhancing the robustness of the model.

[0111] S5, on the basis of the original loss function of YOLOv8, the perceptual loss is fused to form a joint loss function. The joint loss function is used to optimize the disease texture alignment in the feature space of deep disease areas to form enhanced features.

[0112] As a preferred embodiment, the total loss value of the original YOLOv8 loss function As shown in equation (5), the following calculation is obtained:

[0113] (5);

[0114] in, This represents the total loss value of the original loss function, which is the weighted sum of the classification loss, bounding box loss, and distribution loss. The smaller the total loss value, the more accurate the model prediction. This represents the classification loss, used to measure the error of the model in predicting the target class; The weight coefficients representing the classification loss are hyperparameters used to adjust the importance of the classification loss in the total loss. The bounding box loss measures the error in the overlap between the model's predicted target box (position and size) and the ground truth box. It is more than A superior metric that takes into account the overlap area of ​​the frames, the distance between the center points, and the aspect ratio; The weight coefficients representing the bounding box loss are hyperparameters, typically set to values ​​higher than those of the bounding box loss. Larger because bounding box prediction is more critical to the detection results; This represents the distributed loss, used to optimize the prediction accuracy of bounding box coordinates for anchor-free designs in the YOLO series, thereby making coordinate prediction more accurate. The weighting coefficients represent the distributed loss and are hyperparameters used to adjust the contribution of the distributed loss.

[0115] In this embodiment, the preferred value is: , , .

[0116] In a preferred embodiment, the perceptual loss employs RoIAlign-based technology to sample predicted bounding boxes on the deep feature map of the backbone network. With real frame The corresponding feature regions are obtained by calculating the Euclidean distance between them in the deep feature space; the perceptual loss is obtained. The calculation formula is shown in equation (6):

[0117] (6);

[0118] in, For deep feature mapping function, and For the width and height of the feature patch, Representing the prediction box respectively or real frame The corresponding feature regions have their x and y coordinates in the deep feature space;

[0119] As a preferred implementation, the joint loss function The calculation formula is shown in equation (7):

[0120] (7);

[0121] in, The perceptual loss weights are used to balance the detection task and the feature alignment task.

[0122] Based on the original loss function of YOLOv8, a perceptual loss is introduced. The deep feature regions of the predicted box and the ground truth box are aligned through RoIAlign technology, and the Euclidean distance between the two is calculated to construct a joint loss function. The joint loss function can strengthen the fine-grained feature constraints of the disease, improve the model's ability to recognize fine-grained features such as disease texture and edges, enhance the robustness of the model under complex texture and noise interference, improve the robustness of the model to recognize complex morphological diseases, effectively distinguish diseases from noise, and further reduce the false detection rate.

[0123] S6. Input the enhanced features into the detection head and output the defect category, bounding box and confidence level to complete the railway track defect detection.

[0124] This method achieves lightweight, high-precision, and real-time detection of railway track defects by optimizing the backbone network, introducing a multi-scale convolutional attention module, and perceptual loss.

[0125] Example 2

[0126] like Figure 2-3 As shown, this embodiment also provides a railway track defect detection system based on coordinate attention, used to implement the method of Embodiment 1, including:

[0127] The image acquisition module 101 is used to acquire railway track images, perform adaptive pyramid scaling and normalization processing on the railway track images, and expand the dataset based on the Mosaic data augmentation method.

[0128] The multi-scale feature extraction module 102 is used to extract multi-scale features of the railway track image by employing a lightweight backbone network based on FasterNet through grouped convolution and depthwise separable convolution.

[0129] Feature enhancement module 103 is used to enhance the relevant channel features of the disease area and suppress background interference based on the MSCAM multi-scale convolutional attention module;

[0130] The feature fusion enhancement module 104 is used to connect the coordinate attention CoordAtt module after the output of the MSCAM multi-scale convolutional attention module to form a fused feature enhancement module, thereby further strengthening the spatial-channel association of the disease area based on the feature enhancement module and obtaining the associated channel features of the disease area.

[0131] The joint loss function module 105 is used to fuse perceptual loss on the basis of the original loss function of YOLOv8 to form a joint loss function. The joint loss function is used to optimize the alignment of disease texture in the feature space of deep disease areas to form enhanced features.

[0132] The track defect detection module 106 is used to input the enhanced features into the detection head, output the defect category, bounding box and confidence level, and complete the railway track defect detection.

[0133] The present invention also provides a memory that stores multiple instructions for implementing the method as described in Embodiment 1.

[0134] like Figure 4 As shown, the present invention also provides an electronic device, including a processor 301 and a memory 302 connected to the processor 301. The memory 302 stores a plurality of instructions, which can be loaded and executed by the processor to enable the processor to perform methods as described in Embodiments 2 and 3.

[0135] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for detecting railway track defects based on coordinate attention, characterized in that, include: S1, acquire railway track images, perform adaptive pyramid scaling and normalization processing on the railway track images, and expand the dataset based on the Mosaic data augmentation method; S2 employs a lightweight backbone network based on FasterNet to extract multi-scale features from the railway track image through grouped convolution and depthwise separable convolution. S3, based on the MSCAM multi-scale convolutional attention module, enhances the relevant channel features of the diseased area and suppresses background interference; S4, after the output of the MSCAM multi-scale convolutional attention module, the coordinate attention CoordAtt module is connected to form a fused feature enhancement module, thereby further strengthening the spatial-channel association of the disease area based on the feature enhancement module, and obtaining the associated channel features of the disease area. S5, on the basis of the original loss function of YOLOv8, the perceptual loss is fused to form a joint loss function. The joint loss function is used to optimize the disease texture alignment in the feature space of deep disease areas to form enhanced features. S6. Input the enhanced features into the detection head and output the defect category, bounding box and confidence level to complete the railway track defect detection.

2. The railway track defect detection method based on coordinate attention according to claim 1, characterized in that, include: S1 includes: S11, acquire railway track image; S12, Construct a lightweight backbone network model based on FasterNet, and set the training and inference parameters for the model. The training parameters of the model are set as follows: epoch=300, batch size=16. The inference parameters of the model are set as follows: SGD optimizer, initial learning rate lr0=0.01, learning rate decay factor lrf=0.01, warm-up epoch=3.

0. S13, perform adaptive pyramid scaling and normalization processing on the railway track image, wherein the confidence threshold is adjusted according to the actual scene and is set to 0.5 by default; S14, set the mosaic iteration count to 10, and expand the dataset based on the Mosaic data augmentation method.

3. The railway track defect detection method based on coordinate attention according to claim 2, characterized in that, The lightweight backbone network based on FasterNet uses FasterNet as its backbone network. The network structure of the lightweight backbone network based on FasterNet consists of an embedding layer, multiple FasterNet Blocks, and a merging layer, forming a four-stage feature pyramid. Through the coordinated operation of partial convolution and pointwise convolution, spatial convolution is performed only on a subset of the input channels, while the remaining channels are identically mapped. The FasterNet Block of the lightweight backbone network adopts a T-shaped convolution structure, which includes one partial convolution layer and two pointwise convolution layers to form an inverted residual structure. The embedding layer uses 4×4 convolution, and the merging layer uses 2×2 convolution, progressively downsampling and expanding the number of channels.

4. The railway track defect detection method based on coordinate attention according to claim 3, characterized in that, The MSCAM multi-scale convolutional attention module is a serial MSCAM module, comprising a CAB channel attention block, a SAB spatial attention block, and an MSCB multi-scale convolutional block. The CAB channel attention block enhances disease-related channel features, the SAB spatial attention block focuses on disease spatial regions, and the MSCB multi-scale convolutional block extracts and fuses multi-scale features using parallel convolutional kernels of different sizes, while introducing channel shuffling to promote information exchange. The CAB channel attention block generates channel weight maps using adaptive max pooling, average pooling, and 1×1 convolutions. The SAB spatial attention block generates spatial weight maps using channel-dimensional pooling and 7×7 convolutions. The MSCB multi-scale convolutional block employs 1×1, 3×3, and 5×5 parallel depthwise separable convolutions, fuses features through channel shuffling and 1×1 convolutions, and adds residual connections. This module is integrated into the feature extraction stage, enhancing multi-scale disease features and suppressing background interference.

5. The railway track defect detection method based on coordinate attention according to claim 4, characterized in that, In S4, the MSCAM module outputs features that are compressed by average pooling along the x and y axes. Then, a spatial weight map is generated through splicing, convolution, and separation operations. This map is then multiplied element-wise with the original feature map to achieve feature weighting. This module is integrated into the feature extraction stage to synergistically enhance multi-scale features and spatial positioning accuracy.

6. The railway track defect detection method based on coordinate attention according to claim 5, characterized in that, The CoordAtt module enhances the interaction between space and channels by embedding position information into channel attention. Specific operations include: S41, perform feature compression, including: average pooling the output feature map of the MSCAM multi-scale convolutional attention module along the x-axis and y-axis respectively to obtain two 1D feature maps, capturing the dependencies across spatial dimensions; S42, performing feature fusion and transformation, including: concatenating two 1D feature maps to perform the feature fusion, compressing the channel dimension through 1×1 convolution, and performing the transformation through batch normalization and non-linear activation function to obtain the fused feature map, thereby enhancing feature expression; S43, perform feature separation and generate weights, including: separating the fused feature map into two 1D feature maps with the same number of input channels, and generating a spatial weight map through the Sigmoid activation function; S44, Perform feature weighting, including: multiplying the generated spatial weight map element by element with the original input feature map to achieve precise focusing on the diseased area; The calculation formula for the CoordAtt module is shown in equation (4): (4); in, , These are average pooling operations along the x-axis and y-axis, respectively. For feature separation operation, This is element-wise multiplication.

7. The railway track defect detection method based on coordinate attention according to claim 6, characterized in that, The total loss value of the original YOLOv8 loss function As shown in equation (5), the following calculation is obtained: (5); in, This represents the total loss value of the original loss function, which is the weighted sum of the classification loss, bounding box loss, and distribution loss. The smaller the total loss value, the more accurate the model prediction. This represents the classification loss, used to measure the error of the model in predicting the target class; The weight coefficients representing the classification loss are hyperparameters used to adjust the importance of the classification loss in the total loss. The bounding box loss measures the overlap error between the model's predicted target box and the ground truth box. The weight coefficients representing the bounding box loss are hyperparameters, and their values ​​range from... Larger; This represents the distributed loss, used to optimize the prediction accuracy of bounding box coordinates for anchor-free designs in the YOLO series, thereby making coordinate prediction more accurate. The weighting coefficients represent the distributed loss and are hyperparameters used to adjust the contribution of the distributed loss. The perceptual loss employs RoIAlign-based technology to sample prediction boxes on deep feature maps of the backbone network. With real frame The corresponding feature regions are obtained by calculating the Euclidean distance between them in the deep feature space; the perceptual loss is obtained. The calculation formula is shown in equation (6): (6); in, For deep feature mapping function, and For the width and height of the feature patch, and Representing the prediction box respectively or real frame The corresponding feature regions are represented by their x and y coordinates in the deep feature space; the joint loss function. The calculation formula is shown in equation (7): (7); in, The perceptual loss weights are used to balance the detection task and the feature alignment task.

8. A railway track defect detection system based on coordinate attention, used to implement the method according to any one of claims 1-7, characterized in that, include: The image acquisition module (101) is used to acquire railway track images, perform adaptive pyramid scaling and normalization processing on the railway track images, and expand the dataset based on the Mosaic data augmentation method; The multi-scale feature extraction module (102) is used to extract multi-scale features of the railway track image by using a lightweight backbone network based on FasterNet through grouped convolution and depthwise separable convolution. The feature enhancement module (103) is used to enhance the relevant channel features of the disease area based on the MSCAM multi-scale convolutional attention module and suppress background interference; The feature fusion enhancement module (104) is used to connect the coordinate attention CoordAtt module after the output of the MSCAM multi-scale convolutional attention module to form a fused feature enhancement module, thereby further strengthening the spatial-channel association of the disease area based on the feature enhancement module and obtaining the associated channel features of the disease area. The joint loss function module (105) is used to fuse perceptual loss on the basis of the original loss function of YOLOv8 to form a joint loss function. The joint loss function is used to optimize the alignment of disease texture in the feature space of deep disease area to form enhanced features. The track defect detection module (106) is used to input the enhanced features into the detection head, output the defect category, bounding box and confidence level, and complete the railway track defect detection.

9. An electronic device, characterized in that, It includes a processor and a memory, the memory storing multiple instructions, and the processor being used to read the instructions and execute the method as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a plurality of instructions, which can be read by a processor and executed as described in any one of claims 1-7.