A rail disease detection method based on multi-domain collaborative optimization
By extracting and fusing spatial and frequency domain features from railway defect detection images in parallel, and utilizing a parallel attention module and a multi-domain loss function, the problems of insensitivity to small defect detection and blurred reconstruction in traditional methods are solved, thus achieving efficient defect identification.
Patent Information
- Application Number
- CN202511468375.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-15
- Publication Date
- 2026-02-24
- Estimated Expiration
- 2045-10-15
AI Technical Summary
Existing reconstruction-based methods for detecting rail defects lack sensitivity when detecting minute defects, making them prone to missed detections. Furthermore, traditional attention modules suffer from sequence bias and reconstruction ambiguity issues.
We employ parallel extraction of spatial and frequency domain features from images, perform feature enhancement through a parallel attention module, and construct a multi-domain loss function, including a weighted sum of pixel-domain and frequency-domain reconstruction losses, to determine whether an image contains anomalies.
It significantly improves the detection capability of minute defects, reduces the false negative rate, and enhances the accuracy of feature representation and the clarity of reconstruction through multi-domain collaborative optimization methods.
Smart Images

Figure CN120932055B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer vision technology, and in particular to a method for detecting railway defects based on multi-domain collaborative optimization. Background Technology
[0002] Railway transportation safety is of paramount importance, and real-time monitoring of the surface health of railway tracks, as a core load-bearing component, is crucial for ensuring safety. Traditional methods relying on manual inspection are inefficient, subjective, and costly. In recent years, automated inspection technologies based on machine vision and deep learning have demonstrated significant advantages in industrial applications.
[0003] In the field of anomaly detection, methods based on reconstruction models (such as variational autoencoders) are widely used. The basic principle is that the model learns the feature distributions of a large number of normal images, thus accurately reconstructing a normal input image. When the input is an anomalous image containing lesions, because the model has not learned this type of anomaly pattern, its reconstruction result will differ significantly from the original input, i.e., a large reconstruction error. By setting an error threshold, the anomaly can be identified.
[0004] However, most existing reconstruction-based detection methods rely solely on convolutional neural networks to extract spatial domain features of images, such as pixel-level color and contours. These models are not sensitive enough to early, subtle defects present as high-frequency perturbations, easily leading to missed detections. Secondly, attention mechanisms are often introduced to enhance feature discriminative power. However, in mainstream attention modules, the operations performed first alter the distribution of the feature map, resulting in unexpected information suppression or misleading of subsequent operations—a sequence bias problem that limits the overall effectiveness of feature enhancement. Most critically, the optimization objective of standard reconstruction models is usually to minimize pixel-level reconstruction errors. This optimization approach tends to prioritize the global structural similarity of the image, often at the expense of high-frequency texture details, leading to widespread blurring in the reconstructed images. Therefore, when the input image contains anomalies such as tiny cracks or subtle texture changes, the pixel-level difference between the reconstructed image and the original image becomes extremely weak, making it difficult for the model to effectively identify, resulting in severe missed detections. Summary of the Invention
[0005] The main objective of this invention is to provide a rail defect detection method based on multi-domain collaborative optimization, which can improve the detection capability of minute defects, solve the reconstruction fuzzy problem, and reduce the missed detection rate.
[0006] To achieve the above objectives, the first aspect of this application provides a method for detecting rail defects based on multi-domain collaborative optimization, the method comprising:
[0007] Spatial and frequency domain features of the image to be detected are extracted in parallel, and the spatial and frequency domain features are fused to obtain multi-domain fused features; wherein, the frequency domain features are generated by performing at least two different frequency domain transformations on the image to be detected in parallel and fusing the transformation results;
[0008] The multi-domain fusion features are processed by a parallel attention module to generate enhanced features;
[0009] Output latent spatial variables based on the enhanced features;
[0010] The image to be detected is reconstructed based on the latent spatial variables to obtain the reconstructed image;
[0011] Based on the reconstructed image and the image to be detected, a multi-domain loss is calculated; the multi-domain loss includes a weighted sum of pixel domain reconstruction loss and frequency domain reconstruction loss.
[0012] The multi-domain loss is used as the anomaly score, and the presence of anomalies in the image to be detected is determined based on the comparison between the anomaly score and a preset threshold.
[0013] The second aspect of this application provides a rail defect detection device based on multi-domain collaborative optimization, including an encoder, a decoder, a loss calculation module, and a judgment module; wherein:
[0014] The encoder includes:
[0015] The feature extraction unit is used to extract spatial features and frequency domain features of the image to be detected in parallel, and fuse the spatial features and the frequency domain features to obtain multi-domain fusion features; wherein, the frequency domain features are generated by performing at least two different frequency domain transformations on the image to be detected in parallel and fusing the transformation results;
[0016] A parallel attention module is used to process the multi-domain fusion features to generate enhanced features;
[0017] The encoder is used to output latent spatial variables based on the enhanced features;
[0018] The decoder is used to reconstruct the image to be detected based on the latent spatial variables to obtain a reconstructed image;
[0019] The loss calculation module is used to calculate a multi-domain loss based on the reconstructed image and the image to be detected; the multi-domain loss includes a weighted sum of pixel domain reconstruction loss and frequency domain reconstruction loss;
[0020] The judgment module is used to take the multi-domain loss as an anomaly score and determine whether the image to be detected has an anomaly based on the comparison result of the anomaly score and a preset threshold.
[0021] A third aspect of this application provides an electronic device including a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform steps as described in the first aspect and any possible implementation thereof.
[0022] This application provides a method for detecting railway defects based on multi-domain collaborative optimization. The method involves extracting spatial and frequency domain features from an image to be detected in parallel, fusing the spatial and frequency domain features to obtain multi-domain fused features. The frequency domain features are generated by performing at least two different frequency domain transformations on the image to be detected in parallel and fusing the transformation results. The multi-domain fused features are processed by a parallel attention module to generate enhanced features. Latent spatial variables are output based on the enhanced features. The image to be detected is reconstructed based on the latent spatial variables to obtain a reconstructed image. A multi-domain loss is calculated based on the reconstructed image and the image to be detected. The multi-domain loss includes a weighted sum of pixel domain reconstruction loss and frequency domain reconstruction loss. The multi-domain loss is used as an anomaly score, and the presence of anomalies in the image to be detected is determined based on a comparison of the anomaly score with a preset threshold.
[0023] The technical solution provided in this application has the following beneficial effects:
[0024] 1. Enhanced detection of minute defects: By extracting and fusing spatial and frequency domain features in parallel, the model can simultaneously capture the macroscopic structure and microscopic texture (such as high-frequency perturbations) of images, significantly improving its sensitivity and ability to detect early-stage and minute defects. 2. Enhanced accuracy of feature representation: Employing a parallel dual-path attention mechanism eliminates the order bias problem of traditional serial attention, achieving unbiased and synchronous enhancement of key information in channel and spatial dimensions, thereby more accurately locating and responding to defect areas. 3. Resolving reconstruction ambiguity and reducing false negative rate: A multi-domain loss function co-optimized in the pixel and frequency domains is creatively constructed. By directly applying constraints in the frequency domain, the model is forced to accurately reconstruct high-frequency texture details from the optimization objective, effectively solving the pain point of image ambiguity in traditional reconstruction models. This results in significant differences in the frequency domain before and after reconstruction for minute anomalies, which are included in the total anomaly score, thus significantly reducing the false negative rate of minute defects. Attached Figure Description
[0025] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0026] in:
[0027] Figure 1 This is a flowchart illustrating a rail defect detection method based on multi-domain collaborative optimization provided in an embodiment of this application.
[0028] Figure 2 A schematic diagram of the structure of a rail defect detection device based on multi-domain collaborative optimization provided in an embodiment of this application;
[0029] Figure 3 A schematic diagram of the process for an unsupervised rail surface defect detection method based on dual-path residual attention and multi-domain collaborative optimization provided in this application embodiment;
[0030] Figure 4 This is a schematic diagram of a dataset cropping and filtering process provided in an embodiment of this application;
[0031] Figure 5 This is a schematic diagram of a frequency domain feature extraction module framework provided in an embodiment of this application;
[0032] Figure 6 This is a schematic diagram of a dual-path residual attention enhancement mechanism framework provided in an embodiment of this application;
[0033] Figure 7 This is a schematic diagram of the overall framework of a DPRA-VAE method provided in an embodiment of this application;
[0034] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0035] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.
[0036] The terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or apparatuses.
[0037] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a mutually exclusive, independent, or alternative embodiment. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0038] The embodiments of this application are described below with reference to the accompanying drawings.
[0039] Figure 1 A flowchart illustrating a rail defect detection method based on multi-domain collaborative optimization provided in this application is shown below. Figure 1 As shown, the method includes:
[0040] 101. Extract spatial and frequency domain features of the image to be detected in parallel, and fuse the spatial features and frequency domain features to obtain multi-domain fusion features; wherein, the frequency domain features are generated by performing at least two different frequency domain transformations in parallel on the image to be detected and fusing the transformation results.
[0041] The method in this application embodiment can be implemented by a rail defect detection device based on multi-domain collaborative optimization, which can be implemented on an electronic device in practical applications.
[0042] The image to be detected can be a digital image acquired by an industrial camera, mobile inspection equipment, etc. In this embodiment, the image to be detected can be an image required for any anomaly detection scenario. For example, in a railway defect detection scenario, the image to be detected can be a railway surface image.
[0043] First, feature extraction is performed on the input image to be detected. Unlike traditional methods that only focus on spatial information, this application can simultaneously analyze the image from both the spatial and frequency domains. The frequency domain features are generated by performing at least two different frequency domain transformations on the image to be detected in parallel and fusing the transformation results.
[0044] Then, the features extracted from different dimensions can be effectively integrated to form a more comprehensive and information-rich feature representation, namely the multi-domain fusion feature mentioned above. After obtaining the multi-domain fusion feature, step 102 can be executed.
[0045] 102. The above multi-domain fusion features are processed by a parallel attention module to generate enhanced features.
[0046] The parallel attention module can perform parallel attention enhancement on the fused features. This module includes channel attention paths and spatial attention paths. Step 102 aims to recalibrate the fused multi-domain features to highlight the key information most relevant to the anomalous patterns, while suppressing irrelevant or redundant information.
[0047] 103. Output latent spatial variables based on the above enhanced features.
[0048] Step 103 is the core of the reconstructed anomaly detection framework, which can be achieved by learning the distribution patterns of normal samples through an encoding-decoding process.
[0049] Specifically, the enhanced features described above can be input into the deep structure of the encoder, and after a series of convolutional operations and residual block processing, a high-level feature map is obtained. A fully connected layer is used to map the high-level feature map into the mean vector and variance vector of the latent spatial variables, and then the latent spatial variables are obtained through reparameterized sampling.
[0050] 104. Reconstruct the image to be detected based on the aforementioned latent spatial variables to obtain the reconstructed image.
[0051] Subsequently, the image to be detected is reconstructed based on the latent spatial variables. Specifically, the latent spatial variables can be input into the decoder, first expanded into feature vectors through a fully connected layer, then gradually increased in size and restored in detail through a series of upsampling layers and convolutional blocks, and finally output as a reconstructed image with the same size as the original input image and pixel values in the range [0,1].
[0052] 105. Based on the reconstructed image and the image to be detected, calculate the multi-domain loss; the multi-domain loss includes the weighted sum of pixel domain reconstruction loss and frequency domain reconstruction loss.
[0053] Multi-domain loss can be calculated based on the reconstructed image and the image to be detected. The multi-domain loss includes a weighted sum of pixel-domain reconstruction loss and frequency-domain reconstruction loss. Pixel-domain reconstruction loss can use binary cross-entropy (BCE) loss, which measures the difference between the original image and the reconstructed image in pixel space. Frequency-domain reconstruction loss calculates the L1 norm distance between the original image and the reconstructed image in the Fourier domain, directly penalizing the difference in the frequency domain.
[0054] 106. The above multi-domain loss is used as the anomaly score, and the anomaly score is compared with the preset threshold to determine whether the above image to be detected is abnormal.
[0055] In this embodiment, a multi-domain collaborative loss can be calculated as an anomaly score. This step uses a composite loss function to quantify the difference between the original image and the reconstructed image. The anomaly score can then be compared with a preset threshold, and a final judgment is made based on the quantized anomaly score to determine whether the image to be detected is an anomaly.
[0056] Please see Figure 2 This diagram illustrates the basic system architecture of the image anomaly detection apparatus used to perform the above-described method in this embodiment. Specifically, the apparatus can be logically divided into an encoder 10, a decoder 20, and a multi-domain loss calculation module 30. In a typical workflow, an input image x to be detected is fed into the encoder 10. The encoder 10 is responsible for mapping high-dimensional image data to a low-dimensional latent space. Subsequently, the decoder 20 receives the latent space variables output by the encoder 10 and attempts to reconstruct them into a reconstructed image x' that is consistent with the input image x in size and content. Finally, the input image x and the reconstructed image x' are simultaneously fed into the multi-domain loss calculation module 30, which calculates a comprehensive anomaly score for subsequent anomaly judgment.
[0057] The following will combine Figures 3 to 7 The process described above, as well as the apparatus used to implement it, will be explained in more detail.
[0058] Figure 3 This document presents a flowchart illustrating an unsupervised method for detecting railway surface defects based on dual-path residual attention and multi-domain collaborative optimization, as provided in this application. Its core lies in constructing and training a variational autoencoder model called DPRA-VAE (Dual-Path Residual Attention VAE). This method does not rely on defect sample annotations; it is trained using only normal railway track images and identifies defect areas by detecting the difference (reconstruction error) between the input image and the image reconstructed by the model.
[0059] In practical applications, existing railway defect detection methods largely rely on supervised learning, requiring a large amount of labeled data. However, since trains operate normally most of the time, real defect samples are scarce, making it difficult to construct a sufficiently large dataset. Furthermore, due to railway operational safety constraints, collecting real defect data on-site is extremely difficult. Subsequent "weakly supervised" or "semi-supervised" methods, while reducing the need for labeled data, still rely on a small number of defect samples or artificially generated "pseudo-defects." These synthetic defects are insufficient to cover the complex and varied defect types in real-world scenarios, limiting the actual detection performance and generalization ability of the models.
[0060] To completely eliminate reliance on defect data, this application proposes a detection paradigm based on unsupervised normal modeling. During training, the model requires only a large number of easily accessible normal rail image samples, without any defect samples or pixel-level annotations. This overcomes the core challenges of scarce defect samples, extremely high annotation costs, and strong subjectivity in industrial scenarios. The core of this method is to utilize the proposed variational autoencoder to learn the data distribution characteristics of the normal rail surface (including the aforementioned spatial structure and high-frequency texture), rather than memorizing specific defect patterns. In practical engineering applications, this means avoiding the tedious and costly process of collecting and annotating defect data on railway tracks, significantly reducing the barrier to entry and cost of system deployment. During detection, the model identifies anomalies by comparing the differences between the input image and the normal features reconstructed by the model (in the pixel and frequency domains), achieving intelligent detection. The following section combines... Figure 3 Further explanation of the technical solution.
[0061] like Figure 3 As shown, the specific technical solution includes the following steps:
[0062] Dataset preparation: Acquire and process image data of the railway track surface.
[0063] DPRA-VAE Model Construction: Construct a model architecture that includes a frequency domain feature extractor, a dual-path attention module, an encoder-decoder structure, and a multi-domain loss function.
[0064] Model training and testing: Train the DPRA-VAE model using the prepared normal sample dataset; input the railway track image to be tested, calculate its reconstruction error, and determine whether there is any defect based on the anomaly score.
[0065] The following section will focus on the construction of the aforementioned model to further explain the above methods and steps.
[0066] 1. Dataset Preparation
[0067] This application embodiment can use the Railway Surface Defect Detection Dataset (RSDDS). The data processing steps are as follows:
[0068] 11. Data cropping and filtering:
[0069] Input raw defect images of Type-I (high-speed rail) and Type-II (conventional / heavy-load rail), and perform a fixed-ratio cropping operation on the raw images. (See also...) Figure 4The diagram illustrates a dataset cropping and filtering process. Each image is divided into sub-image patches containing potential defect regions. Invalid cropped image patches whose defect regions are segmented are strictly removed. Finally, a valid sample set is output, containing multiple defective sample patches, and divided into training and test sets in a 4:1 ratio. (Here, "sample patch" refers to the cropped small image.)
[0070] 12. Data Augmentation and Standardization:
[0071] The valid sample blocks obtained in step 11 are input, and data augmentation techniques are applied to the normal sample blocks in the training set. These techniques may include: random 90°, 180°, and 270° flips, mirror flips, and hue, saturation, and brightness (HSV) adjustments. The number of samples in the augmented training set is increased to 6 times the original number (note: the test set is not augmented). Finally, the dimensions of all images are standardized to adapt to the input of the model.
[0072] 2. Construction of the Disease Identification Model (DPRA-VAE)
[0073] 21. Construct a wavelet-Fourier frequency domain feature extraction module (FreqEncoder).
[0074] Figure 5 This is a schematic diagram of a frequency domain feature extraction module framework provided in an embodiment of this application.
[0075] This module extracts and fuses spatial frequency domain features from the input image to enhance the perception of subtle textures (such as scratches and rust), while simultaneously performing wavelet transform and Fourier transform. Specific steps include:
[0076] Input: Image of the railway track surface;
[0077] Discrete Wavelet Transform (DWT): The DWT module decomposes the image into four sub-bands: a low-frequency approximation component LL (Low-Low) and three high-frequency detail components LH (Low-High), HL (High-Low), and HH (High-High). A standard two-dimensional DWT filter bank is applied for the transformation.
[0078] The output after wavelet transform is a wavelet coefficient tensor F_wave, which is composed of four subbands (LL, LH, HL, and HH) concatenated along the channel dimension. Subsequently, features are extracted from the wavelet transform output F_wave, processed by a convolutional block (Conv2D + BatchNorm (BN) + ReLU), adjusting the number of channels and introducing nonlinearity. The output is denoted as F_wave_feat.
[0079] Fast Fourier Transform (FFT): Extracts components from the first channel of the input image, applies a two-dimensional real-number Fast Fourier Transform to the components, and obtains the real and imaginary parts of the transformed result. The transformation formula is as follows:
[0080]
[0081] In the formula It is the frequency domain representation after Fourier transform, where and It is an index in the frequency space. This represents the signal of the input image in the spatial domain. These represent the coordinates of the image. and It refers to the size of the image (i.e., its width and height). It is the imaginary unit, representing the complex part of a number;
[0082] The transformed output is a Fourier spectrum tensor F_fft, composed of the real and imaginary parts concatenated along the channel dimension. F_fft is then processed through a convolutional block (Conv2D + BatchNorm (BN) + ReLU), while average pooling is applied to align the wavelet feature sizes. The output is denoted as F_fft_feat.
[0083] Feature fusion: F_wave_feat and F_fft_feat are concatenated along the channel dimension to obtain the preliminary fused feature F_fusion_pre. F_fusion_pre is then input into a fusion convolutional module FusionConv(3×3 Conv2D + BatchNorm (BN) + ReLU), and finally outputs the deep integrated and concatenated frequency domain feature F_freq.
[0084] Final output: F_freq: fused frequency domain feature map, used by the subsequent backbone network; F_fft: original Fourier complex tensor (real part + imaginary part), used for subsequent frequency domain loss. calculate.
[0085] The wavelet-Fourier frequency domain feature extraction module in this embodiment of the application fully combines the advantages of wavelets in spatial-frequency local analysis with the ability of Fourier in overall spectral response, realizing cross-domain collaborative coding. This multi-domain fusion of normal feature expression makes the model's characterization of normality more profound and complete, laying a solid foundation for accurately identifying subtle abnormal deviations.
[0086] 22. Construct a dual-path residual attention enhancement module (DPRA).
[0087] During the network feature propagation process, the DPRA module introduces attention mechanisms in both the spatial and channel dimensions. Figure 6 This is a schematic diagram of a dual-path residual attention enhancement mechanism framework provided in an embodiment of this application.
[0088] On one hand, the goal of the channel attention mechanism is to determine how to adjust the weights of each channel by using the global features of each channel (usually obtained through pooling operations). Its mathematical formula is:
[0089]
[0090] In the formula Indicates the input feature map, Yes Global average pooling is performed to obtain the global features for each channel. The result is a graph with shape [formula missing]. The tensor, in which Indicates the number of channels. and It is the learned convolution kernel (1x1 convolution), and ReLU is the activation function (adding non-linearity). It is a sigmoid activation function that outputs the attention weights for each channel.
[0091] Specifically, the input feature map is first processed through a channel attention path, and then compressed into a global statistical description for each channel using global average pooling. Next, two channel-wise convolutional layers (each containing a ReLU activation function) are used to extract the non-linear response weights. Finally, a sigmoid activation function is applied to output the channel attention weight vector ca, whose value is in the range [0,1], representing the importance of each channel. This weight is used to emphasize sensitive channels related to defects, such as the significant feature responses of metal fatigue textures and structural scratches.
[0092] On the other hand, the goal of spatial attention mechanisms is to enhance the features of certain regions by learning the weights of each spatial location in the image. The formula is:
[0093]
[0094] In the formula Indicates the input feature map, Yes Convolution operations are typically performed using a 3×3 convolution kernel; It is a sigmoid activation function that outputs spatial attention weights sa.
[0095] Specifically, in the spatial attention path, the original feature map is used to generate a spatial attention map through a 7×7 convolutional kernel. This map is used to capture spatially clustered anomalous regions in the image, such as rust patches or concentrated areas of track surface cracks. Spatial attention guides the model to focus on defective regions on a location-by-location basis.
[0096] Finally, the attention maps output from the two paths are fused with the original feature map through element-wise multiplication to output a refined feature map. This achieves residual feature recalibration, enabling the network to enhance the response of disease-related areas and suppress background interference during transmission. The formula is as follows:
[0097]
[0098] in and These represent channel attention and spatial attention, respectively. This is the input feature map.
[0099] The dual-path residual attention enhancement module in this embodiment breaks through the traditional single-path attention mode by introducing channel attention and spatial attention structures, and employs a parallel fusion strategy to enhance input features, achieving simultaneous modeling and enhancement of spatial regions and channel dimensions. By computing channel and spatial attention in parallel and fusing them in a residual manner, this mechanism can more accurately and unbiasedly evaluate feature importance.
[0100] 23. Construct a variational autoencoder (DPRA-VAE) based on dual-path residual attention and multi-domain collaborative optimization.
[0101] The disease identification model adopts a variational autoencoder (encoder-decoder) architecture, namely a variational autoencoder (DPRA-VAE) based on dual-path residual attention and multi-domain collaborative optimization.
[0102] Figure 7 This is a schematic diagram of the overall framework of a DPRA-VAE method provided in an embodiment of this application. Figure 7 As shown:
[0103] The encoder section includes:
[0104] First, the input railway track image x undergoes shallow feature fusion, which includes two paths, as follows:
[0105] Path 1 (Spatial Path): x is input into the shallow convolutional structure layer0 of the ResNet network (as the backbone) (containing basic convolutions, pooling, and initial residual blocks), and spatial structure features F_res are extracted;
[0106] Path 2 (Frequency Domain Path): x is input to the FreqEncoder module constructed in step 21, and outputs the fused frequency domain feature map F_freq.
[0107] Feature alignment and fusion: Before channel concatenation, to ensure the consistency of the dimensions of the two features, bilinear interpolation is used to unify the spatial dimensions of F_res and F_freq (i.e., align with the layer 0 output resolution of the ResNet network). Subsequently, concatenation is performed along the channel dimension to obtain the fused feature F_fusion, and the number of channels is compressed / adapted through 1×1 convolution to meet the input channel requirements of the subsequent backbone network.
[0108] The fused F_fusion is then input into the high-level structure of the ResNet (containing 4 residual blocks) within the DPRA module. Simultaneously, the DPRA module constructed in step 22 is embedded between or within the original residual blocks of the ResNet (e.g., ...). Figure 7 As shown in the diagram, a DPRA module is added after the output of each residual block. To control model complexity and improve generalization ability, the parameters of ResNet's layer 2 and layer 3 are frozen, and only other key modules are trained.
[0109] After the feature map F_fusion is processed by a deep DPRA-ResNet, a high-level feature map is obtained. Fully connected layers are then used to generate latent variable parameters, i.e., mean vectors, representing the distribution of the input data. and latent variable variance vector Then, reparameter sampling is performed to obtain the latent spatial variables.
[0110] The decoder part includes:
[0111] The latent spatial variables output by the encoder are fed into a fully connected layer (FC layer) to expand them into a feature vector with a sufficient number of elements to reshape them into a small initial feature map. A series of upsampling layers combined with convolutional blocks are used to progressively increase the feature map size and restore details. The last convolutional block uses the sigmoid activation function to output the reconstructed image. Its size is the same as the original input image. The same applies; the pixel value range is [0,1].
[0112] Meanwhile, this application's embodiments construct a multi-domain collaborative optimization loss function, defined in both pixel and frequency spaces, ensuring collaborative optimization of the model in terms of content consistency and high-frequency detail fidelity, guiding the network to more comprehensively restore image content. Total loss Defined as the weighted sum of the two, where and These are hyperparameters used to balance the reconstruction loss and frequency domain loss, and their formulas are as follows:
[0113]
[0114] 1. Reconstruction Loss ( This loss is calculated in pixel space and measures the original image. With reconstructed image The differences between them are the foundation for ensuring content consistency. A binary cross-entropy (BCE) loss is used, where... This indicates the total number of pixels in the image:
[0115]
[0116] 2. Frequency domain loss ( To directly force the model to learn high-frequency details from the optimization objective, a frequency domain loss is introduced. This loss calculates the L1 norm distance between the original image and the reconstructed image in the Fourier domain, directly penalizing the difference in the frequency domain.
[0117]
[0118] in This represents the Fast Fourier Transform. Since image anomalies (such as scratches and blemishes) are usually manifested as high-frequency signal disturbances, constraining the differences in the frequency domain can capture these subtle changes more sensitively than pixel-level loss, thereby guiding the decoder to generate images with clearer textures and richer details.
[0119] In one alternative implementation, the dual-path attention mechanism mentioned in the embodiments of this application may not only consider this one attention mechanism, but may also consider channel attention mechanism (ECA), squeeze and excitation (SE) attention mechanism, etc.; in addition to variational autoencoder architecture, other single-class unsupervised detection architectures may be considered for rail defect detection, and the embodiments of this application do not limit this.
[0120] In this embodiment, the aforementioned frequency domain fusion mechanism and attention enhancement module are introduced into the ResNet backbone structure to improve the fusion capability between shallow texture details and deep structural semantics. A multi-domain loss function co-optimized in the pixel and frequency domains is constructed. By directly applying constraints in the frequency domain, the model is guided to accurately reconstruct the normal high-frequency texture of a normal railway track from the optimization objective. This not only ensures content consistency but also forces the model to learn and memorize the key "normal" component of high-frequency texture details. Therefore, when encountering defects, the model produces significant errors in both domains because it cannot reconstruct the "abnormal" features, greatly improving detection sensitivity.
[0121] 3. Training and testing of the disease identification network
[0122] Based on the rail surface images collected in step 21, the unsupervised learning model constructed in step 23 is trained. The optimal model obtained from the training is then used to identify rail surface defects, yielding the defect identification results. Specifically:
[0123] Training data: The training set prepared in step 21 is used, which contains only enhanced images of normal (defect-free) rail tracks. Crucially, the model is never exposed to any defective samples or their annotations throughout the training process.
[0124] Training objective: The training objective of the model (DPRA-VAE) is to minimize the multi-domain collaborative loss function constructed in step 23. By minimizing The encoder learns to compress a normal image into highly generalized latent features, while the decoder learns to reconstruct the normal input image from these features with high fidelity. Essentially, this process allows the model to accurately learn and memorize the complete feature distribution of a normal railway track surface in both pixel and frequency spaces, thereby constructing a tight "normal distribution" model in the latent space.
[0125] 33. In reconstructive anomaly detection tasks, the training objective of the model is to reconstruct the input image to the greatest extent possible. Since the model is trained only on normal samples, the trained network exhibits structural biases when reconstructing anomaly images from the test set, with higher multi-domain loss values for diseased images. Therefore, the following technical approach can be adopted:
[0126] Forward propagation and error calculation: The image of the railway track to be detected is input into the trained DPRA-VAE model to obtain its reconstructed image. Then, the multi-domain collaborative loss function value between the input image and the reconstructed image is calculated. This loss value is defined as the anomaly score of the image. The higher the anomaly score, the greater the deviation of the input image from the "normal" state.
[0127] Threshold setting: To distinguish between normal and abnormal samples, a scientific method for setting a threshold is needed. This invention employs a statistical method: using the loss values of all normal samples during the training phase to calculate a baseline threshold. Specifically, the mean of the abnormal scores of normal samples in the training set can be calculated and set as a threshold.
[0128] Disease identification:
[0129] If the abnormality score of the image under test is less than or equal to the threshold T, the image is considered normal; if the abnormality score of the image under test is greater than the threshold T, the image is considered abnormal (i.e., there is a defect).
[0130] Therefore, the multi-domain loss value is denoted as the anomaly score, and the threshold is set to the average loss value of the training set. If the anomaly score of an image is greater than this threshold, it indicates that there is damage to the railway track in the image. Optionally, this threshold can be determined on a validation set composed of normal samples, for example, it can be set as the maximum value of the anomaly scores of all normal samples on the validation set or a certain high quantile (such as the 99th quantile). If the anomaly score of the image to be detected is greater than this threshold, the image is determined to have anomalies, that is, there is damage to the railway track surface; otherwise, it is determined to be a normal image.
[0131] The above methods can be referenced. Figure 1 The specific descriptions of the embodiments shown are not repeated here.
[0132] Through the above methods, the embodiments of this application can effectively utilize complementary information in the spatial domain and frequency domain, enhance key features through an unbiased attention mechanism, and finally force the model to focus on the reconstruction of high-frequency details by means of a multi-domain collaborative loss function, thereby significantly improving the detection capability of minor and early rail defects and reducing the false negative rate.
[0133] Existing methods primarily rely on convolutional neural networks (CNNs) to extract spatial domain (pixel-level) features from images, resulting in the complete neglect of crucial frequency domain information that reveals the image's intrinsic physical properties (such as periodic textures and minor scratches). In particular, early, minute defects (such as slight detachment) manifest as unique high-frequency perturbations in the frequency domain. Therefore, relying solely on spatial domain features makes the model extremely insensitive to these subtle anomalies, ultimately leading to insufficient detection accuracy and the easy omission of minute defects. The wavelet-Fourier frequency domain feature extraction module (Freq Encoder) in this application embodiment synergistically utilizes the localization capability of wavelet transform and the global spectral analysis capability of Fourier transform to deeply mine the frequency domain physical properties of images, significantly improving the model's ability to capture minute, high-frequency defect features.
[0134] Current mainstream sequential attention modules (such as CBAM) require sequential execution of channel attention and spatial attention operations. This causes the earlier attention operation (such as channel attention) to alter the distribution of the feature map, resulting in unexpected information suppression or misleading effects on the later attention operation (such as spatial attention) (the order bias problem). Therefore, it is impossible to perform unbiased and joint evaluation of feature importance in the channel and spatial dimensions, ultimately limiting the effectiveness of feature enhancement and affecting the accuracy of the model's response to diseased areas. The Parallel Dual-Path Residual Attention Module (DPRA) proposed in this application eliminates the order bias of the sequential mechanism by decoupling and synchronizing channel and spatial attention, achieving unbiased enhancement of key features.
[0135] Currently, the optimization objective of standard variational autoencoders (VAEs) (pixel-level reconstruction loss + KL divergence) tends to prioritize global structural similarity during training, resulting in the sacrifice of high-frequency texture details during reconstruction and widespread blurring in the reconstructed images. Therefore, when the input contains minor texture variations or anomalies such as fine cracks, the pixel-level difference between the reconstructed image and the original anomalous image becomes extremely weak, making it difficult for the model to effectively identify these subtle differences and causing serious missed detections. The multi-domain loss function constructed in this application, which co-optimizes the pixel and frequency domains, guides the model to accurately reconstruct high-frequency textures by directly applying constraints in the frequency domain, based on the optimization objective.
[0136] In summary, the method in the embodiments of this application has the following key technical features and advantages:
[0137] 1. An unsupervised method for detecting railway surface defects is proposed, based on a dual-path residual attention VAE (DPRA-VAE) and multi-domain collaborative optimization. This method enables the VAE to learn the "healthy" features inherent in normal samples during the training phase, constructing a highly accurate "normal pattern distribution" in the latent space. During inference, anomalies are identified by calculating the degree of deviation of the input image from this inherent "normality" (frequency domain / pixel reconstruction error).
[0138] 2. The designed wavelet-Fourier frequency domain feature extraction module (Freq Encoder) utilizes the localization capability of wavelet transform and the global spectral analysis capability of Fourier transform to capture the complete feature representation of a normal railway track surface in the frequency domain. This ensures that the "normal" aspect learned by the model includes not only the macroscopic structure (wavelet low-frequency subband) but also subtle high-frequency information such as texture periodicity and granularity (wavelet high-frequency subband, Fourier spectrum).
[0139] 3. The proposed Parallel Dual-Path Residual Attention Module (DPRA) eliminates the sequential bias of the serial mechanism by decoupling and synchronizing channel and spatial attention, achieving unbiased enhancement of key features. It protects and strengthens the feature channels and spatial positions representing the "normal state" rather than simply looking for "defects". This ensures that features representing normal railway background and healthy texture are preserved and enhanced in deep networks, resulting in a purer and more discriminative "normal" potential distribution.
[0140] 4. The constructed multi-domain loss function, which co-optimizes the pixel and frequency domains, guides the model to accurately reconstruct the "normal input" from the optimization objective by directly applying constraints in the frequency domain. It simultaneously constrains the model from both pixel and frequency domain dimensions to accurately reconstruct all the details of the normal sample.
[0141] In one embodiment of this application, an electronic device is also provided. See also... Figure 8 , Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 8 As shown, the electronic device 800 includes a processor 801 and a memory 802. The memory 802 stores a computer program, which, when executed by the processor 801, will perform actions such as... Figure 1 or Figure 3 Any step in the method embodiment shown. The electronic device 800 may also include input / output devices, etc. In a specific embodiment, the electronic device may be a terminal device, etc.
[0142] In one embodiment, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor 801, causes the processor 801 to perform any of the steps in the above method embodiments.
[0143] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.
[0144] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0145] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.
Claims
1. A method for detecting rail defects based on multi-domain collaborative optimization, characterized in that, The method includes: Spatial and frequency domain features of the image to be detected are extracted in parallel, and the spatial and frequency domain features are fused to obtain multi-domain fused features. The frequency domain features are generated by performing at least two different frequency domain transformations on the image to be detected in parallel and fusing the transformation results. The at least two different frequency domain transformations include discrete wavelet transform and fast Fourier transform. The discrete wavelet transform decomposes the image to be detected into a low-frequency approximation component and multiple high-frequency detail components. The fast Fourier transform obtains the real and imaginary parts of the transformation result. The multi-domain fusion features are processed by a parallel attention module to generate enhanced features. The parallel attention module includes at least two parallel attention paths, which generate attention weights from different dimensions and fuse the generated attention weights with the multi-domain fusion features. Output latent spatial variables based on the enhanced features; The image to be detected is reconstructed based on the latent spatial variables to obtain the reconstructed image; Based on the reconstructed image and the image to be detected, a multi-domain loss is calculated; the multi-domain loss includes a weighted sum of pixel domain reconstruction loss and frequency domain reconstruction loss; the pixel domain reconstruction loss adopts binary cross-entropy loss or mean square error loss; the frequency domain reconstruction loss adopts the L1 norm distance between the image to be detected and the reconstructed image in the Fourier domain or the L2 norm distance between the high-frequency component coefficients in the wavelet domain. The multi-domain loss is used as the anomaly score, and the presence of anomalies in the image to be detected is determined based on the comparison between the anomaly score and a preset threshold.
2. The rail defect detection method based on multi-domain collaborative optimization according to claim 1, characterized in that, The at least two parallel attention paths include a channel attention path and a spatial attention path; The channel attention path generates channel attention weights through global average pooling and convolutional layers; the spatial attention path generates a spatial attention map through a convolutional layer.
3. The rail defect detection method based on multi-domain collaborative optimization according to claim 1, characterized in that, The frequency domain reconstruction loss is calculated based on the difference between the image to be detected and the reconstructed image in the frequency domain.
4. The rail defect detection method based on multi-domain collaborative optimization according to claim 1, characterized in that, The image to be detected is an image of the surface of a railway track. The step of determining whether the image to be detected has an anomaly based on the comparison result of the anomaly score and a preset threshold includes: If the anomaly score of the rail surface image is greater than the preset threshold, it is determined that there is a defect in the rail in the rail surface image.
5. A rail defect detection device based on multi-domain collaborative optimization, characterized in that, It includes an encoder, a decoder, a loss calculation module, and a decision module; among which: The encoder includes: A feature extraction unit is used to extract spatial and frequency domain features of the image to be detected in parallel, and fuse the spatial and frequency domain features to obtain multi-domain fused features. The frequency domain features are generated by performing at least two different frequency domain transformations on the image to be detected in parallel and fusing the transformation results. The at least two different frequency domain transformations include discrete wavelet transform and fast Fourier transform. The discrete wavelet transform decomposes the image to be detected into a low-frequency approximation component and multiple high-frequency detail components. The fast Fourier transform obtains the real and imaginary parts of the transformation result. A parallel attention module is used to process the multi-domain fusion features to generate enhanced features. The parallel attention module includes at least two parallel attention paths, which generate attention weights from different dimensions and fuse the generated attention weights with the multi-domain fusion features. The encoder is used to output latent spatial variables based on the enhanced features; The decoder is used to reconstruct the image to be detected based on the latent spatial variables to obtain a reconstructed image; The loss calculation module is used to calculate a multi-domain loss based on the reconstructed image and the image to be detected. The multi-domain loss includes a weighted sum of pixel domain reconstruction loss and frequency domain reconstruction loss. The pixel domain reconstruction loss uses either binary cross-entropy loss or mean square error loss. The frequency domain reconstruction loss uses the L1 norm distance between the image to be detected and the reconstructed image in the Fourier domain or the L2 norm distance between the high-frequency component coefficients in the wavelet domain. The judgment module is used to take the multi-domain loss as an anomaly score and determine whether the image to be detected has an anomaly based on the comparison result of the anomaly score and a preset threshold.
6. An electronic device, characterized in that, It includes a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps of the method as described in any one of claims 1-4.
7. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it causes the processor to perform the steps of the method as described in any one of claims 1-4.
Citation Information
Patent Citations
SAR (Synthetic Aperture Radar) image change detection method based on double-domain network
CN117690019A