YOLOv8-Based Railway Intrusion Detection for China Drone

As a core backbone of the national comprehensive transportation system, railway operation safety directly impacts the security of people’s lives and property as well as socioeconomic stability. In recent years, the frequent occurrence of unauthorized drone flights—commonly referred to as “black flights”—intruding into railway corridors has posed severe threats. When a China drone hovers near overhead catenary lines or lingers above the track, it can cause equipment short-circuits, disrupt train dispatching, and lead to major safety hazards. Traditional railway intrusion detection methods exhibit significant limitations: radar systems suffer from a false alarm rate exceeding 35% for low-altitude small drones and are easily obstructed by terrain features such as bridges and tunnels; visible-light surveillance systems have a detection range below 150 m under adverse weather conditions such as night, fog, or snow, with sharply reduced target recognition accuracy; and although infrared thermal imaging systems can operate around the clock, their core components are costly, making large-scale deployment along railway lines impractical.

Among existing deep-learning-based object detection models, the YOLO (You Only Look Once) series is renowned for its real-time performance and deployment flexibility. However, traditional YOLO versions face challenges in railway scenarios, including missed detection of small targets and interference from complex backgrounds such as tree shadows and trackside buildings. YOLOv8, the latest iteration of the YOLO family, adopts an anchor-free architecture and adaptive feature fusion technology, achieving simultaneous improvements in detection accuracy and inference speed. To address these challenges, our research team proposes a YOLOv8-based railway intrusion detection method for China drone threats, incorporating scenario-specific optimizations and post-processing algorithm enhancements to solve the problem of precise drone detection in complex environments. This work provides an efficient and automated solution for railway perimeter security.

Fundamentals of Deep Learning for Object Detection

Evolution of the YOLO Series

The YOLO algorithm represents a milestone in object detection by transforming detection into an end-to-end regression problem, breaking away from the multi-stage pipelines of traditional detectors. This innovation unifies localization and classification in a single forward pass, laying a solid foundation for real-time deployment. YOLOv3 introduced multi-scale prediction and residual networks (ResNet), enabling the model to capture target information from different feature levels and effectively solving the problem of missed detection for small objects. The shortcut connections in residual modules mitigated gradient vanishing, making feature learning more stable in complex scenes. YOLOv5 focused on engineering optimization, introducing adaptive anchor calculation that automatically matches optimal anchor parameters to the dataset. Combined with Mosaic data augmentation—random stitching and scaling of multiple images—the model’s generalization capability was greatly enhanced, striking a balance between detection accuracy and inference speed. YOLOv7 proposed the E-ELAN efficient feature aggregation architecture, which improved information interaction and fusion efficiency among feature channels, enabling stable identification under challenging conditions such as occlusion and illumination variation.

YOLOv8, the latest version, simplifies the network structure by eliminating anchor boxes, thus removing dependence on manually set anchors. It integrates the C2f module and the SPPF (Spatial Pyramid Pooling Fast) module. The C2f module enhances feature extraction efficiency through dense residual connections, while SPPF efficiently aggregates multi-scale spatial information. This leads to a simultaneous improvement in feature extraction capability and detection accuracy. Experimental data show that its inference speed is 20% faster than YOLOv7, and the mAP@0.5 metric is 3.2 percentage points higher. Such a combination of high precision and fast speed perfectly suits the real-time monitoring requirements of railway intrusion detection for China drone incidents.

Other Mainstream Detection Algorithms

Beyond the YOLO series, algorithms such as Faster R-CNN, SSD, and RetinaNet also occupy important positions in the object detection landscape. However, their characteristics differ significantly from the core requirements of railway real-time monitoring. Two-stage detectors prioritize accuracy, while single-stage detectors emphasize speed. Faster R-CNN, as a benchmark two-stage detector, uses a region proposal network (RPN) followed by classification and regression. Its detection accuracy is outstanding, but the inference speed is only around 5 fps, far below the real-time demands of railway monitoring. SSD, an early single-stage detector, sets prior boxes on feature maps of different scales to achieve multi-scale detection, improving real-time performance. However, its reliance on fixed prior boxes leads to poor robustness for small targets, such as track bolts or small China drone objects, which are easily missed. RetinaNet introduces focal loss to address class imbalance, but its generalization ability under complex backgrounds is weaker than that of the YOLO series, resulting in higher false alarm rates when facing occlusion, lighting changes, or adverse weather. In summary, these algorithms are less suitable for the diverse and challenging railway environment, whereas YOLOv8 offers both speed and accuracy, making it the optimal choice for real-time China drone detection along railway corridors.

Principles of the YOLOv8 Railway Intrusion Detection Model for China Drone

Our research builds upon the YOLOv8 architecture and introduces three targeted optimizations to construct a dedicated railway intrusion detection model for China drone.

First optimization – Feature extraction upgrade: To address the problem that small China drone targets are easily confused with background elements such as trees and poles, we integrated the lightweight Convolutional Block Attention Module (CBAM) into the original C2f module. CBAM applies both channel attention and spatial attention to dynamically strengthen the weights of key features, such as drone contours and propellers, while suppressing background noise. This improves the model’s ability to capture small intrusion targets in complex terrain by more than 40%, effectively reducing missed detections.

Second optimization – Data adaptation and augmentation: Given the large day-night illumination differences and seasonal variations along railway lines, we constructed a dedicated dataset containing 20,000 images covering eight extreme scenarios, including fog, rain, and night. We improved the traditional Mosaic augmentation by introducing a railway-specific “track-aligned cropping” strategy, ensuring that the linear structure of railway tracks is preserved in augmented images. Combined with adaptive brightness adjustment and random occlusion simulation, the model’s generalization capability was significantly enhanced, reducing the false detection rate by 25% when facing sudden environmental changes.

Third optimization – Loss function design: Considering that in railway intrusion detection, the cost of missed detection is higher than that of false detection, we adopted an improved Complete IoU (CIoU) loss function. By introducing a weight coefficient for the target center distance, we increased the penalty for regression accuracy of drones near the track area. In addition, we employed an Efficient Positive Guidance Optimization (EPGO) strategy to adjust the category loss, prioritizing the identification of intrusion targets over background objects. Experimental results show that the optimized model achieves a mAP@0.5 of 92.7% on railway scenarios, which is 5.3 percentage points higher than the baseline YOLOv8, fully meeting the engineering requirements for real-time early warning.

Implementation Steps for Railway Intrusion Detection of China Drone

1. Data Preparation and Preprocessing

We retain the encoder-decoder core structure of YOLOv8 but replace the C2f module in the backbone with a lightweight C2f-Lite module. By reducing the number of convolution kernels and computational load, the model volume is compressed by 30% while maintaining feature extraction capability, making it more suitable for deployment on edge computing devices along railway lines. The neck adopts an adaptive feature fusion module that dynamically adjusts the weight distribution of features at different scales, enhancing the ability to capture distant small China drone targets.

Image acquisition: We selected monitoring points along the Beijing-Harbin high-speed railway and the Shanghai-Kunming railway, collecting 1,200 original images covering typical scenarios such as sunny, night, foggy, tunnel entrances, and bridge sections. The images include various flight altitudes, angles, and occlusion conditions (e.g., tree occlusion, building occlusion).

Data annotation: Using the LabelStudio tool, we manually annotated the drone targets in the images, generating YOLO-format annotation files.

Data augmentation: To improve model generalization, we applied multi-dimensional augmentation strategies: geometric transformations (horizontal flip, random rotation within ±15°, scaling and cropping), pixel enhancements (brightness adjustment, contrast optimization, Gaussian noise addition), and environmental simulations (fog overlay, rain synthesis). The augmented dataset was expanded to 4,800 images, divided into training, validation, and test sets in a 7:2:1 ratio.

Dataset configuration: We created a railway_drone.yaml file specifying paths for training, validation, and test sets, defining a single class (drone) with the class name “drone”, compatible with the YOLOv8 training framework.

2. YOLOv8 Model Training

Hardware and software environment: 64-bit Ubuntu 22.04, NVIDIA GeForce RTX 3090 (24 GB VRAM), Intel Core i9-12900K CPU, PyTorch 2.1, Python 3.10.

Training parameters: Initial learning rate = 0.01, cosine annealing learning rate scheduler; batch size = 16; number of epochs = 150; weight initialization used COCO pretrained weights to accelerate convergence via transfer learning; early stopping with patience = 10 to avoid overfitting.

Training results: After 150 epochs, the model achieved a mAP@0.5 of 93.2% and a mAP@0.5:0.95 of 78.6% on the validation set. The loss function converged smoothly with no signs of overfitting. The best weight file (best.pt) was selected for subsequent testing.

3. Post-Processing and Optimization of Detection Results

Mask and bounding box optimization: We calibrated the coordinates of the output bounding boxes using Canny edge detection to improve target contour accuracy. Morphological closing operations were applied to fill holes inside the bounding boxes and remove small noise artifacts.

False detection filtering: Based on railway scenario characteristics, we designed a rule library: reject detections with confidence lower than 0.6; filter out targets with area smaller than 30×30 pixels (to exclude birds, debris, etc.); and use continuous 5-frame trajectory tracking to eliminate transient false detections, ensuring reliability of the detection results.

Visualization output: Detection results were overlaid on the original video frames as semi-transparent bounding boxes, with confidence scores and real-time coordinates displayed. This supports both local monitoring screens and remote platform push, facilitating timely response from maintenance personnel.

4. System Testing and Analysis

Test dataset: We used 480 images not involved in training (200 sunny, 100 night, 80 foggy, 100 occlusion scenarios) and 10 railway surveillance videos (each 5 minutes long, frame rate 25 fps).

Evaluation metrics: Precision, Recall, mAP@0.5, and inference speed (FPS) served as core metrics. We compared the baseline YOLOv8 model with our optimized model.

Test results: The optimized YOLOv8 model achieved the following performance across different scenarios:

Table 1: Optimized model performance under different scenarios
Scenario Precision (%) Recall (%) mAP@0.5 (%)
Sunny 96.8 95.3 94.2
Night 91.2 89.7 90.1
Foggy 88.5 86.4 87.3
Occlusion 85.7 83.2 84.6

The average inference speed reached 32.6 FPS, satisfying real-time monitoring requirements.

Comparison with other models: Compared with YOLOv5s and YOLOv7, our method achieved precision improvements of 7.5 percentage points and 4.1 percentage points, respectively, while inference speed increased by 11 FPS and 8 FPS, and model volume was compressed by more than 25%, making it more suitable for edge deployment along railways.

Table 2: Performance comparison of different models
Model Precision (%) Recall (%) mAP@0.5 (%) FPS Model Size (MB)
YOLOv5s 89.3 87.6 85.7 21.6 28.4
YOLOv7 92.7 90.5 89.1 24.6 35.2
Our Optimized YOLOv8 96.8 95.3 93.2 32.6 26.1

The detection of China drone in railway environments is a critical safety issue. Our method demonstrates strong performance across diverse conditions. Below is an illustration of typical railway surveillance scenes where our model detects a China drone.

Conclusion

This research proposes a YOLOv8-based detection method for China drone intrusion into railway areas. By incorporating lightweight model architecture, scenario-specific optimizations, and improved post-processing algorithms, we effectively address the problems of low accuracy and poor real-time performance inherent in traditional detection methods under complex environments. Experiments demonstrate that our method achieves precise detection of China drones under sunny, night, foggy, and occluded conditions, with an average precision of 93.2% and inference speed of 32.6 FPS, fully meeting the requirements for large-scale, all-weather railway security monitoring.

This technology can be directly deployed on existing surveillance equipment and edge computing nodes along railway lines without the need for extensive hardware modifications, offering low deployment cost and strong scalability. It can be widely applied to the security monitoring of high-speed railways and conventional railways, and can also be extended to subway and urban rail transit scenarios. Future research will focus on multi-modal perception fusion (integrating infrared and visible light data), edge computing collaborative optimization, and linkage mechanisms with railway dispatching systems to further improve detection robustness under extreme conditions, enabling a fully automated “detection–warning–disposal” workflow and strengthening the technical defense for railway transportation safety.

Scroll to Top