Improved SwinIR-based low-illumination urban rail train key part defect image reconstruction and defect detection method and system
By using a cascaded scheme of the improved SwinIR model and the YOLO detection model, the problem of high-resolution reconstruction and detection of defects in key parts of urban rail trains under low-light conditions was solved, achieving high-accuracy defect detection, especially for the detection of small defects under complex lighting conditions.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CRRC (CHONGQING) SMART RAIL TRANSIT TECHNOLOGY CO LTD
- Filing Date
- 2025-12-23
- Publication Date
- 2026-05-01
AI Technical Summary
Existing technologies struggle to effectively recover high-resolution and detailed information from images of critical defects in urban rail trains under low-light conditions, resulting in insufficient detection accuracy, especially for small targets and weak-contrast defects under complex lighting conditions.
An improved SwinIR model is adopted, which performs cross-window aggregation through deep integration of L3DG layers. Combined with three prior gating of defect significance, exposure deviation and noise intensity, pseudo-high frequencies and noise are suppressed. In addition, frequency domain bandpass cleaning and joint attention mechanism are combined to reconstruct high-resolution images. The reconstructed images are then input into an optimized YOLO detection model for defect detection.
It significantly improves the accuracy and recall rate of defect detection under low light conditions, especially the ability to detect difficult-to-detect defects such as fine cracks and low-contrast wear, and enhances the ability to detect defects in key parts of urban rail trains.
Smart Images

Figure CN121962016A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer vision and image processing, specifically to a method and system for image reconstruction and defect detection of key parts of urban rail trains in low light conditions based on an improved SwinIR. Background Technology
[0002] In the field of urban rail transit, accurate detection and maintenance of critical track components (such as bearings, bolted connections, and welds) are crucial. Image information from these critical components plays an irreplaceable role in fault diagnosis, condition assessment, and preventative maintenance. However, in actual shooting, due to the limitations of special environments such as underground tunnels, images of these critical components often face low-light conditions. Images of critical components of urban rail trains under low-light conditions commonly suffer from low resolution, blurred details, and significant noise. Traditional image enhancement methods, such as histogram equalization and contrast-limited adaptive histogram equalization (CLAHE), can improve image brightness and contrast to some extent, but they are insufficient to effectively improve image resolution and restore detail. Simple interpolation algorithms for magnification result in blurred edges and artifacts, failing to meet the demands for high-resolution, clear images in practical applications. Existing deep learning-based super-resolution methods, such as SRCNN and GAN, while improving image resolution and quality to some extent, still have limitations when processing images of critical components of urban rail trains in low-light conditions. These methods are poorly adapted to the noise distribution and uneven lighting conditions unique to images under low light conditions. They also fail to capture the unique textures and structural features of key parts of urban rail trains (such as bolts and welds on the rails), and these parts have defects, resulting in insufficient detail and realism in the generated images, making it difficult to meet the high-precision image standards required for professional inspection and maintenance.
[0003] Furthermore, defect images of critical components of urban rail transit often possess complex textures, intricate structures, and important semantic information. However, existing methods have limited effectiveness in preserving and enhancing these key features when processing low-light images, easily losing or blurring details of critical components, thus affecting subsequent detection and analysis. Moreover, there are many difficulties in detecting defects in critical components of urban rail transit. In urban rail operation and safety inspection scenarios, factors such as low illumination, strong reflections, occlusion, and structural similarity cause critical components of the vehicle body (such as bolts, connectors, cracks, and wear edges) to exhibit visual characteristics such as small targets, multiple scales, and weak contrast, posing significant challenges to defect detection.
[0004] Therefore, there is an urgent need for an innovative, end-to-end solution that can first perform high-quality restoration and reconstruction of low-resolution defect images acquired under low lighting conditions, and then input them into the defect detection model, thereby comprehensively improving the accuracy of defect detection and system robustness of key parts of urban rail trains under complex lighting conditions. Summary of the Invention
[0005] The purpose of this invention is to provide a method and system for image reconstruction and defect detection of key parts of urban rail trains in low light conditions based on an improved SwinIR, so as to at least solve the problem that current methods cannot capture fine features in images of defects in key parts caused by environmental factors such as low light conditions.
[0006] To address the aforementioned technical problems, in a first aspect, this invention provides a method for image reconstruction and defect detection of key components of urban rail trains under low-light conditions based on an improved SwinIR, comprising the following steps:
[0007] S1: Based on the downsampling of images of defects in key parts of urban rail trains collected under low light conditions, low-resolution image pairs corresponding to high-resolution images are generated to construct a dataset; and the dataset is divided into training set, validation set and test set.
[0008] S2: Construct an improved SwinIR-based image reconstruction model for key defect parts of urban rail trains in low-light conditions. The model includes a shallow feature map extraction module, a deep feature map extraction module, and a reconstruction module. The shallow feature map extraction module includes a 3×3 convolutional layer, which outputs shallow feature maps of the low-resolution image. The deep feature map extraction module includes multiple cascaded RSTB blocks, each of which integrates an L3DG layer, and outputs shallow feature maps to extract deep feature maps of the low-resolution image. The reconstruction module includes a residual module, a convolutional layer, and a pixel shuffling operation module, which outputs a reconstructed image.
[0009] S3: Design a loss function, use the training set and validation set to train the improved SwinIR low-light urban rail train key part defect image reconstruction model to obtain the trained optimal model and weights; then use the test set to test the trained optimal model and evaluate the test results.
[0010] S4: Input the defect images of key parts of urban rail trains into the trained improved SwinIR low-light urban rail train key part defect image reconstruction model to obtain the final super-resolution reconstructed image.
[0011] Furthermore, the method also includes:
[0012] S5: Input the super-resolution reconstructed image into the YOLO detection model for defect detection, and output the category, bounding box location, and distribution regression results of the defect targets in the image.
[0013] Furthermore, step S1 also includes preprocessing the low-resolution images in the dataset, including:
[0014] Perform image normalization, denoising, and data augmentation operations;
[0015] Data augmentation operations include random cropping, rotation, flipping, and color dithering.
[0016] Furthermore, the shallow feature map extraction module includes a 3×3 convolutional layer, and the output of the shallow feature map extraction module is:
[0017] ;
[0018] in, This represents the input image. This represents a convolutional layer with a 3×3 kernel. This represents the output shallow feature map, where H and W represent the height and width of the input image, respectively, and C represents the number of channels in the feature map.
[0019] Furthermore, the RSTB block integrates an L3DG layer for prior-guided sparse fusion of cross-window information, specifically including:
[0020] Three prior generation: for input or intermediate feature maps Defect saliency maps are generated using lightweight convolutional branches. Exposure deviation diagram Noise intensity diagram ;
[0021] Gating scoring and sparse neighbor window selection: First, select the current window. any candidate neighbor window The window average is calculated to obtain the gating score. The calculation formula is as follows:
[0022] ;
[0023] Then by temperature The softmax function yields the gate weights, calculated using the following formula:
[0024] ;
[0025] Where: D is the defect saliency map, with a value range of [0,1], representing the pixel region in the image related to the defect; E is the exposure deviation map, representing the exposure degree of each pixel in the image, with a real value, describing the deviation of lighting conditions; N is the noise intensity map, with a value range of [0,1], representing the intensity of noise in the image; Candidate neighboring windows represent the current window. Adjacent windows; To calculate adjacent windows The mean value within; β and γ are hyperparameters used to control the weights of defect significance, exposure deviation, and noise intensity in the gating score; η( (for adjacent windows) The score is calculated from the previous formula; η(u) is the score for set C( The score of any primitive u in ); τ is a temperature parameter that controls gating sparsity, with smaller temperature values enhancing sparsity; C(W) is the current window The set of candidate neighboring windows; exp( ) is an exponential function used to calculate softmax;
[0026] Frequency domain bandpass cleaning and cross-window aggregation: for selected neighboring windows value vector After applying frequency domain bandpass operations and then weighted aggregation, the calculation formula is as follows:
[0027] ;
[0028] ;
[0029] in: For the current neighboring window The value vector; For bandpass mask, it represents the frequency band that needs to be retained in the frequency domain, used to remove pseudo-high frequencies and noise; The Fast Fourier Transform (FFT) is used to transform a value vector into the frequency domain. The inverse fast Fourier transform (IFFT) converts the frequency domain signal back to the time domain; For adjacent windows that have undergone frequency domain bandpass cleaning The value vector; For the neighboring window The gating weight represents the selection weight for each adjacent window; This is the value vector after cross-window aggregation; Current window The set of candidate neighboring windows;
[0030] For the selected neighbor window key vector After applying frequency domain bandpass operations and then weighted aggregation, the calculation formula is as follows:
[0031] ;
[0032] ;
[0033] in: For the current neighboring window The key vector; For adjacent windows that have undergone frequency domain bandpass cleaning The key vector, The key vector after cross-window aggregation;
[0034] Joint attention: , The window output will then be:
[0035] ;
[0036] in: The concatenated key vector contains information about the current window and the windows spanning it. This is a key vector representing key information of the current window; This is the concatenated value vector, containing information about the current window and the windows spanning it. The value vector of the current window; The output features of the current window W represent the features processed by the attention mechanism. d is the query vector, representing the feature information of the current window; d is the feature dimension, representing the dimension of the query and key vectors; B is the bias term, used to adjust the weights of the calculation; M is the mask term, used to control the effective calculation area.
[0037] No-shift index mapping: Read neighbor window tokens in a gather manner through a pre-compiled neighbor window index table.
[0038] Furthermore, the reconstruction module first uses a residual module to perform residual fusion of shallow and deep features to obtain a fused feature image; then, a convolutional layer is used to increase the number of channels of the fused feature image to C×r. 2 The output size is H×W×(C×r) 2 The feature map of H×W×(C×r) is then used to perform a pixel shuffling operation on the feature map. 2 The feature map is upsampled to output a reconstructed image of size (H×r)×(W×r)×C.
[0039] Furthermore, the loss function is:
[0040] ;
[0041] in: The total loss represents the training objective of the model. , and These are the weights of the loss terms, representing the importance of controlling different loss terms; and , respectively, represent the intensity values at pixel i in the reconstructed image and the original image; ∇ is the gradient operator, used to calculate the gradient of the image; It is a robust constant to prevent numerical instability; The mean of the reconstructed image; This is the mean value of the target image (e.g., the target exposure mean).
[0042] Furthermore, the test results are evaluated, specifically including:
[0043] The peak signal-to-noise ratio (PSNR) of the optimal model is calculated using the following formulas:
[0044] ;
[0045] ;
[0046] Where: MSE is the mean squared error, a commonly used loss function to measure the quality of image reconstruction. The smaller the value, the closer the reconstruction result is to the real image. Original images In the passage Pixel values at the location, reconstruct the image The pixel value at channel c.
[0047] Furthermore, the YOLO detection model includes a backbone network, a neck network, and a DPA detection head; the method used to detect defects in key parts of urban rail trains using the YOLO detection model is as follows:
[0048] The super-resolution reconstructed image first enters the backbone network, and then goes through multiple convolutional layers and C3k2 structure to complete step-by-step downsampling and semantic extraction. In the deep layers, SPPF is used to gather multi-scale context and C2PSA is used for attention enhancement to obtain bottom-up high semantic features.
[0049] Then, the neck network is upsampled from top to bottom using FPN / PAN, and the high-level semantics and shallow details of adjacent layers are concatenated laterally using Concat, and fused with C3k2 to obtain fine-grained pyramid features; then, the convolution backpropagation downsampling is fused with subsequent Concat and C3k2 to form medium-scale and large-scale outputs in sequence, thus obtaining a three-scale feature group.
[0050] Then, DPA detection is used to extract and perform pyramid context encoding on each path in a multi-branch manner. Dynamic fusion across branches and scales is completed through position-adaptive gating. Finally, the class confidence and boundary distribution are output by decoupled classification and distributed regression subheaders. After cross-scale merging and post-processing, the detection results of defects in key parts of urban rail are obtained.
[0051] Finally, the YOLO detection model is transferred to the reconstructed images and trained for 200 epochs to obtain weights. Based on the weights obtained after training the YOLO detection model, prediction and inference are performed on the test set.
[0052] Secondly, the present invention provides a low-light urban rail train critical component defect image reconstruction and defect detection system based on improved SwinIR, including a processor and a memory; wherein, the memory is used to store computer execution instructions, and when the system device is running, the processor executes the computer execution instructions stored in the memory to make the device perform the method provided in the first aspect above.
[0053] The beneficial effects of this invention are as follows:
[0054] 1. By deeply integrating the L3DG layer into the SwinIR framework, the model can effectively aggregate "valuable" neighborhood information across windows in low-light scenes: through three prior gating mechanisms of defect saliency, exposure deviation, and noise intensity, the correct window is selected before fusion. Before fusion, pseudo-high frequencies and ringing are cleaned with frequency domain bandpass. Before cross-window aggregation, the value vector is cleaned with frequency domain bandpass to suppress common low-light noise such as ringing, pseudo-high frequencies, and particle noise. Combined with the joint attention of this window and cross windows, the structural continuity of key parts of urban rail trains and fine-grained edge textures (such as bolt outlines, connector gaps, and crack endpoints) can be preserved at the same time.
[0055] 2. By inputting the reconstructed super-resolution image into the optimized YOLO detection model, the fine details restored in the reconstructed image can be fully utilized. Compared with directly detecting low-light images or using a general super-resolution model before detection, this cascaded scheme has significantly improved the defect recall, accuracy, and mean precision (mAP), especially the ability to detect difficult defects such as fine cracks and low-contrast wear.
[0056] 3. By combining ROI weighting, gradient consistency, and exposure correction loss loop training, the model becomes more focused on real defect structures and more robust to underexposure in dark areas, enhancing its ability to capture long-distance dependencies and extract local details. Utilizing its enhanced feature extraction and image restoration capabilities, the model accurately constructs a mapping model between a large number of low-resolution and high-resolution images of defects in key parts of urban rail trains under low light conditions, thereby performing super-resolution reconstruction of the images and ultimately outputting high-resolution, detailed images of defects in key parts of urban rail trains. The generated images are then fed into the improved YOLOv11 model for transfer learning to detect defects in key parts of urban rail trains.
[0057] 4. By adopting an improved YOLO detection model, defects in key parts of urban rail trains can be detected accurately and quickly. Using the DPA detection head, different branches can focus on information at different scales and levels, avoiding the loss of small target features that may be lost under a single scale. Furthermore, the combination of channel attention and spatial attention can better select and focus on features related to small targets, enhancing the detection capability of small objects. Attached Figure Description
[0058] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, use the same reference numerals to denote the same or similar parts. The illustrative embodiments of this application and their descriptions are used to explain this application and do not constitute an undue limitation of this application. In the drawings:
[0059] Figure 1 This is a flowchart of the improved SwinIR super-resolution reconstruction process of the present invention;
[0060] Figure 2 This is a flowchart of the improved YOLO detection process for defects in low-light urban rail trains according to the present invention.
[0061] Figure 3 This is the overall flowchart of the present invention. Detailed Implementation
[0062] like Figure 1 The method for image reconstruction and defect detection of key parts of urban rail trains in low-light conditions, based on the improved SwinIR, includes the following steps:
[0063] S1: Based on downsampling of images of defects in key parts of urban rail trains collected under low light conditions, generate low-resolution image (LR) pairs corresponding to high-resolution images (HR) to construct a dataset; and divide the dataset into training set, validation set and test set; the dataset size can consist of 200 images with a resolution of 512x512;
[0064] S2: Construct an improved SwinIR-based image reconstruction model for key defect parts of urban rail trains in low-light conditions. The model includes a shallow feature map extraction module, a deep feature map extraction module, and a reconstruction module. The shallow feature map extraction module includes a 3×3 convolutional layer, which outputs shallow feature maps of the low-resolution image. The deep feature map extraction module includes multiple cascaded RSTB blocks, each of which integrates an L3DG layer, and outputs shallow feature maps to extract deep feature maps of the low-resolution image. The reconstruction module includes a residual module, a convolutional layer, and a pixel shuffling operation module, which outputs a reconstructed image.
[0065] S3: Design a loss function, use the training set and validation set to train the improved SwinIR low-light urban rail train key part defect image reconstruction model to obtain the trained optimal model and weights; then use the test set to test the trained optimal model and evaluate the test results.
[0066] S4: Input the defect images of key parts of urban rail trains into the trained improved SwinIR low-light urban rail train key part defect image reconstruction model to obtain the final super-resolution reconstructed image.
[0067] This invention deeply integrates the L3DG layer into the SwinIR framework, enabling the model to purposefully aggregate "valuable" neighborhood information across windows in low-light scenarios. By using three prior gating mechanisms—defect salience, exposure bias, and noise intensity—the correct windows are selected before fusion. Before fusion, pseudo-high frequencies and ringing are cleaned with frequency domain bandpass filtering. Before cross-window aggregation, the value vector is cleaned with frequency domain bandpass filtering to suppress common low-light noise such as ringing, pseudo-high frequencies, and particle noise. Combined with the joint attention of this window and cross-windows, the structural continuity of key parts of urban rail trains and fine-grained edge textures (such as bolt outlines, connector gaps, and crack endpoints) can be preserved simultaneously.
[0068] According to one embodiment of this application, the method further includes:
[0069] S5: Input the super-resolution reconstructed image into the YOLO detection model for defect detection, and output the category, bounding box location, and distribution regression results of the defect targets in the image.
[0070] This invention also fully utilizes the fine details recovered in the reconstructed image by inputting the reconstructed super-resolution image into the optimized YOLO detection model. Compared with directly detecting low-light images or using a general super-resolution model before detection, this cascaded scheme significantly improves the defect recall, accuracy, and mean precision (mAP), especially enhancing the detection capability of difficult-to-detect defects such as fine cracks and low-contrast wear.
[0071] According to one embodiment of this application, step S1 further includes preprocessing the low-resolution images in the dataset, including: firstly, normalizing the defect images of key parts of the low-light urban rail train to normalize their pixel values to the range of [0,1]; then, using Gaussian filtering to denoise the images to reduce noise interference in the images; and finally, performing data augmentation operations, including random cropping, rotation, flipping, and color jittering, to expand the dataset size and enhance the generalization ability of the model.
[0072] According to one embodiment of this application, the shallow feature map extraction module includes a 3×3 convolutional layer, and the output of the shallow feature map extraction module is:
[0073] ;
[0074] in, This represents the input image. This represents a convolutional layer with a 3×3 kernel. This represents the output shallow feature map, where H and W represent the height and width of the input image, respectively, and C represents the number of channels in the feature map.
[0075] According to one embodiment of this application, the RSTB block integrates an L3DG layer to perform prior-guided sparse fusion of cross-window information, specifically including:
[0076] 1) Three-prior generation: For input or intermediate feature maps Defect saliency maps are generated using lightweight convolutional branches. Exposure deviation diagram Noise intensity diagram The three prior branches are... Convolution, nonlinear activation and Convolutional structure, outputting a single channel ;in From local brightness average With target exposure The difference is worth;
[0077] 2) Gating scoring and sparse neighbor window selection: First, for the current window... any candidate neighbor window The window average is calculated to obtain the gating score. The calculation formula is as follows:
[0078] ;
[0079] Then by temperature The softmax function yields the gate weights, calculated using the following formula:
[0080] ;
[0081] Where: D is the defect saliency map, with a value range of [0,1], representing the pixel region in the image related to the defect; E is the exposure deviation map, representing the exposure degree of each pixel in the image, with a real value, describing the deviation of lighting conditions; N is the noise intensity map, with a value range of [0,1], representing the intensity of noise in the image; Candidate neighboring windows represent the current window. Adjacent windows; To calculate adjacent windows The mean value within; β and γ are hyperparameters used to control the weights of defect significance, exposure deviation, and noise intensity in the gating score; η( (for adjacent windows) The score is calculated from the previous formula; η(u) is the score for set C( The score of any original u in ); τ is the temperature parameter, temperature During training, an annealing strategy is used to gradually reduce the gate sparsity to enhance gating sparsity; Soft-k sparsity (all neighboring windows participate, but...) is adopted during the training phase. (Sparse), HardTop-k routing is used in the inference phase (only retaining) (nearby windows); C(W) is the current window. The set of candidate neighboring windows; exp( ) is an exponential function used to calculate softmax;
[0082] 3) Frequency domain bandpass cleaning and cross-window aggregation: for selected neighboring windows value vector After applying frequency domain bandpass operations and then weighted aggregation, the calculation formula is as follows:
[0083] ;
[0084] ;
[0085] in: For the current neighboring window The value vector; For bandpass mask, it represents the frequency band that needs to be retained in the frequency domain, used to remove pseudo-high frequencies and noise; The Fast Fourier Transform (FFT) is used to transform a value vector into the frequency domain. The inverse fast Fourier transform (IFFT) converts the frequency domain signal back to the time domain; For adjacent windows that have undergone frequency domain bandpass cleaning The value vector; For the neighboring window The gating weight represents the selection weight for each adjacent window; This is the value vector after cross-window aggregation; Current window The set of candidate neighboring windows;
[0086] For the selected neighbor window key vector After applying frequency domain bandpass operations and then weighted aggregation, the calculation formula is as follows:
[0087] ;
[0088] ;
[0089] in: For the current neighboring window The key vector; For adjacent windows that have undergone frequency domain bandpass cleaning The key vector, The key vector after cross-window aggregation;
[0090] 4) Joint attention: , The window output will then be:
[0091] ;
[0092] Among them: Among them: The concatenated key vector contains information about the current window and the windows spanning it. This is a key vector representing key information of the current window; This is the concatenated value vector, containing information about the current window and the windows spanning it. The value vector of the current window; The output features of the current window W represent the features processed by the attention mechanism. d is the query vector, representing the feature information of the current window; d is the feature dimension, representing the dimension of the query and key vectors; B is the bias term, used to adjust the weights of the calculation; M is the mask term, used to control the effective calculation area.
[0093] 5) No shift index mapping: Read neighbor window tokens in a gather manner through a pre-compiled neighbor window index table.
[0094] Window size is (Number of tokens per window) Attention channel dimension is The attention complexity within the window is... The complexity of cross-window sparse aggregation is The total complexity is ,in .
[0095] According to one embodiment of this application, the steps taken by the reconstruction module to achieve its function are as follows:
[0096] First, the residual module is used to perform residual fusion of shallow and deep features to obtain a fused feature image. By using the residual module to perform residual fusion of shallow and deep features, feature fusion is achieved. This fusion method can preserve the low-frequency information and high-frequency details of the image, making the reconstructed image clearer and more natural. Long skip connections directly pass the shallow features extracted in the early stage to the later reconstruction stage of the network, enabling the network to make full use of the low-frequency information of the original image and avoid losing important global information during the reconstruction process, thereby improving the quality and stability of the reconstructed image.
[0097] Then, a convolutional layer is used to increase the number of channels in the fused feature image to C×r. 2 The output size is H×W×(C×r) 2 The feature maps are then rearranged to prepare data for subsequent pixel shuffling operations. This rearrangement increases the spatial resolution by a factor of r, while reducing the number of channels to 1 / r of the original number. 2 ;
[0098] Finally, the module performs a pixel shuffling operation on pixels of size H×W×(C×r). 2 The feature map is upsampled to output a reconstructed image of size (H×r)×(W×r)×C.
[0099] This embodiment directly upsamples the low-resolution feature map to the target resolution by using one convolution operation and one pixel shuffling operation, avoiding multiple convolution and pixel shuffling operations, reducing computational complexity and the number of parameters, and is suitable for lightweight image super-resolution tasks.
[0100] According to one embodiment of this application, the loss function is:
[0101] ;
[0102] in: The total loss represents the training objective of the model. , and These are the weights of the loss terms, representing the importance of controlling different loss terms; and , respectively, represent the intensity values at pixel i in the reconstructed image and the original image; ∇ is the gradient operator, used to calculate the gradient of the image; It is a robust constant to prevent numerical instability; The mean of the reconstructed image; This is the mean value of the target image (e.g., the target exposure mean).
[0103] The network is trained end-to-end using a composite loss consisting of a ROI-weighted robust pixel term, an edge gradient consistency term, and an exposure correction term, and then outputs a high-resolution result image via an upsampled reconstruction head.
[0104] According to one embodiment of this application, the evaluation of test results specifically includes:
[0105] The peak signal-to-noise ratio (PSNR) of the optimal model is calculated using the following formulas:
[0106] ;
[0107] ;
[0108] Where: MAX I : Maximum pixel value, 255 for 8-bit images; if already normalized to ,but MSE stands for Mean Squared Error, a commonly used loss function to measure the quality of image reconstruction. The smaller the value, the closer the reconstruction result is to the real image. Original images In the passage Pixel values at the location, reconstruct the image The pixel value at channel c.
[0109] According to one embodiment of this application, the YOLO detection model includes a backbone network, a neck network, and a DPA detection head (multi-branch patch-aware + cascaded channels / spatial attention); the method used to detect defects in key parts of urban rail trains using the YOLO detection model is as follows:
[0110] The super-resolution reconstructed image first enters the backbone network, and then goes through multiple convolutional layers and C3k2 structure to complete step-by-step downsampling and semantic extraction. In the deep layers, SPPF is used to gather multi-scale context and C2PSA is used for attention enhancement to obtain bottom-up high semantic features.
[0111] Then, the neck network is upsampled from top to bottom using FPN / PAN, and the high-level semantics and shallow details of adjacent layers are concatenated laterally using Concat, and fused with C3k2 to obtain fine-grained pyramid features; then, the convolution backpropagation downsampling is fused with subsequent Concat and C3k2 to form medium-scale and large-scale outputs in sequence, thus obtaining a three-scale feature group.
[0112] Finally, using the detection head, DPA is used to extract and perform pyramid context encoding in each path in a multi-branch manner. Dynamic fusion across branches and scales is completed through position-adaptive gating. Finally, the class confidence and boundary distribution are output by decoupled classification and distributed regression subheaders. After cross-scale merging and post-processing, the detection results of defects in key parts of urban rail are obtained.
[0113] Finally, the YOLO detection model is transferred to the reconstructed images and trained for 200 epochs to obtain weights. Based on the weights obtained after training the YOLO detection model, prediction and inference are performed on the test set.
[0114] In a second aspect, the present invention discloses a low-light urban rail train key component defect image reconstruction and defect detection system based on improved SwinIR, including a processor and a memory; wherein, the memory is used to store computer execution instructions, and when the system device is running, the processor executes the computer execution instructions stored in the memory to make the device perform the method provided in the first aspect above.
[0115] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.
Claims
1. A method for image reconstruction and defect detection of key parts of urban rail trains in low-light conditions based on improved SwinIR, characterized in that, Including the following steps: S1: Based on the downsampling of images of defects in key parts of urban rail trains collected under low light conditions, low-resolution image pairs corresponding to high-resolution images are generated to construct a dataset; and the dataset is divided into training set, validation set and test set. S2: Construct an improved SwinIR-based image reconstruction model for key defects in low-light urban rail trains. The model includes a shallow feature map extraction module, a deep feature map extraction module, and a reconstruction module. The shallow feature map extraction module includes a 3×3 convolutional layer, outputting the shallow feature map of the low-resolution image. The deep feature map extraction module includes multiple cascaded RSTB blocks, each RSTB block integrating an L3DG layer, outputting the shallow feature map to extract the deep feature map of the low-resolution image. The reconstruction module includes a residual module, a convolutional layer, and a pixel shuffling operation module, outputting the reconstructed image. S3: Design a loss function, and use the training set and validation set to train the improved SwinIR low-light urban rail train key part defect image reconstruction model to obtain the trained optimal model and weights; then use the test set to test the trained optimal model and evaluate the test results. S4: Input the defect images of key parts of the urban rail train into the trained SwinIR low-light urban rail train key part defect image reconstruction model to obtain the final super-resolution reconstructed image.
2. The method for image reconstruction and defect detection of key parts of urban rail trains based on improved SwinIR according to claim 1, characterized in that, The method also includes: S5: Input the super-resolution reconstructed image into the YOLO detection model for defect detection, and output the category, bounding box position, and distribution regression results of the defect targets in the image.
3. The method for image reconstruction and defect detection of key parts of urban rail trains based on improved SwinIR according to claim 1 or 2, characterized in that, Step S1 further includes preprocessing the low-resolution images in the dataset, including: Perform image normalization, denoising, and data augmentation operations; The data augmentation operations include random cropping, rotation, flipping, and color dithering.
4. The method for image reconstruction and defect detection of key parts of urban rail trains based on improved SwinIR according to claim 3, characterized in that, The shallow feature map extraction module includes a 3×3 convolutional layer, and the output of the shallow feature map extraction module is: ; in, This represents the input image. This represents a convolutional layer with a 3×3 kernel. This represents the output shallow feature map, where H and W represent the height and width of the input image, respectively, and C represents the number of channels in the feature map.
5. The method for image reconstruction and defect detection of key parts of urban rail trains based on improved SwinIR according to claim 4, characterized in that, The RSTB block integrates an L3DG layer for prior-guided sparse fusion of cross-window information, specifically including: Three prior generation: for input or intermediate feature maps Defect saliency maps are generated using lightweight convolutional branches. Exposure deviation diagram Noise intensity diagram ; Gating scoring and sparse neighbor window selection: First, select the current window. any candidate neighbor window The window average is calculated to obtain the gating score. The calculation formula is as follows: ; Then by temperature The softmax function yields the gate weights, calculated using the following formula: ; Where: D is the defect saliency map; E is the exposure deviation map; N is the noise intensity map; As a candidate neighboring window; To calculate adjacent windows The mean value within; β and γ are hyperparameters; η( (for adjacent windows) The score, η(u) is the score for set C( The score of any original u in ); τ is the temperature parameter; C( () is the current window The set of candidate neighboring windows; exp( ) is an exponential function used to calculate softmax; Frequency domain bandpass cleaning and cross-window aggregation: for selected neighboring windows value vector After applying frequency domain bandpass operations and then weighted aggregation, the calculation formula is as follows: ; ; in: For the current neighboring window The value vector; For bandpass mask; For Fast Fourier Transform (FFT); This is the inverse fast Fourier transform; For adjacent windows that have undergone frequency domain bandpass cleaning The value vector; For the neighboring window Gating weights; This is the value vector after cross-window aggregation; Current window The set of candidate neighboring windows; For the selected neighbor window key vector After applying frequency domain bandpass operations and then weighted aggregation, the calculation formula is as follows: ; ; in: For the current neighboring window The key vector; For adjacent windows that have undergone frequency domain bandpass cleaning The key vector, The key vector after cross-window aggregation; Joint attention: , The window output will then be: ; in: This is the concatenated key vector; The key vector; This is the concatenated value vector; The value vector of the current window; Current window The output features represent the features processed by the attention mechanism. d is the query vector; d is the feature dimension; B is the bias term; M is the mask term; No-shift index mapping: Read neighbor window tokens in a gather manner through a pre-compiled neighbor window index table.
6. The method for image reconstruction and defect detection of key parts of urban rail trains based on improved SwinIR according to claim 5, characterized in that, The reconstruction module first uses the residual module to perform residual fusion of the shallow and deep features to obtain a fused feature image; then, it uses a convolutional layer to increase the number of channels of the fused feature image to C×r. 2 The output size is H×W×(C×r) 2 The feature map of H×W×(C×r) is then used to perform a pixel shuffling operation on the feature map. 2 The feature map is upsampled to output the reconstructed image with a size of (H×r)×(W×r)×C.
7. The method for image reconstruction and defect detection of key parts of urban rail trains based on improved SwinIR according to claim 1, characterized in that, The loss function is: ; in: Total loss; , and These are the weights of the loss terms; and represents the intensity values at pixel i in the reconstructed image and the original image, respectively; ∇ is the gradient operator; It is the robustness constant; The mean of the reconstructed image; The mean of the target image.
8. The method for image reconstruction and defect detection of key parts of urban rail trains based on improved SwinIR according to claim 1, characterized in that, The evaluation of the test results specifically includes: The peak signal-to-noise ratio (PSNR) of the optimal model is calculated using the following formula: ; ; Where: MSE is the mean squared error; Original images and reconstructed images In the passage The pixel value at that location.
9. The method for image reconstruction and defect detection of key parts of urban rail trains based on improved SwinIR according to claim 2, characterized in that, The YOLO detection model includes a backbone network, a neck network, and a DPA detection head; the method used to detect defects in key parts of urban rail trains using the YOLO detection model is as follows: The super-resolution reconstructed image first enters the backbone network, and then undergoes multi-layer convolution and C3k2 structure to complete step-by-step downsampling and semantic extraction. In the deep layers, multi-scale context is gathered by SPPF and attention is enhanced by C2PSA to obtain bottom-up high semantic features. Then, the neck network is upsampled from top to bottom using FPN / PAN, and the high-level semantics and the shallow details of the adjacent layers are concatenated laterally using Concat, and fused with C3k2 to obtain fine-grained pyramid features; Then, through convolution backpropagation downsampling and subsequent Concat and C3k2 fusion, medium-scale and large-scale outputs are formed in sequence, thus obtaining three-scale feature groups; Then, DPA detection is used to extract and perform pyramid context encoding on each path in a multi-branch manner. Dynamic fusion across branches and scales is completed through position-adaptive gating. Finally, the class confidence and boundary distribution are output by decoupled classification and distributed regression subheaders. After cross-scale merging and post-processing, the detection results of defects in key parts of urban rail are obtained. Finally, the YOLO detection model is trained for 200 epochs using transfer learning on the reconstructed images to obtain weights, and prediction and inference are performed on the test set based on the weights obtained after training the YOLO detection model.
10. A system for image reconstruction and defect detection of key components of urban rail trains in low-light conditions based on improved SwinIR, characterized in that, The system includes a processor and a memory; wherein the memory is used to store computer execution instructions, and when the system device is running, the processor executes the computer execution instructions stored in the memory to cause the device to perform the method of any one of claims 1-9.