A Railway Rail Surface Defect Detection Method Based on Generative Adversarial Networks and Multi-Scale Feature Fusion
By using generative adversarial networks and multi-scale feature fusion, a YOLOv8-GLCA model was constructed, which solved the problems of low efficiency and low accuracy in rail surface defect detection, and achieved more efficient and accurate defect detection.
Patent Information
- Application Number
- CN202510541003.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-27
- Publication Date
- 2025-11-14
- Estimated Expiration
- 2045-04-27
AI Technical Summary
Existing technologies for detecting defects on rail surfaces suffer from low detection efficiency and low accuracy. In particular, they are difficult to effectively extract discriminative feature information in complex backgrounds, leading to errors or omissions in the detection of small targets.
A method for detecting surface defects on railway rails based on generative adversarial networks and multi-scale feature fusion is adopted. The domain adaptation enhancement dataset is constructed using the StyleGAN3 model, the Backbone, Neck, and Head parts of the YOLOv8 network are improved, and the MLCA, LAWDS, and DetectAux modules are introduced to enhance feature interaction and supervision information.
It significantly improves detection accuracy and robustness, enhances the ability to understand complex images, solves the accuracy and reliability problems of rail crack detection, and achieves more efficient defect detection.
Smart Images

Figure CN120598845B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of rail surface defect detection technology, specifically involving a method for detecting railway rail surface defects based on generative adversarial networks and multi-scale feature fusion. Background Technology
[0002] With the increasing frequency and heavy load of rail transit operations, the problem of rail surface defects has become increasingly prominent. Although traditional manual inspection methods are inexpensive, they are inefficient. Methods such as laser ultrasound and eddy current testing also have limitations in terms of detection efficiency or environmental adaptability, making it difficult to meet the inspection needs of modern railways that operate tens of thousands of kilometers per day.
[0003] Machine vision-based inspection technology has become a research hotspot due to its advantages such as non-contact operation and high efficiency. However, it faces multiple challenges in practical applications: the reflective effect of rail surfaces weakens defect features; the irregular geometric boundaries and small target areas (common block damage, scratches, and microcracks) and the scarcity of samples limit the detection accuracy; heavy-haul railways are more prone to cross-sectional wear due to their heavy axle load and high transport volume. In addition, the corrosion and stains on rails caused by harsh environments such as ports and mining areas significantly increase the complexity of the image background.
[0004] In recent years, scholars both domestically and internationally have made significant progress in the field of rail surface defect detection. By integrating traditional image processing and deep learning technologies, they have proposed several innovative solutions to key problems in practical engineering. Related research mainly focuses on lightweight detection models, small target recognition, and multi-scale feature processing. Regarding the development of lightweight detection systems, addressing the issue of fully supervised methods relying on large amounts of pixel-level annotation and the high cost of manual annotation, some studies have achieved accurate defect localization using only 20% of the labeled data by employing a semi-supervised consistency training framework and a deep-assisted multi-scale cross-modal fusion module (DMCFM). To improve detection accuracy in complex scenarios, some studies have improved upon the YOLOv4 framework by enhancing the learning ability of rail defect edge features through a feature enhancement module, effectively overcoming detection bottlenecks such as small defect size and background texture interference. For the problems of small targets and dense occlusion, some studies have introduced a multi-scale attention mechanism based on YOLOv8 to improve the localization accuracy of small defects and occluded targets on the rail surface.
[0005] Although convolutional neural network-based methods have made some progress in rail surface defect detection, achieving significant improvements in detection accuracy and ensuring high model efficiency through various algorithm optimizations, in-depth research on rail defects remains relatively insufficient. The scarcity of rail defect images presents numerous challenges to algorithmic detection. Furthermore, the small pixel proportion of defect targets in images and their indistinct features make the detection task extremely difficult. Additionally, some subtle defects are highly similar to the rail background features, making it difficult for the network to effectively extract discriminative feature information, severely impacting detection accuracy. In such cases, the network may misidentify small cracks or even completely miss their detection. Therefore, there is an urgent need to develop more refined and efficient detection algorithms to address these challenges and improve the accuracy and reliability of rail crack detection. Summary of the Invention
[0006] To address the problems existing in the above-mentioned background technology, the purpose of this invention is to provide a method for detecting surface defects of railway rails based on generative adversarial networks and multi-scale feature fusion.
[0007] To achieve the above objectives, the present invention adopts the following technical solution:
[0008] A method for detecting surface defects in railway rails based on generative adversarial networks and multi-scale feature fusion includes the following steps:
[0009] S1. Input the collected rail defect images into the StyleGAN3 model based on the transfer learning strategy for domain adaptation enhancement and construct the enhanced dataset;
[0010] S2. Constructing a YOLOv8-GLCA model for detecting surface defects in railway rails.
[0011] Based on the YOLOv8n network, the Bottleneck structure in the C2f module of the Backbone network in the YOLOv8 network is replaced with a Hybrid Local Channel Attention (MLCA) module to construct the C2f_MLCA module. The C2f_MLCA module constructs a cross-channel feature interaction matrix through the MLCA module and uses deformable convolutional kernels to achieve dynamic receptive field adjustment. The C2f_MLCA module is introduced into layers 6-7 of the Backbone network in the YOLOv8 network, and the C2f_MLCA module and the Lightweight Adaptive Weighted Downsampling (LAWDS) module are fused in layers 18-19 of the Neck network in the YOLOv8 network. The Head part of the YOLOv8 network adopts the DetectAux auxiliary detection head. The result is the YOLOv8-GLCA railway rail surface defect detection model based on generative adversarial network and multi-scale feature fusion.
[0012] S3. Use the augmented dataset to train the YOLOv8-GLCA railway rail surface defect detection model to obtain the trained railway rail surface defect detection model.
[0013] S4. Input the dataset to be tested into the trained railway rail surface defect detection model for defect detection and output the detection results.
[0014] Furthermore, in S1, in the StyleGAN3 model based on the transfer learning strategy, the StyleGAN3 model is standardized using Exponential Moving Average (EMA) to replace the skip connection structure, a low-pass upsampling filter is used to replace the bilinear 2x upsampling filter, and the 3×3 convolutional kernel is replaced with a 1×1 convolutional kernel; the pixel noise input layer of the StyleGAN3 model is removed and a learning affine transformation module is introduced; and Leaky ReLU is encapsulated between upsampling and downsampling.
[0015] Furthermore, the method for constructing the augmented dataset is as follows:
[0016] First, the latent coding vector z of the acquired rail defect image is transformed into a style vector w through a mapping network;
[0017] Secondly, Fourier features are used to replace the traditional input constants, and a 1×1 convolution kernel and a low-pass upsampling filter are combined to process rail defect images.
[0018] Finally, the rail defect images are further processed by learning the affine transformation module, and the generated rail defect images are used to construct an augmented dataset.
[0019] Furthermore, in S2, the DetectAux auxiliary detection head models label allocation as an optimal transmission problem by constructing a cost matrix, prioritizes candidate boxes with high classification confidence and small positioning error as positive samples, dynamically adjusts the weight of negative samples, suppresses interference from ballast areas similar to rail features, and generates prediction boxes based on feature points.
[0020] Compared with the shortcomings and deficiencies of existing technologies, the present invention has the following beneficial effects:
[0021] 1. In order to expand the collected image dataset using StyleGAN3, this invention enriches the training samples of the detection model and enhances the generalization ability and robustness of the detection model;
[0022] 2. The detection model of this invention is based on the YOLOv8n network. An MLCA model is added to the C2f module of the Backbone network to construct the C2f_MLCA module, enhancing the model's interaction and fusion capabilities during feature extraction. This allows the detection model to more effectively integrate feature information from different levels and scales, thereby improving its understanding and analysis of complex images. The C2f_MLCA module and the LAWDS module are integrated into the Neck network. Through the synergistic optimization of a dual-path attention mechanism and a dynamic feature selection strategy, the accuracy and robustness of rail surface defect detection are effectively improved. The Head part uses a DetectAux auxiliary detection head, which provides additional supervision information or optimization objectives to help the model learn the characteristics and distribution patterns of defects more deeply, thereby significantly improving detection accuracy and robustness, and further enhancing the detection performance of the detection model.
[0023] 3. The detection method of the present invention not only solves the problem of scarce rail crack image data, but also achieves a breakthrough in the accuracy of rail defect detection. Compared with the detection methods of YOLOv5, YOLOv8, GD-YOLOv8, and YOLOv10, the detection accuracy of the detection method of the present invention is significantly improved, and its detection effect meets the standards and requirements of practical applications. It has significant advantages and practicality in the field of rail defect detection, and provides strong protection for the safe operation and maintenance of rails. Attached Figure Description
[0024] Figure 1 This is a flowchart of the railway rail surface defect detection method provided in the embodiments of the present invention;
[0025] Figure 2 This is a structural diagram of the StyleGAN3 model based on transfer learning strategy provided in an embodiment of the present invention;
[0026] Figure 3 This is a comparison image of the original rail defect image provided in the embodiment of the present invention and the rail defect image generated by the StyleGAN3 model based on the transfer learning strategy. In the figure, (a) is the original rail defect image and (b) is the generated rail defect image.
[0027] Figure 4 This is a structural diagram of the C2f_MLCA module provided in an embodiment of the present invention;
[0028] Figure 5 This is a network structure diagram of the YOLOv8-GLCA railway rail surface defect detection model provided in this embodiment of the invention;
[0029] Figure 6 This is a network structure diagram of MLCA provided in an embodiment of the present invention;
[0030] Figure 7 This is a framework structure diagram of the LAWDS module provided in an embodiment of the present invention;
[0031] Figure 8 This is a structural diagram of the DetectAux auxiliary detection head provided in an embodiment of the present invention;
[0032] Figure 9 This is a comparison of the PR curves of different models provided in the embodiments of the present invention. In the figure, (a) is the PR curve of the insulator and the damaged one, and (b) is the PR curve of the damaged one.
[0033] Figure 10 This is a comparison of the detection results of different models provided in the embodiments of the present invention. In the figure, (a) is YOLOv5, (b) is YOLOv8, (c) is YOLOv10, (d) is GD-YOLOv8, and (e) is YOLOv8-GLCA. Detailed Implementation
[0034] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to specific embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0035] Example
[0036] The flowchart of the railway rail surface defect detection method based on generative adversarial networks and multi-scale feature fusion proposed in this invention is shown below. Figure 1 The steps are as follows:
[0037] S1. To address the challenge of scarce samples of rail surface defects, a defect generation model is constructed using the StyleGAN3 framework based on transfer learning. The structure of the StyleGAN3 model based on the transfer learning strategy is as follows: Figure 2 As shown, the StyleGAN3 model uses Exponential Moving Average (EMA) for standardization to replace the skip-connection structure and avoid gradient vanishing; a low-pass upsampling filter replaces the bilinear 2x upsampling filter; the 3×3 convolutional kernel is replaced with a 1×1 convolutional kernel; the pixel noise input layer is removed and an affine transformation learning module is introduced; and Leaky ReLU is encapsulated between upsampling and downsampling. The StyleGAN3 model's network architecture incorporates a transfer learning strategy and achieves decoupling and controllable generation of defect features through a series of core modules.
[0038] The collected rail defect images are input into the StyleGAN3 model based on a transfer learning strategy for domain adaptation enhancement, enriching the diversity of defect samples and constructing an enhanced dataset. The method is as follows:
[0039] First, the latent encoding vector z of the acquired rail defect image is transformed into a style vector w through a mapping network. This style vector is then injected into various layers of the synthesis network through the Adaptive Instance Normalization (AdaIN) module, thereby achieving fine control over features at different scales (covering rail matrix texture, defect morphology, etc.).
[0040] Secondly, Fourier features are used instead of traditional input constants, which effectively eliminates texture adhesion caused by pixel-level position references. Simultaneously, combining a 1×1 convolution kernel with a low-pass upsampling filter to process rail defect images improves the geometric consistency of the generated images under continuous translation and rotation transformations.
[0041] Finally, by learning the affine transformation module to further process the rail defect images, the network's ability to express the structural features of defects is further enhanced, and the generated rail defect images are used to construct an augmented dataset.
[0042] Comparison of original rail defect images with rail defect images generated by the StyleGAN3 model based on transfer learning strategy, for example... Figure 3 As shown, Figure 3 In the image, (a) shows the original rail defect image, and (b) shows the rail defect image generated by the model. It can be seen that the generated image is highly consistent with the original data in terms of surface crack morphology, defect edge continuity, and local texture details.
[0043] S2. Constructing a YOLOv8-GLCA model for detecting surface defects in railway rails.
[0044] Based on the YOLOv8n network, the overall architecture remains consistent with the YOLOv8 network, including the input, backbone, neck, and head. While retaining the original YOLOv8 feature pyramid structure, the backbone network replaces the Bottleneck structure in the C2f module with a Hybrid Local Channel Attention (MLCA) module, constructing the C2f_MLCA module, whose structure is as follows: Figure 4As shown, the C2f_MLCA module is introduced into layers 6-7 of the Backbone network. The C2f_MLCA module constructs a cross-channel feature interaction matrix through the MLCA module and uses deformable convolutional kernels to achieve dynamic receptive field adjustment. To address the multi-scale target detection requirements in complex scenarios, the C2f_MLCA module and the Lightweight Adaptive Weighted Downsampling (LAWDS) module are fused in layers 18-19 of the Neck network. A feature contribution evaluation function is established through a dynamic channel recalibration mechanism, and a dual-path feature fusion strategy is used to improve the efficiency of cross-scale feature interaction. To enhance target localization accuracy, the Head part uses a DetectAux auxiliary detection head. This detection head employs a feature pyramid distillation algorithm, establishing multi-level supervision signals to achieve accurate mapping from the high-dimensional feature space to target localization and classification, effectively compensating for the accumulated error of coordinate regression in traditional architectures. Finally, the YOLOv8-GLCA railway rail surface defect detection model based on generative adversarial networks and multi-scale feature fusion is obtained, and its network structure is shown below. Figure 5 As shown, a progressive architecture of "data augmentation - feature extraction - multi-scale fusion - collaborative detection" is adopted, which consists of a complete technical loop composed of StyleGAN3 data generation module, improved Backbone network, enhanced Neck network and dual-path detection head.
[0045] S3. The YOLOv8-GLCA model for detecting surface defects on railway rails is trained using an augmented dataset to improve the robustness and generalization ability of the algorithm, resulting in the trained model for detecting surface defects on railway rails.
[0046] S4. Input the dataset to be tested into the trained railway rail surface defect detection model for defect detection and output the detection results.
[0047] The YOLOv8-GLCA model introduces the MLCA (Mixed Local Channel Attention) module, a lightweight attention mechanism that mixes local and global spatial information. This achieves a balance between detection performance, speed, and the number of model parameters, while simultaneously incorporating channel, spatial, local, and global channel information. The MLCA network structure is as follows: Figure 6 As shown, this module first performs Local Spatial Pooling on the input features to generate a C×ks×ks local representation tensor. Then, it uses a dual-path feature transformation: the global branch uses global average pooling to extract global statistical features along the channel dimension, while the local branch uses spatial expansion to preserve local spatial structure information. After the two feature paths interact across channels using one-dimensional convolutional kernels, the original spatial resolution is restored through unpooling. Finally, feature fusion is achieved by element-wise addition.
[0048] When processing images using the C2f_MLCA module, local spatial attention is first used to focus on key areas of rail damage, and dilated convolution is used to expand the receptive field and capture long-range dependencies. Subsequently, channel attention is used to dynamically calibrate feature channel weights, strengthening effective features and suppressing redundant information. During the training phase, multi-scale feature interaction branching enhances the model's ability to represent subtle defects in insulators. During inference, attention weight fusion and branch folding techniques are used to achieve synergistic optimization of feature selection and information integration while maintaining single-path computation efficiency, thus achieving a balance between model lightweighting and detection robustness.
[0049] The YOLOv8-GLCA model introduces the LAWDS module, which effectively improves the accuracy and robustness of rail surface defect detection through the synergistic optimization of a dual-path attention mechanism and a dynamic feature selection strategy. Its framework structure is as follows: Figure 7 As shown, this module integrates a spatial-channel hybrid attention mechanism with adaptive downsampling operations, optimizing the design to address the limitations of traditional fixed downsampling in complex industrial scenarios. In the backbone network feature extraction stage, LAWDS achieves adaptive fusion of multi-scale features through a dual-branch parallel processing architecture: the main branch performs basic downsampling operations through group convolution layers, simultaneously expanding the channel dimension by four times to match the spatial decomposition requirements of neighborhood features. Then, tensor reshaping reconstructs the feature dimensions into a structure matching the attention weights. Secondly, the auxiliary branch uses cascaded local average pooling layers and convolutional layers to construct a spatial attention mechanism, where pooling captures local contextual prior information, and the convolutional layers learn to generate a spatially adaptive attention distribution. The softmax function is used to normalize the weights of the four sub-regions within the neighborhood, establishing a probability distribution model under spatial constraints. Finally, element-wise modulation of the expanded features and normalized weights is achieved through multiplication, and a weighted summation operation is performed along the spatial dimension, thereby achieving resolution dimensionality reduction while maintaining feature discriminativeness.
[0050] The YOLOv8-GLCA model uses the DetectAux auxiliary detection head, the structure of which is as follows: Figure 8As shown, this paper optimizes the dynamic label assignment mechanism for adapting target features in complex scenarios during rail surface defect detection. Rail detection typically faces challenges such as background interference, diverse morphologies of rail surface defects, and small-scale or localized corrosion. The Assigner in the DetectAux auxiliary detection head employs a dynamic strategy, adaptively adjusting the matching threshold based on the statistical characteristics of the predicted results and the ground truth bounding boxes. Addressing the common problem of low-quality predicted bounding boxes in rail detection, a cost matrix is constructed to model label assignment as an optimal transport problem. Candidate bounding boxes with high classification confidence and small localization errors are prioritized as positive samples, while the weights of negative samples are dynamically adjusted to suppress interference from ballast areas similar to rail features. Furthermore, rail detection is often affected by ballast texture and light reflection, generating a large number of low-quality predicted bounding boxes. Cross-level label assignment is achieved through YOLOv8's Neck and Head, enabling multi-scale feature collaboration: low-level feature maps utilize high resolution to capture the microscopic edge features of rail surface defects, while high-level feature maps perceive the overall rail alignment with strong semantic information. Each level independently calculates the optimal matching cost, enhancing the ability to jointly model local defect details and global structural features. YOLOv8 itself adopts an anchor-free design, while the Assigner in the DetectAux auxiliary detection head further eliminates the size constraints of preset anchor frames, directly generating predicted boxes based on feature points. For rail inspection, this avoids the positioning deviation caused by the fixed aspect ratio of traditional anchor frames. At the same time, by combining the loss function to refine the probability distribution of bounding box coordinates, it significantly improves the positioning accuracy of key points of rail surface defects.
[0051] Evaluation and Analysis of Experimental Results
[0052] 1. Experimental Platform
[0053] This experiment was conducted in a PyTorch environment, using Python 3.12.0 and CUDA 12.1. Details of the required software and hardware configurations are shown in Table 1.
[0054] Table 1 Software and Hardware Platform Configuration Parameters
[0055]
[0056]
[0057] In the experiment, the total number of iterations was 100, the input image pixel size was 640×640, the learning rate was set to 0.001, the training time was approximately 2.3 hours, and other hyperparameter settings are shown in Table 2.
[0058] Table 2 Experimental Hyperparameter Settings
[0059]
[0060] 2. Performance Evaluation Metrics of the YOLOv8-GLCA Model
[0061] To evaluate the performance of the detection model YOLOv8-GLCA constructed in this invention, precision (P), recall (R), mean precision (mAP), floating-point operations (FLOPs), and frames per second (FPS) are used as the main evaluation metrics. Specifically, precision and recall are calculated based on true positives (TP), false positives (FP), and false negatives (FN), where TP represents the number of correct targets in the detection results, FP is the number of incorrect targets, and FN is the number of targets that were not correctly detected. Furthermore, the formulas for calculating mAP and FPS are given in detail to comprehensively measure the accuracy, efficiency, and real-time performance of the method. The specific formulas are as follows:
[0062]
[0063] In the evaluation metrics, n represents the total number of image categories, i represents the number of detection attempts, and AP is the average accuracy for a single category. For evaluating detection speed, Time represents the total time required to process the images, which is then used to calculate FPS. A higher FPS value indicates a faster detection rate and superior real-time performance of the model.
[0064] 3. Comparative Analysis of Experimental Results
[0065] (1) Comparison of different C2f modules
[0066] To evaluate the performance gain of the C2f_MLCA module in the YOLOv8 object detection framework, a comparative ablation experiment was designed for rail surface defect detection. By comparing the C2f_MLCA module with current mainstream C2f architectures (including C2f variants), and maintaining strict consistency in module embedding positions and model hyperparameters, the system verified the impact of different feature extraction modules on network performance. The results are shown in Table 3.
[0067] Table 3 Comparison of different C2f modules
[0068]
[0069] Based on the ablation experiment results shown in Table 3, different improved schemes exhibited differentiated detection performance on the same dataset when introducing different variants of the C2f module into the YOLOv8 target detection framework. Among them, the improved model using the C2f_MLCA structure significantly improved the detection accuracy of multi-scale targets while maintaining real-time detection efficiency. Compared to the original C2f, C2f_MLCA improved precision by 12.2% for the first type and by 2% for the second type; in terms of recall, the improvement for the second type of target also reached 5%. From the overall detection performance perspective, the introduction of the C2f_MLCA module into YOLOv8 improved the average precision (AP@0.5) of the first type of target by 3.2% and the AP@0.5 of the second type of target by 2.1%, with overall mAP@0.5 and mAP@0.5:0.95 achieving optimization gains of 2.6% and 1%, respectively. Although the C2f_MLCA module has increased GFLOPs compared to C2f_ODConv and C2f_Faster, it effectively enhances feature representation capabilities through a multi-dimensional long-range attention mechanism, demonstrating advantages in target localization accuracy under complex background interference and recall of occluded targets. This structure achieves cross-scale feature fusion through a channel-space joint attention mechanism, exhibiting superior engineering applicability in balancing computational efficiency and detection accuracy. Therefore, this paper chooses C2f_MLCA to replace C2f to improve the model's detection performance for rail defects.
[0070] (2) Ablation test
[0071] To evaluate the effectiveness of modular improvements to the YOLOv8 architecture in object detection systems, a systematic validation was conducted using ablation studies with controlled variables, validating its performance while maintaining a consistent experimental configuration and training strategy. However, due to the limited original dataset, all training and detection datasets for the models were obtained through GAN processing. The experimental results based on the improved YOLOv8-G model are shown in Table 4.
[0072] Table 4 Comparison Model Based on mAP
[0073]
[0074] Table 4 shows that the introduction of each optimization module effectively improves defect detection performance. Regarding single-module optimization: After introducing LAWDS, the YOLOv8-GL model improved the detection accuracy for Type 1 defects by 3.5% and Type 2 defects by 0.6%, with an overall mAP@0.5 improvement of 2.1%, but a 0.2% decrease in mAP0.5-0.95. The C2f_MLCA module improved the detection accuracy of the YOLOv8-GC model for Type 1 and Type 2 defects by 3.2% and 2.1%, respectively, while simultaneously improving mAP@0.5 and mAP@0.5-0.95 by 2.6% and 1.0%, respectively. The DetectAux module improved the accuracy of the YOLOv8-GA model for Type 1 and Type 2 defects by 5.2% and 0.9%, respectively, with an overall improvement in mAP@0.5 and mAP0.5-0.95 by 2.6% and 1%, respectively. In the dual-module combination experiments, the YOLOv8-GLC model combining LAWDS and C2f_MLCA improved the accuracy of Type 1 by 4.6% and Type 2 by 1.5%. mAP@0.5 improved by 3.1%. The YOLOv8-GLA model combining LAWDS and DetectAux improved the accuracy of Type 1 and Type 2 by 2.6% and 0.6%, respectively, and the model's mAP@0.5 improved by 1.6%, but the model's mAP0.5-0.95 decreased by 1.3%. The YOLOv8-GCA model combining C2f_MLCA and DetectAux improved the accuracy of Type 1 and Type 2 by 3.3% and 2.1%, respectively, and the model's mAP@0.5 and mAP0.5-0.95 improved by 1.6% and 0.7%, respectively. The performance gains of the dual-module combination did not significantly exceed the single-module optimization effect; some metrics even showed negative fluctuations. When all three modules are introduced simultaneously, the defect accuracy of the YOLOv8-GLCA model for Type 1 and Type 2 improves by 7.7% and 4.2%, respectively, while the overall mAP@0.5 and mAP0.5-0.95 improve by 5.9% and 1.2%, respectively. Experimental data show that the LAWDS, C2f_MLCA, and DetectAux modules form a complementary optimization mechanism through the synergistic effect of feature enhancement, multi-scale context aggregation, and auxiliary supervision. Specifically, LAWDS strengthens the feature representation of small targets, C2f_MLCA optimizes cross-scale feature fusion, and DetectAux improves training stability through deep supervision. The synergy of these three modules effectively overcomes the performance bottleneck of single / dual module optimization.
[0075] Table 5 shows a comparison of the precision and recall rates of defect detection after each module was introduced into YOLOv8-G:
[0076] Table 5. Based on the P and R comparison model
[0077]
[0078]
[0079] Table 5 shows that the introduction of each module into YOLOv8-G improved defect detection accuracy. YOLOv8-GL improved precision for Type 2 by 2.1% and recall for Type 1 by 3.7%. YOLOv8-GC improved precision for Type 1 by 12.2%, and improved precision and recall for Type 2 by 2% and 5%, respectively. YOLOv8-GA improved precision for Type 1 by 23.1% and precision for Type 2 by 1.7%. In the dual-module combination, YOLOv8-GLC improved precision for Type 1 by 14.3%, and precision and recall for Type 2 by 4.9% and 0.8%, respectively. YOLOv8-GLA improved precision for Type 1 by 0.9% and precision for Type 2 by 9.5%. YOLOv8-GCA improved precision for Type 1 by 13.9%, and precision and recall for Type 2 by 0.3% and 6.4%, respectively. YOLOv8-GLCA improved Precision and Recall by 8.5% and 5.6% for Type 1 and by 7.3% and 1.4% for Type 2, respectively. Experimental results show that while the introduction of single or dual modules can partially improve specific metrics, the performance gains exhibit locality. The three-module joint optimization strategy, however, achieved comprehensive optimization of the Precision-Recall metrics, validating the effectiveness of the multi-module collaborative mechanism in rail defect detection and providing a new technical path for improving the performance of industrial vision inspection systems.
[0080] To further evaluate the advantages of the detection model of this invention, mAP@0.5 curves and PR curves (refer to...) were used. Figure 9Further research and analysis were conducted, and a comprehensive performance evaluation was performed on the rail damage detection model based on the improved YOLOv8 architecture. Experimental results show that the baseline model YOLOv8-G has a slow convergence rate in the mAP@0.5 index, and its Precision-Recall curve exhibits a rapid decay trend at the IoU=0.5 threshold. This indicates that the model gets trapped in local optima too early during training, resulting in limited feature representation capabilities. In contrast, six improved models, namely YOLOv8-GL, YOLOv8-GC, YOLOv8-GA, YOLOv8-GLC, YOLOv8-GLA, and YOLOv8-GCA, show better convergence characteristics in the mAP@0.5 index, and their Precision-Recall curve decay rate is reduced. However, the performance difference between the improved models is only about 1%, which does not form a significant distinction. However, the mAP@0.5 curve of the YOLOv8-GLCA model proposed in this invention shows an exponential upward trend in the early stage of training (the improvement reaches 80% in the first 50 epochs), while the PR curve achieves a gradual decrease while maintaining high accuracy. This performance improvement stems from the improved feature extraction efficiency brought about by multi-module collaborative optimization. Through gradient guidance mechanism and attention recalibration strategy, the model's fine-grained feature learning ability in complex track scenarios is enhanced, verifying the effectiveness and robustness of this invention in rail surface defect detection tasks.
[0081] (3) Comparison of experiments with different network models
[0082] To ensure the systematic verification of the performance advantages of the YOLOv8-GLCA algorithm in rail defect detection, a strictly controlled comparative experimental scheme was adopted: all reference models (covering mainstream detection frameworks such as YOLOv5, YOLOv8, YOLOv10, and GD-YOLOv8) and the detection model of this invention were trained and evaluated under completely identical benchmark conditions. The training dataset was uniformly preprocessed using the StyleGAN3 generative adversarial network to effectively expand the diversity of defect samples through data augmentation; simultaneously, the experimental parameter configurations of each model (including key hyperparameters such as learning rate strategy, batch size, and training cycle) were kept absolutely consistent with YOLOv8-GLCA, and followed the same dataset partitioning ratio. The experimental data comparison is shown in Table 6:
[0083] Table 6 Comparison of the models
[0084]
[0085] As shown in Table 6, the YOLOv8-GLCA detection model proposed in this invention exhibits superior performance in rail defect identification tasks. This model comprehensively surpasses mainstream algorithms YOLOv5, YOLOv8, YOLOv10, and the modified GD-YOLOv8 in core detection accuracy metrics. Experimental results show that the mAP@0.5 of YOLOv8-GLCA is 5.9% higher than that of YOLOv8. While maintaining class balance, the identification accuracy for small target defects Type 1 and Type 2 reaches 94% and 89.9%, respectively, which are 42.5% and 44.7% higher than the GD-YOLOv8 model. Furthermore, this model demonstrates particularly outstanding performance in recall. By introducing an adaptive anchor frame optimization strategy and a dynamic threshold mechanism, it effectively reduces the false negative rate under complex lighting conditions, significantly improving the stability of defect detection in practical engineering applications. Although the GFLOPs of the YOLOv8-GLCA model are 0.9 higher than those of GD-YOLOv8, this slight increase in computational cost yields a significant return on accuracy. Considering detection accuracy, real-time performance, and engineering practicality, YOLOv8-GLCA demonstrates superior overall performance in intelligent rail inspection scenarios. Especially when detection accuracy is prioritized over extremely lightweight deployment, this model maintains high detection efficiency while providing railway maintenance departments with more reliable defect diagnosis data, which has significant engineering application value for improving railway transportation safety.
[0086] To objectively evaluate the actual detection performance of this invention in real railway scenarios, a set of comparative experiments based on field-collected data were designed and implemented, such as... Figure 10 As shown, this is a real track surface dataset containing samples with complex lighting conditions and multi-scale defects. Figure 10The comparison of on-site detection results (a)-10(e) shows that different algorithms exhibit significant performance differences in real-world track surface defect detection tasks. Experimental data shows that the YOLOv5 and GD-YOLOv8 models reveal significant shortcomings in complex scene detection. Both models have a high rate of missed detection for low-contrast cracks and rust areas, and the detection accuracy of both models is below 60%, reflecting their limitations in feature extraction and scale adaptability. Although YOLOv8 and YOLOv10 improve the average accuracy to about 73% through a hierarchical feature fusion strategy, they still have blind spots in small-scale defect detection, especially under extreme conditions such as sudden changes in illumination and motion blur. The proposed YOLOv8-GLCA model, by coupling global context awareness and local detail enhancement mechanisms, achieves improved detection performance in real-world testing, reaching an accuracy of approximately 91%. Furthermore, the algorithm significantly enhances its robustness against complex backgrounds through effective multi-scale feature interaction and greatly improves the feature representation quality of minute defects using an adaptive spatial attention mechanism, enabling precise defect location. This algorithm not only provides railway departments with a high-precision intelligent detection solution but also lays a solid technical foundation for achieving integrated detection of rail defects—from discovery to location to assessment—due to its excellent engineering adaptability.
[0087] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for detecting surface defects in railway rails based on generative adversarial networks and multi-scale feature fusion, characterized in that, Includes the following steps: S1. Input the collected rail defect images into the StyleGAN3 model based on the transfer learning strategy for domain adaptation enhancement and construct the enhanced dataset; S2. Constructing a YOLOv8-GLCA model for detecting surface defects in railway rails. Based on the YOLOv8n network, the Bottleneck structure in the C2f module of the Backbone network of the YOLOv8 network is replaced with the MLCA module to construct the C2f_MLCA module. The C2f_MLCA module constructs a cross-channel feature interaction matrix through the MLCA module and uses deformable convolutional kernels to achieve dynamic receptive field adjustment. The C2f_MLCA module is introduced into the 6th-7th layers of the Backbone network in the YOLOv8 network, and the C2f_MLCA module and the LAWDS module are fused in the 18th-19th layers of the Neck network in the YOLOv8 network. The Head part of the YOLOv8 network adopts the DetectAux auxiliary detection head. The YOLOv8-GLCA model for detecting railway rail surface defects based on generative adversarial networks and multi-scale feature fusion is obtained. S3. Use the augmented dataset to train the YOLOv8-GLCA railway rail surface defect detection model to obtain the trained railway rail surface defect detection model. S4. Input the dataset to be tested into the trained railway rail surface defect detection model for defect detection and output the detection results.
2. The railway rail surface defect detection method based on generative adversarial networks and multi-scale feature fusion as described in claim 1, characterized in that, In S1, the StyleGAN3 model is normalized using exponential moving average to replace the skip connection structure, a low-pass upsampling filter replaces the bilinear 2x upsampling filter, and the 3×3 convolution kernel is replaced with a 1×1 convolution kernel. The pixel noise input layer of the StyleGAN3 model is removed and a learning affine transformation module is introduced. Leaky ReLU is encapsulated between upsampling and downsampling.
3. The railway rail surface defect detection method based on generative adversarial networks and multi-scale feature fusion as described in claim 2, characterized in that, The method for constructing the augmented dataset is as follows: First, the latent coding vectors of the collected rail defect images are transformed into style vectors through a mapping network; Secondly, Fourier features are used to replace the traditional input constants, and a 1×1 convolution kernel and a low-pass upsampling filter are combined to process rail defect images. Finally, the rail defect images are further processed by learning the affine transformation module, and the generated rail defect images are used to construct an augmented dataset.
4. The railway rail surface defect detection method based on generative adversarial networks and multi-scale feature fusion as described in claim 1, characterized in that, In S2, the DetectAux auxiliary detection head models label allocation as an optimal transmission problem by constructing a cost matrix, prioritizes candidate boxes with high classification confidence and small positioning error as positive samples, dynamically adjusts the weight of negative samples, suppresses interference from ballast areas similar to rail features, and generates prediction boxes based on feature points.
Citation Information
Patent Citations
Aluminum material surface defect detection method for enhancing multi-scale feature extraction and target detection
CN118799268A
Improved YOLOv8-based steel surface defect target detection method
CN118823299A
Cited By
Steel rail surface defect detection method, device, equipment, medium and product
CN122199436A