Low-illumination track foreign matter intrusion detection method based on improved YOLOv8n

By improving the YOLOv8n model, combining adaptive image enhancement, RWSPPF module, spatially perceived attention mechanism and optimized loss function, the problem of low foreign object detection accuracy in low-illumination orbit environments is solved, and efficient and accurate foreign object intrusion detection is achieved.

CN119851225AInactive Publication Date: 2025-04-18SHANGHAI INST OF TECH
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202411962198.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-30
Publication Date
2025-04-18
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The existing railway track foreign object detection algorithm is difficult to identify the dangers caused by workers, animals or natural disasters with different postures in complex track environments, especially in low-illumination environments, which leads to low detection efficiency and poor accuracy, making it difficult to meet the needs of real-time and accurate detection.

Method used

The low-illumination orbital foreign object intrusion detection method based on improved YOLOv8n is adopted. By adding an adaptive enhancement module to the input end, replacing the SPPF module with the RWSPPF module, introducing a spatially perceived attention mechanism, and using the MDPIoU loss function and Adam optimizer, the YOLOv8n model is optimized to improve detection accuracy and adaptability.

Benefits of technology

The detection accuracy of the YOLOv8n model in low illumination environments has been significantly improved, the detection ability of foreign objects in complex orbital environments has been enhanced, real-time and accurate detection of foreign object intrusion, and the problem of difficulty in identifying in low illumination in the prior art is solved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119851225A_ABST
    Figure CN119851225A_ABST
Patent Text Reader

Abstract

The invention provides a low-illumination track foreign matter intrusion detection method based on improved YOLOv8n, and the method comprises the steps: carrying out the contrast enhancement, gamma correction and image sharpening of a low-illumination image through an adaptive enhancement module, improving the quality of an input image, and improving the precision of subsequent target detection; an SPPF module is replaced with an RWSPPF module in the YOLOv8n model, and a spatial perception attention mechanism is introduced, so that the multi-scale adaptive capacity and the feature extraction effect of the model are enhanced, and the foreign matter detection accuracy is improved; and an improved loss function and an Adam optimizer are adopted, so that the training efficiency and precision are improved. By calculating the intersection-to-union ratio and the shortest distance of the foreign matter and the track area, the danger degree of the foreign matter is evaluated, safety alarm information is generated in real time, and railway traffic safety is guaranteed. On the basis of the detection method, the track foreign matter can be accurately recognized under the low-illumination condition, the detection efficiency and safety are improved, and the method has wide application prospects.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of image processing, and in particular relates to a low-illumination track foreign object intrusion detection method based on improved YOLOv8n. Background Art

[0002] With the rapid development of urbanization and industrialization, railway transportation plays an important role in social economy with its high efficiency and safety. However, the problem of foreign object intrusion on the track, such as illegal entry of pedestrians, vehicles, and animals into the train clearance area, and track burial caused by natural disasters such as rockfalls and mudslides, has become a potential safety hazard that may lead to traffic accidents. In the complex track environment, the existing foreign object detection algorithms for rails still face challenges when applied to transportation systems. Different environments and scenarios increase the difficulty of feature extraction. Existing target detection algorithms have difficulty identifying workers, animals, or dangers caused by natural disasters in different postures when feature extraction is insufficient, especially in low-light environments. It becomes more difficult to ensure that all intrusive foreign objects are detected.

[0003] In order to solve these problems, most railway departments currently use patrol vehicles to detect foreign objects. However, traditional target detection methods, such as template matching and background difference methods, are not only computationally complex and time-consuming, but also easily affected by external environmental factors such as lighting changes and occlusions. These traditional patrol inspection methods have problems such as low detection efficiency and poor detection accuracy. In addition, due to the suddenness and unpredictability of foreign object intrusion, traditional methods often cannot meet the needs of real-time and accurate detection. Summary of the invention

[0004] The purpose of the present invention is to overcome the defects of the above-mentioned prior art and provide a low-illumination track foreign object intrusion detection method based on improved YOLOv8n.

[0005] The purpose of the present invention can be achieved by the following technical solutions:

[0006] The present invention provides a low-light track foreign body intrusion detection method based on improved YOLOv8n, comprising the following steps:

[0007] Acquire low-light track monitoring images;

[0008] The acquired image is input into the improved YOLOv8n model to identify the track area and output the detection frame information of the foreign object;

[0009] Evaluate the distance between the foreign object and the track area and the degree of danger based on the detection frame information of the foreign object;

[0010] The improved YOLOv8n model includes:

[0011] Add an adaptive enhancement module to the input of the YOLOv8n model;

[0012] Replace the SPPF module in the YOLOv8n model backbone network with the RWSPPF module;

[0013] Introduce a spatially aware attention mechanism in the C2f module of the neck network of the YOLOv8n model.

[0014] Furthermore, the adaptive enhancement module includes:

[0015] Perform contrast enhancement, gamma correction and image sharpening on the input image;

[0016] Perform contrast enhancement under the input image and prediction parameters to obtain a contrast enhanced image;

[0017] Performing gamma correction on the contrast-enhanced image to obtain a gamma-corrected image;

[0018] Perform Gaussian blur on the contrast-enhanced image to obtain the final enhanced image;

[0019] The final enhanced image is input into the subsequent improved YOLOv8n model for processing.

[0020] Furthermore, the image processing formula of the adaptive enhancement module is:

[0021]

[0022] I gamma =([W r I r ,W g I g ,W g I b ]) γ

[0023] I enhanced =GaussianBlur((I contrast +λ sharpen ·(I contrast -GaussianBlur(I contrast ,(3,3),σ=1)))),(0,0),σ

[0024] Among them, I contrast is the image after contrast enhancement, I gamma is the gamma-corrected image, I∈

[0025] R H×W×3 is the input image, I enhanced is the final enhanced image, Igamma,r , I gamma,g , I gamma,b They are the gamma-corrected images I gamma The red, green and blue channels of the GaussianBlur function are Gaussian blur function, (3,3) is the size of the Gaussian kernel, σ = 1 is the standard deviation of the Gaussian kernel, and λ sharpen is the image sharpening scale factor, α is the weighting coefficient, γ is the gamma correction index, W r , W g , W b are the weighting coefficients of the three color channels of RGB in the image, I r ,I g ,I b They are input images I∈R H×W×3 The pixel values ​​of the red, green, and blue channels in .

[0026] Furthermore, replacing the SPPF module in the YOLOv8n model backbone network with the RWSPPF module includes: replacing the SPPF module at position 10 in the structure of the YOLOv8n backbone network with the RWSPPF module.

[0027] Further, the RWSPPF module includes:

[0028] Adjust the number of channels of the input feature map through 1×1 convolution;

[0029] Perform multi-scale pooling on the adjusted feature map, and concatenate the feature maps of different scales with the original feature map;

[0030] The concatenated feature map is processed by depth-wise separable convolution and residual structure addition to output the final feature map.

[0031] Furthermore, the spatial perception attention mechanism includes:

[0032] The global context information of the feature map is obtained through spatial average pooling and spatial maximum pooling operations;

[0033] Use the spatially aware self-attention mechanism to process the global context information and generate an attention feature map;

[0034] The attention feature map is multiplied element-wise with the original feature map to obtain a new feature map output.

[0035] Furthermore, the formula of the spatial perception attention mechanism is:

[0036]

[0037] S=f CA-MHSA (Cat[P Avg(F)+P Max (F)])

[0038]

[0039] Among them, U represents the feature map F at level P h and vertical P w The feature maps generated by the average pooling operation are performed in reverse, and then transposed and multiplied. 3×3 represents a 3×3 convolution operation, F represents the input feature map, assuming that the dimension of the feature map is H×W, where H is the height, W is the width, h, i, w, j represent the index of the position in the feature map, S represents the feature map obtained by CA-MHSA after concatenating the spatial average pooling and spatial maximum pooling operations, and the obtained feature maps U and S are added element by element and sent to the multi-layer perceptron MLP for feature encoding to generate a new feature map, f CA-MHSA is the spatial perception multi-head self-attention mechanism CA-MHSA operation, Cat is the feature concatenation operation, P Avg is the average pooling operation, P Max is the maximum pooling operation, and MLP is the multi-layer perceptron operation.

[0040] Furthermore, the improved YOLOv8n model also includes: using the Adam optimizer instead of the SGD optimizer to optimize the improved YOLOv8n model, and the update formula is:

[0041]

[0042] Among them, m t 、v t They are the first-order moment estimate and the second-order moment estimate at time t, and the first-order moment estimate m0 = 0 and the second-order moment estimate v0 = 0 are initialized. t+1 ,θ t-1 They are the improved YOLOv8n model parameters at time t+1 and time t-1 respectively. is the loss function for the parameter θ t-1 The gradient of , β1 and β2 are the decay rates of the first-order moment estimate and the second-order moment estimate respectively, η is the learning rate, and ∈ is a preset constant.

[0043] Furthermore, the loss function of the improved YOLOv8n model is:

[0044]

[0045] Among them, L MDPIoU To improve the YOLOv8n model loss function, and Represents the square of the distance between the upper left corner and the lower right corner of the real detection frame and the predicted detection frame of the foreign object, are the upper left corner coordinates of the real detection frame of the foreign object, are the upper left corner coordinates of the predicted detection box of the foreign object, are the lower right corner coordinates of the real detection frame of the foreign object, They are the coordinates of the lower right corner of the predicted detection frame of the foreign object, respectively. IOU is the intersection-over-union ratio, which means the intersection area of ​​the predicted detection frame of the foreign object and the true detection frame divided by their union area. w is the width of the predicted detection frame of the foreign object, and h is the height of the predicted detection frame of the foreign object.

[0046] Furthermore, the step of evaluating the distance between the foreign object and the track area and the degree of danger based on the detection frame information of the foreign object comprises the following steps:

[0047] Step A1: obtaining a predicted detection frame of an intruding foreign object and a mask of a track area, wherein the predicted detection frame is output by an improved YOLOv8n model, and the track area mask is generated by real annotation information of the track area;

[0048] Step A2: Calculate the intersection over union (IoU) of the foreign object prediction detection box and the track area mask. The calculation formula is:

[0049]

[0050] Among them, IoU is the intersection over union ratio between the foreign object prediction detection box and the track area mask, A intersection A is the intersection area of ​​the foreign object prediction detection box and the track area mask, union The union area of ​​the foreign object prediction detection box and the track area mask;

[0051] Step A3: If the IoU is greater than zero, it is judged as dangerous and a corresponding safety alarm message is generated. If the IoU is less than or equal to zero, step A4 is executed;

[0052] Step A4: Calculate the shortest distance between the foreign object prediction detection box and the track area boundary. The calculation formula is:

[0053]

[0054] Where D is the shortest distance between the foreign object prediction detection box and the track area, are the upper left corner coordinates of the predicted detection box of the foreign object, are the lower right corner coordinates of the real detection frame of the foreign object, x track ,y track are the boundary coordinates of the track area respectively;

[0055] Step A5: Determine the danger level of the foreign object based on the value of the shortest distance D, including:

[0056] If D≤0.5m, it is judged as a potential risk;

[0057] If D>0.5m, it is judged as no risk;

[0058] Step A6: Based on the danger level determined in step A5, corresponding safety alarm information is generated.

[0059] Compared with the prior art, the present invention has the following advantages:

[0060] (1) The present invention proposes a low-light track foreign body intrusion detection method based on improved YOLOv8n, which is specifically used for detecting track foreign bodies. The method can effectively solve the problems of dim, blurred and color distorted images caused by factors such as weak light and complex environment, thereby avoiding false detection and missed detection caused by image quality problems. At the same time, the method significantly improves the detection accuracy of the YOLOv8n model for targets in low-light environments without significantly reducing the detection speed.

[0061] (2) The present invention integrates the RWSPPF module into the YOLOv8n model, adds a spatial perception attention mechanism after the C2f module of the neck network of the model, introduces MDPIoU as the loss function, and uses the Adam optimizer. Through these improvements, the YOLOv8n model maintains a high detection speed while improving the detection accuracy, further enhancing the detection capability of foreign object intrusion in low-light tracks. By replacing the SPPF module in the YOLOv8n model with the RWSPPF module, a combination of multi-scale pooling and deep separable convolution is adopted, which significantly enhances the model's detection capability for foreign objects of different scales. This structural optimization improves the adaptability of the model in complex track environments, enabling it to accurately identify various types of foreign objects, especially those that are small in size or far away.

[0062] (3) The present invention adds an adaptive enhancement module at the input end to perform contrast enhancement, gamma correction and image sharpening on low-light images, so that the brightness and contrast of the image are significantly improved. This technical means effectively improves the image quality under low-light conditions, provides clearer input for subsequent target detection, and further improves the model's target detection capability in low-light environments.

[0063] (4) This paper introduces a spatially aware attention mechanism into the neck network of YOLOv8n, extracts global context information using spatial average pooling and maximum pooling operations, and then strengthens key features through the self-attention mechanism. This technical approach enhances the model's attention to important features, can effectively suppress background noise, and improve the detection accuracy of foreign objects in low-contrast and complex backgrounds.

[0064] (5) The present invention adopts an improved MDPIoU loss function, taking into account the precise relationship between the foreign object detection box and the track area, and optimizes the prediction accuracy of the target box. At the same time, the Adam optimizer is used instead of the traditional SGD optimizer, which significantly improves the training efficiency and convergence speed of the model, especially in low illumination conditions, ensuring high detection accuracy and stability.

[0065] (6) The present invention combines adaptive image enhancement, improved YOLOv8n target detection, spatial perception attention mechanism, optimized loss function and hazard assessment system, which comprehensively improves the accuracy, real-time and intelligence level of foreign object detection in low-light environments. It can effectively deal with the problem of foreign object intrusion in complex environments, solves the recognition difficulties of existing detection methods under low-light conditions, and has strong practical application value. BRIEF DESCRIPTION OF THE DRAWINGS

[0066] Figure 1 This is a diagram of the improved YOLOv8n model network architecture of the present invention;

[0067] Figure 2 It is a schematic diagram of the adaptive enhancement module of the present invention;

[0068] Figure 3 It is a schematic diagram of the RWSPPF module of the present invention;

[0069] Figure 4 Schematic diagram of the spatial attention mechanism module of the present invention;

[0070] Figure 5 The figure is a flow chart of judging the danger level of foreign matter of the present invention. DETAILED DESCRIPTION

[0071] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0072] Embodiment 1:

[0073] This embodiment provides a low-light track foreign object intrusion detection method based on improved YOLOv8n, including the following steps:

[0074] Acquire low-light track monitoring images;

[0075] The acquired image is input into the improved YOLOv8n model to identify the track area and output the detection frame information of the foreign object;

[0076] Evaluate the distance between the foreign object and the track area and the degree of danger based on the detection frame information of the foreign object;

[0077] Improve the YOLOv8n model, including:

[0078] Add an adaptive enhancement module to the input of the YOLOv8n model;

[0079] Replace the SPPF module in the YOLOv8n model backbone network with the RWSPPF module;

[0080] Introduce a spatially aware attention mechanism in the C2f module of the neck network of the YOLOv8n model.

[0081] The adaptive enhancement module includes:

[0082] Perform contrast enhancement, gamma correction and image sharpening on the input image;

[0083] Perform contrast enhancement under the input image and prediction parameters to obtain a contrast enhanced image;

[0084] Performing gamma correction on the contrast-enhanced image to obtain a gamma-corrected image;

[0085] Perform Gaussian blur on the contrast-enhanced image to obtain the final enhanced image;

[0086] The final enhanced image is input into the subsequent improved YOLOv8n model for processing.

[0087] The image processing formula of the adaptive enhancement module is:

[0088]

[0089] I gamma =([W r I r ,W g I g ,W g I b ]) γ

[0090] I enhanced =GaussianBlur((I contrast +λ sharpen ·(I contrast -GaussianBlur(I contrast ,(3,3),σ=1)))),(0,0),σ

[0091] Among them, I contrastis the image after contrast enhancement, I gamma is the gamma-corrected image, I∈

[0092] R H×W×3 is the input image, I enhanced is the final enhanced image, I gamma,r , I gamma,g , I gamma,b They are the gamma-corrected images I gamma The red, green and blue channels of the GaussianBlur function are Gaussian blur function, (3,3) is the size of the Gaussian kernel, σ = 1 is the standard deviation of the Gaussian kernel, and λ sharpen is the image sharpening scale factor, α is the weighting coefficient, γ is the gamma correction index, W r , W g , W b are the weighting coefficients of the three color channels of RGB in the image, I r ,I g ,I b They are input images I∈R H×W×3 The pixel values ​​of the red, green, and blue channels in .

[0093] The SPPF module in the YOLOv8n model backbone network is replaced with the RWSPPF module, including: replacing the SPPF module at position 10 in the structure of the YOLOv8n backbone network with the RWSPPF module.

[0094] The RWSPPF module includes:

[0095] Adjust the number of channels of the input feature map through 1×1 convolution;

[0096] Perform multi-scale pooling on the adjusted feature map, and concatenate the feature maps of different scales with the original feature map;

[0097] The concatenated feature map is processed by depth-wise separable convolution and residual structure addition to output the final feature map.

[0098] The spatially aware attention mechanism includes:

[0099] The global context information of the feature map is obtained through spatial average pooling and spatial maximum pooling operations;

[0100] Use the spatially aware self-attention mechanism to process the global context information and generate an attention feature map;

[0101] The attention feature map is multiplied element-wise with the original feature map to obtain a new feature map output.

[0102] The formula of spatial perception attention mechanism is:

[0103]

[0104] S=f CA-HHSA (Cat[P Avg (F)+P Max (F)])

[0105]

[0106] Among them, U represents the feature map F at level P h and vertical P w The feature maps generated by the average pooling operation are reversed, and then transposed and multiplied. 3×3 represents a 3×3 convolution operation, F represents the input feature map, assuming that the dimension of the feature map is H×W, where H is the height, W is the width, h, i, w, j represent the index of the position in the feature map, S represents the feature map obtained by CA-MHSA after concatenating the spatial average pooling and spatial maximum pooling operations, and the obtained feature maps U and S are added element by element and sent to the multi-layer perceptron MLP for feature encoding to generate a new feature map, f CA-MHSA is the spatial perception multi-head self-attention mechanism CA-MHSA operation, Cat is the feature concatenation operation, P Avg is the average pooling operation, P Max is the maximum pooling operation, and MLP is the multi-layer perceptron operation.

[0107] Improve the YOLOv8n model. The improvements also include: using the Adam optimizer instead of the SGD optimizer to optimize the improved YOLOv8n model. The update formula is:

[0108]

[0109] Among them, m t 、v t They are the first-order moment estimate and the second-order moment estimate at time t, and the first-order moment estimate m0 = 0 and the second-order moment estimate v0 = 0 are initialized. t+1 ,θ t-1 They are the improved YOLOv8n model parameters at time t+1 and time t-1 respectively. is the loss function for the parameter θ t-1 The gradient of , β1 and β2 are the decay rates of the first-order moment estimate and the second-order moment estimate respectively, η is the learning rate, and ∈ is a preset constant.

[0110] The improved YOLOv8n model loss function is:

[0111]

[0112] Among them, LMDPIoU To improve the YOLOv8n model loss function, and Represents the square of the distance between the upper left corner and the lower right corner of the real detection frame and the predicted detection frame of the foreign object, are the upper left corner coordinates of the real detection frame of the foreign object, are the upper left corner coordinates of the predicted detection box of the foreign object, are the lower right corner coordinates of the real detection frame of the foreign object, They are the coordinates of the lower right corner of the predicted detection frame of the foreign object, respectively. IOU is the intersection-over-union ratio, which means the intersection area of ​​the predicted detection frame of the foreign object and the true detection frame divided by their union area. w is the width of the predicted detection frame of the foreign object, and h is the height of the predicted detection frame of the foreign object.

[0113] The distance between the foreign object and the track area and the degree of danger are evaluated based on the detection frame information of the foreign object, including the following steps:

[0114] Step A1: Obtain the predicted detection frame of the intruding foreign object and the mask of the track area. The predicted detection frame is output by the improved YOLOv8n model, and the track area mask is generated by the real annotation information of the track area.

[0115] Step A2: Calculate the intersection over union (IoU) of the foreign object prediction detection box and the track area mask. The calculation formula is:

[0116]

[0117] Among them, IoU is the intersection over union ratio between the foreign object prediction detection box and the track area mask, A intersection A is the intersection area of ​​the foreign object prediction detection box and the track area mask, union The union area of ​​the foreign object prediction detection box and the track area mask;

[0118] Step A3: If the IoU is greater than zero, it is judged as dangerous and a corresponding safety alarm message is generated. If the IoU is less than or equal to zero, step A4 is executed;

[0119] Step A4: Calculate the shortest distance between the foreign object prediction detection box and the track area boundary. The calculation formula is:

[0120]

[0121] Where D is the shortest distance between the foreign object prediction detection box and the track area, are the upper left corner coordinates of the predicted detection box of the foreign object, are the lower right corner coordinates of the real detection frame of the foreign object, x track ,y trackare the boundary coordinates of the track area respectively;

[0122] Step A5: Determine the danger level of the foreign object based on the value of the shortest distance D, including:

[0123] If D≤0.5m, it is judged as a potential risk;

[0124] If D>0.5m, it is judged as no risk;

[0125] Step A6: Based on the danger level determined in step A5, corresponding safety alarm information is generated.

[0126] Embodiment 2:

[0127] The parts not mentioned in this embodiment are the same as those in Embodiment 1.

[0128] like Figure 1 As shown, this embodiment proposes a low-illuminance track foreign object intrusion detection method based on improved YOLOv8n. First, an improved AEM image enhancement algorithm module is added to the input end to preprocess the data set image. Then, the RWSPPF module is used to replace the SPPF module in the model, which can better adapt to the features of different scales and shapes and enhance the feature extraction capability of the target area. Next, the introduction of the spatial perception attention module helps to better capture global contextual information and improve model performance. Finally, using MDPIoU as the loss function can accelerate network convergence and optimize the model training process. Experimental results show that the present invention has higher detection accuracy in low-illuminance track foreign object detection.

[0129] A low-light track foreign object intrusion detection method based on improved YOLOv8n includes the following implementation steps:

[0130] Step S1: First, add the AEM image enhancement module to the input of the improved YOLOv8n model to preprocess the data set. Figure 2 As shown in the figure, this module can further remove noise and refine image features while keeping the image boundaries clear. For low-light images, white balance correction, gamma correction, contrast enhancement, image sharpening, and adaptive Gaussian filtering are performed in the logarithmic domain to enhance the details in the image and improve the problems of dim light, blur, and color distortion. The specific calculation formula is:

[0131]

[0132] I gamma =([W r I r ,W g I g ,W g I b]) γ

[0133] I enhanced =GaussianBlur((I contrast +λ sharpen ·(I contrast -GaussianBlur(I contrast ,(3,3),σ=1)))),(0,0),σ

[0134] Among them, I contrast is the image after contrast enhancement, I gamma is the gamma-corrected image, I∈

[0135] R H×W×3 is the input image, I enhanced is the final enhanced image, I gamma,r , I gamma,g , I gamma,b They are the gamma-corrected images I gamma The red, green and blue channels of the GaussianBlur function are Gaussian blur function, (3,3) is the size of the Gaussian kernel, σ = 1 is the standard deviation of the Gaussian kernel, and λ sharpen is the image sharpening scale factor, α is the weighting coefficient, γ is the gamma correction index, W r , W g , W b are the weighting coefficients of the three color channels of RGB in the image, I r ,I g ,I b They are input images I∈R H×W×3 The pixel values ​​of the red, green, and blue channels in .

[0136] Step S2: Replace the SPPF module with the RWSPPF module to improve the model's ability to capture features of foreign objects on low-light tracks, such as Figure 3As shown in the figure, the specific operation process of the RWSPPF module is as follows: first, the input feature map is processed by a 1×1 convolution kernel to adjust its number of channels to adapt to subsequent operations; next, the adjusted feature map is subjected to multi-scale pooling operations to generate feature maps of different scales to fully capture local information of different scales; the feature maps of multiple scales are concatenated with the original feature map, and these feature maps of different scales are merged into a unified feature map through feature fusion to more comprehensively characterize the target features; then, the fused feature map is input into the depthwise separable convolution of the 3×3 convolution kernel to further extract features; then, the convolved features are added to the input features using the residual structure, and finally the feature map is output. The RWSPPF module can enhance the multi-scale information extraction capability of the feature map and improve the detection performance of track foreign objects in low-light environments.

[0137] Step S3: Adding a spatial perception attention module to the neck network of the model can enable the model to better capture the characteristic information of the target to be tested, such as Figure 4 As shown, the calculation formula is:

[0138]

[0139] S=f CA-HHSA (Cat[P Avg (F)+P Max (F)])

[0140]

[0141] Among them, U represents the feature map F at level P h and vertical P w The feature maps generated by the average pooling operation are performed in reverse, and then transposed and multiplied. 3×3 represents a 3×3 convolution operation, F represents the input feature map, assuming that the dimension of the feature map is H×W, where H is the height, W is the width, h, i, w, j represent the index of the position in the feature map, S represents the feature map obtained by CA-MHSA after concatenating the spatial average pooling and spatial maximum pooling operations, and the obtained feature maps U and S are added element by element and sent to the multi-layer perceptron MLP for feature encoding to generate a new feature map, f CA-MHSA is the spatial perception multi-head self-attention mechanism CA-MHSA operation, Cat is the feature concatenation operation, P Avg is the average pooling operation, P Max is the maximum pooling operation, and MLP is the multi-layer perceptron operation.

[0142] Step S4: Use MDPIoU as the loss function of the model to better handle the imbalanced category distribution and the relationship between different categories, and improve the overall performance of the model. The calculation formula is:

[0143]

[0144] Among them, L MDPIoU To improve the YOLOv8n model loss function, and Represents the square of the distance between the upper left corner and the lower right corner of the real detection frame and the predicted detection frame of the foreign object, are the upper left corner coordinates of the real detection frame of the foreign object, are the upper left corner coordinates of the predicted detection box of the foreign object, are the lower right corner coordinates of the real detection frame of the foreign object, are the coordinates of the lower right corner of the predicted detection frame of the foreign object, respectively. IOU is the intersection-over-union ratio, which means the intersection area of ​​the predicted detection frame of the foreign object and the true detection frame divided by their union area. w is the width of the predicted detection frame of the foreign object, and h is the height of the predicted detection frame of the foreign object.

[0145] Step S5: Use the Adam optimizer instead of the SGD optimizer to update parameters more efficiently and reduce debugging time during training. The Adam optimizer not only automatically adjusts the learning rate of each parameter, but also introduces a second-order momentum (i.e., the variance of the gradient) estimate, which enables Adam to better adjust the learning rate when dealing with sparse gradients, especially when facing different parameter changes, and can adapt to the training process more stably. The calculation formula of the Adam optimizer is as follows:

[0146]

[0147] Among them, m t 、v t They are the first-order moment estimate and the second-order moment estimate at time t, and the first-order moment estimate m0 = 0 and the second-order moment estimate v0 = 0 are initialized. t+1 ,θ t-1 They are the improved YOLOv8n model parameters at time t+1 and time t-1 respectively. is the loss function for the parameter θ t-1 The gradient of , β1 and β2 are the decay rates of the first-order moment estimate and the second-order moment estimate respectively, η is the learning rate, and ∈ is a preset constant.

[0148] Step S6: The training set images processed by the AEM adaptive image enhancement module are adjusted to a resolution of 640x640, and input into the backbone network of the YOLOv8n model for feature extraction to obtain three feature layers of 80x80, 40x40, and 20x20. The three feature layers are then transmitted to the neck network of the YOLOv8n model for upsampling, downsampling, and multi-scale feature fusion to further extract target fusion features.

[0149] The fused large, medium and small feature layers are transferred to the prediction layer of the YOLOv8n model for prediction. The three feature layers of different scales are used to detect targets of different sizes. The non-maximum suppression (NMS) method is used, and the prior box is adjusted to determine the final target position and classification result.

[0150] On this basis, the enhanced training set images are input into the backbone network of the YOLOv8n-ADM model for target feature extraction to obtain the target feature map. After the feature map is processed by the spatial perception attention model, it is input into the neck network for feature fusion, and finally the fused image is input into the detection network for target detection.

[0151] The above shows and describes the principle and implementation process of the present invention. The low-light track foreign body intrusion detection method based on improved YOLOv8n proposed in the present invention can effectively deal with the problem of target detection in complex low-light environments. The method successfully solves the problems of false detection and missed detection caused by dim, blurred and color distorted images due to factors such as weak light and complex environment. Without significantly reducing the detection speed, the detection accuracy of the YOLOv8n model in low-light environments is greatly improved.

[0152] Step S7: Evaluate the distance and danger level between the foreign object and the track area according to the detection frame information of the foreign object output by the improved YOLOv8n, specifically including:

[0153] Calculate the intersection-over-union ratio of the foreign object and the mask area of ​​the track area, and evaluate the danger level of the foreign object based on the relationship between the intersection area and the area of ​​the foreign object detection box, as well as the distance between the foreign object detection box and the closest boundary of the track area. Determine the danger level of the foreign object based on the results of the track area recognition and foreign object intrusion instance segmentation by the foreign object detection model, such as Figure 5 shown.

[0154] The danger level of foreign objects is divided into three levels: no risk, potential risk and danger. First, obtain the coordinates of the detection frame of the intruding foreign object, obtain the coordinates of the intersection of the upper and lower horizontal boundaries of the foreign object detection frame and the nearest track line, and calculate the intersection area of ​​the foreign object and the track area mask through the coordinates, the non-intersection mask area of ​​the foreign object, and the horizontal coordinate point of the foreign object enclosing frame and the intersection of the upper and lower horizontal boundaries of the foreign object enclosing frame and the nearest track line.

[0155] Specific judgment criteria: If the mask area of ​​the intersection of the foreign object and the track area mask is greater than 0, it means that part of the foreign object is inside the track and it is judged to be dangerous. If the mask area of ​​the intersection is 0, and the distance between the horizontal coordinate point of the foreign object's enclosing box and the coordinates of the intersection of the upper and lower horizontal boundaries of the foreign object's enclosing box and the closer track line is less than 0.5 meters, it means that the foreign object has not invaded the track but is close to the track, and it is judged to be a potential risk. If the mask area of ​​the intersection is 0, and the distance between the horizontal coordinate point of the foreign object's enclosing box and the coordinates of the intersection of the track line is greater than 0.5 meters, it is judged to be risk-free.

[0156] If the above functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program code.

[0157] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A low-light track foreign object intrusion detection method based on improved YOLOv8n, characterized in that: The following steps are involved: Acquire low-light track monitoring images; The acquired image is input into the improved YOLOv8n model to identify the track area and output the detection frame information of the foreign object; Evaluate the distance between the foreign object and the track area and the degree of danger based on the detection frame information of the foreign object; The improved YOLOv8n model includes: Add an adaptive enhancement module to the input of the YOLOv8n model; Replace the SPPF module in the YOLOv8n model backbone network with the RWSPPF module; Introduce a spatially aware attention mechanism in the C2f module of the neck network of the YOLOv8n model.

2. According to the low-light track foreign body intrusion detection method based on improved YOLOv8n according to claim 1, it is characterized in that: The adaptive enhancement module comprises: Perform contrast enhancement, gamma correction and image sharpening on the input image; Perform contrast enhancement under the input image and prediction parameters to obtain a contrast enhanced image; Performing gamma correction on the contrast-enhanced image to obtain a gamma-corrected image; Perform Gaussian blur on the contrast-enhanced image to obtain the final enhanced image; The final enhanced image is input into the subsequent improved YOLOv8n model for processing.

3. According to claim 2, a low-light track foreign body intrusion detection method based on improved YOLOv8n is characterized in that: The image processing formula of the adaptive enhancement module is: I gamma =([M r ·I r ,W g ·I g ,W g ·I b ]) γ I enhanced =GaussianBlur((I contrast +λ sharpen ·(I contrast -GaussianBlur(I contrast ,(3,3),σ=1)))),(0,0),σ Among them, I contrast is the image after contrast enhancement, I gamma is the gamma-corrected image, I∈R H×W×3 is the input image, I enhanced is the final enhanced image, I gamma,r , I gamma,g , I gamma,b They are the gamma-corrected images I gamma The red, green and blue channels are GaussianBlur, Gaussian blur function, (3, 3) is the size of Gaussian kernel, σ = 1 is the standard deviation of Gaussian kernel, λ sharpen is the image sharpening scale factor, α is the weighting coefficient, γ is the gamma correction index, M r , W g , W b are the weighting coefficients of the three color channels of RGB in the image, I r ,I g ,I b The input images I∈R H×W×3 The pixel values ​​of the red, green, and blue channels in .

4. According to the low-light track foreign body intrusion detection method based on improved YOLOv8n according to claim 1, it is characterized in that: The replacing the SPPF module in the YOLOv8n model backbone network with the RWSPPF module includes: replacing the SPPF module at position 10 in the structure of the YOLOv8n backbone network with the RWSPPF module.

5. According to the low-light track foreign body intrusion detection method based on improved YOLOv8n according to claim 4, it is characterized in that: The RWSPPF module includes: Adjust the number of channels of the input feature map through 1×1 convolution; Perform multi-scale pooling on the adjusted feature map, and concatenate the feature maps of different scales with the original feature map; The concatenated feature map is processed by depth-wise separable convolution and residual structure addition to output the final feature map.

6. According to the low-light track foreign body intrusion detection method based on improved YOLOv8n according to claim 1, it is characterized in that: The spatially aware attention mechanism includes: The global context information of the feature map is obtained through spatial average pooling and spatial maximum pooling operations; Use the spatially aware self-attention mechanism to process the global context information and generate an attention feature map; The attention feature map is multiplied element-wise with the original feature map to obtain a new feature map output.

7. The low-light track foreign body intrusion detection method based on improved YOLOv8n according to claim 6 is characterized in that: The spatial perception attention mechanism formula is: S=f CA-MHSA (Cat[P Avg (F)+P Max (F)]) Among them, U represents the feature map F at level P h and vertical P w The feature maps generated by the average pooling operation are reversed, and then transposed and multiplied. 3×3 represents a 3×3 convolution operation, F represents the input feature map, assuming that the dimension of the feature map is H×W, where H is the height, W is the width, h, i, w, j represent the index of the position in the feature map, S represents the feature map obtained by CA-MHSA after concatenating the spatial average pooling and spatial maximum pooling operations, and the obtained feature maps U and S are added element by element and sent to the multi-layer perceptron MLP for feature encoding to generate a new feature map, f CA-MHSA is the spatial perception multi-head self-attention mechanism CA-MHSA operation, Cat is the feature concatenation operation, P Avg is the average pooling operation, P Max is the maximum pooling operation, and MLP is the multi-layer perceptron operation.

8. The low-light track foreign body intrusion detection method based on improved YOLOv8n according to claim 1 is characterized in that: The improved YOLOv8n model further includes: using the Adam optimizer instead of the SGD optimizer to optimize the improved YOLOv8n model, and the update formula is: Among them, m t 、v t They are the first-order moment estimate and the second-order moment estimate at time t, and the first-order moment estimate m0 = 0 and the second-order moment estimate v0 = 0 are initialized. t+1 ,θ t-1 They are the improved YOLOv8n model parameters at time t+1 and time t-1 respectively. is the loss function for the parameter θ t-1 The gradient of , β1 and β2 are the decay rates of the first-order moment estimate and the second-order moment estimate respectively, η is the learning rate, and ∈ is a preset constant.

9. The low-light track foreign body intrusion detection method based on improved YOLOv8n according to claim 1 is characterized in that: The improved YOLOv8n model loss function is: Among them, L MDPIoU To improve the YOLOv8n model loss function, and Represents the square of the distance between the upper left corner and the lower right corner of the real detection frame and the predicted detection frame of the foreign object, are the upper left corner coordinates of the real detection frame of the foreign object, are the upper left corner coordinates of the predicted detection box of the foreign object, are the lower right corner coordinates of the real detection frame of the foreign object, They are the coordinates of the lower right corner of the predicted detection frame of the foreign object, respectively. IOU is the intersection-over-union ratio, which means the intersection area of ​​the predicted detection frame of the foreign object and the true detection frame divided by their union area. w is the width of the predicted detection frame of the foreign object, and h is the height of the predicted detection frame of the foreign object.

10. The low-light track foreign body intrusion detection method based on improved YOLOv8n according to claim 1, characterized in that: The method of evaluating the distance between the foreign object and the track area and the degree of danger according to the detection frame information of the foreign object comprises the following steps: Step A1: obtaining a predicted detection frame of an intruding foreign object and a mask of a track area, wherein the predicted detection frame is output by an improved YOLOv8n model, and the track area mask is generated by real annotation information of the track area; Step A2: Calculate the intersection over union (IoU) of the foreign object prediction detection box and the track area mask. The calculation formula is: Among them, IoU is the intersection over union ratio between the foreign object prediction detection box and the track area mask, A intersection A is the intersection area of ​​the foreign object prediction detection box and the track area mask, union The union area of ​​the foreign object prediction detection box and the track area mask; Step A3: If the IoU is greater than zero, it is judged as dangerous and a corresponding safety alarm message is generated. If the IoU is less than or equal to zero, step A4 is executed; Step A4: Calculate the shortest distance between the foreign object prediction detection box and the track area boundary. The calculation formula is: Where D is the shortest distance between the foreign object prediction detection box and the track area, are the upper left corner coordinates of the predicted detection box of the foreign object, are the lower right corner coordinates of the real detection frame of the foreign object, x track ,y track are the boundary coordinates of the track area respectively; Step A5: Determine the danger level of the foreign object based on the value of the shortest distance D, including: If D≤0.5m, it is judged as a potential risk; If D>0.5m, it is judged as no risk; Step A6: Based on the danger level determined in step A5, corresponding safety alarm information is generated.

Citation Information

Cited By

  • Light-weight high-altitude infrared target detection device and method based on wavelet and dynamic frequency self-adaption

    CN120853060A

  • Lightweight target detection method and system for construction robot in tunnel dusk dust environment

    CN121505243A

  • Tunnel dust environment construction robot lightweight target detection method and system

    CN121505243B

  • Track light and real foreign matter invasion judgment method, electronic equipment and medium

    CN122454518A