Improved YOLOv5-based Anti-UAV Target Detection for Substations

In recent years, the proliferation of unmanned aerial vehicles (UAVs) has posed significant security challenges to critical infrastructure, such as electrical substations. Unauthorized UAV intrusions can lead to operational disruptions, safety hazards, and potential sabotage. Therefore, developing efficient and accurate anti-UAV target detection systems is paramount. Traditional detection methods, including radar, radio frequency, and electro-optical techniques, often struggle with small, fast-moving UAVs due to limitations like clutter interference, high costs, and sensitivity to environmental conditions. To address these issues, I propose an enhanced target detection algorithm based on YOLOv5, specifically designed for anti-UAV applications in substation environments. This method focuses on improving detection accuracy for small targets while maintaining real-time performance, leveraging advanced deep learning techniques to meet the stringent requirements of substation security.

The core of my approach involves three key modifications to the YOLOv5 Nano model: a four-scale feature fusion structure to enhance small object detection, the integration of a Transformer encoder into the C3 module for better feature learning, and the incorporation of a convolutional block attention module (CBAM) to emphasize target regions. These enhancements collectively boost the model’s ability to identify UAVs in complex backgrounds with high precision and speed. In this paper, I detail the methodology, experimental setup, and results, demonstrating that the improved algorithm achieves superior performance compared to existing state-of-the-art methods. The work contributes to the growing field of anti-UAV technology by providing a lightweight, efficient solution tailored for real-time surveillance in substations.

Target detection in anti-UAV scenarios is particularly challenging due to the small size and high mobility of drones. Most existing deep learning-based detectors, such as two-stage algorithms (e.g., Faster R-CNN) and single-stage algorithms (e.g., YOLO series), face trade-offs between accuracy and speed. While YOLOv5 offers a balance with its lightweight architecture, its default configuration may not fully capture small UAV features in cluttered environments. My improvements aim to overcome these limitations by refining the feature extraction and fusion processes. The proposed model is evaluated on a composite dataset of UAV images, showing significant gains in recall, precision, and average precision, along with a fast inference speed suitable for real-time anti-UAV monitoring.

Methodology

The overall architecture of my improved YOLOv5-based anti-UAV detection algorithm is built upon the YOLOv5 Nano framework, which is known for its low parameter count and computational efficiency. I retain the CSPDarknet53 backbone and the path aggregation network (PAN) for feature fusion but introduce several modifications to enhance performance. The network takes 640×640 RGB images as input and outputs bounding boxes with confidence scores for UAV detection. The key innovations include a four-scale feature fusion structure, a redesigned C3 module with a Transformer encoder (C3TR), and the integration of CBAM attention mechanisms. These components work together to improve feature representation, especially for small targets, making the system more robust in anti-UAV applications.

Four-Scale Feature Fusion Structure

Original YOLOv5 models typically use three detection scales (e.g., 20×20, 40×40, and 80×80 feature maps) for object detection. However, for small UAVs, shallow features with higher spatial resolution are crucial. I extend this to a four-scale structure by adding a detection layer at a 160×160 scale, which corresponds to a 4× down-sampling of the input image. This allows the network to leverage richer low-level semantic information, improving the detection of tiny objects. The feature maps at different scales are fused through a combination of feature pyramid network (FPN) and PAN mechanisms, enhancing both semantic and positional information flow. The correspondence between feature map sizes and anchor box dimensions is summarized in Table 1.

Table 1: Feature Map Sizes and Anchor Box Dimensions for Anti-UAV Detection
Receptive Field Feature Map Size Anchor Box Dimensions
Small 160×160 [5,6], [8,14], [15,11]
Medium 80×80 [10,13], [16,30], [33,23]
Large 40×40 [30,61], [62,45], [59,119]
Extra Large 20×20 [30,61], [62,45], [373,326]

The four-scale fusion process can be described mathematically. Let $F_i$ denote the feature map at scale $i$, where $i \in \{1,2,3,4\}$ corresponding to 160×160, 80×80, 40×40, and 20×20 resolutions. The fusion involves up-sampling and concatenation operations. For instance, to fuse features from deeper layers to the 160×160 scale, I up-sample higher-level features and concatenate them with the shallow features. This enhances the gradient flow and preserves fine-grained details, critical for anti-UAV tasks. The output at each scale is given by:

$$ F_i’ = \text{Concat}(\text{UpSample}(F_{i+1}), F_i) $$

where $\text{UpSample}$ denotes bilinear interpolation, and $\text{Concat}$ denotes channel-wise concatenation. This multi-scale approach significantly boosts the model’s ability to detect small UAVs against complex backgrounds.

C3TR Module with Transformer Encoder

The original C3 module in YOLOv5 uses a CSP structure with bottleneck layers to reduce computational cost. To improve feature learning for small targets, I replace the bottleneck with a Transformer encoder, creating the C3TR module. The Transformer encoder leverages multi-head self-attention mechanisms to capture long-range dependencies between pixel patches, enhancing the model’s contextual understanding. This is particularly beneficial for anti-UAV detection, where drones may appear in varied orientations and scales. The encoder consists of multi-head attention (MHA) and multi-layer perceptron (MLP) blocks with layer normalization and residual connections, as shown in the following equations.

For an input feature map $X \in \mathbb{R}^{H \times W \times C}$, it is first flattened into a sequence of patches $X_p \in \mathbb{R}^{N \times D}$, where $N = H \times W$ and $D = C$. The multi-head attention computes:

$$ \text{Attention}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right)V $$

where $Q, K, V$ are query, key, and value matrices derived from $X_p$, and $d_k$ is the dimension of keys. The output is processed through an MLP with GELU activation and dropout for regularization. The overall transformation in the C3TR module can be expressed as:

$$ X’ = X + \text{MHA}(\text{LayerNorm}(X)) $$
$$ X” = X’ + \text{MLP}(\text{LayerNorm}(X’)) $$

This design strengthens feature correlations and reduces information loss in deep layers, leading to better performance in anti-UAV scenarios. I integrate C3TR modules primarily in the backbone’s deeper layers and the detection heads, balancing accuracy and computational efficiency.

Convolutional Block Attention Module (CBAM)

To further enhance the model’s focus on UAV targets, I incorporate CBAM into the neck network before each prediction output. CBAM combines channel and spatial attention mechanisms to refine feature maps by emphasizing important regions and suppressing irrelevant background noise. For a feature map $F \in \mathbb{R}^{H \times W \times C}$, the channel attention module computes weights $M_c(F)$ using global average and max pooling, followed by an MLP:

$$ M_c(F) = \sigma(\text{MLP}(\text{AvgPool}(F)) + \text{MLP}(\text{MaxPool}(F))) $$

where $\sigma$ is the sigmoid function. The spatial attention module then generates weights $M_s(F)$ by applying a convolutional layer on concatenated average and max pooled features:

$$ M_s(F) = \sigma(f^{7\times7}([\text{AvgPool}(F); \text{MaxPool}(F)])) $$

where $f^{7\times7}$ denotes a 7×7 convolution. The final refined feature map $F”$ is obtained as:

$$ F’ = M_c(F) \otimes F $$
$$ F” = M_s(F’) \otimes F’ $$

with $\otimes$ denoting element-wise multiplication. By integrating CBAM at multiple scales, the model becomes more adept at highlighting UAV features in cluttered substation environments, improving detection accuracy for anti-UAV operations.

Experimental Setup and Evaluation

To validate the effectiveness of my improved anti-UAV detection algorithm, I conduct extensive experiments on a dataset compiled from public sources, including Real World and Det Fly datasets. The combined dataset contains 65,244 images with UAV instances in diverse backgrounds such as skies, urban areas, and fields. I split the data into training, validation, and test sets with an 80:10:10 ratio. All images are resized to 640×640 pixels, and data augmentation techniques like Mosaic, MixUp, and random cropping are applied to enhance generalization. The model is trained for 100 epochs with a batch size of 16, using stochastic gradient descent (SGD) optimizer with momentum 0.937 and a cosine annealing learning rate schedule from 0.01 to 0.0001. Warm-up is used for the first 3 epochs to stabilize training.

Evaluation Metrics

I adopt standard metrics for object detection to assess performance: precision (P), recall (R), average precision (AP), and frames per second (FPS). Precision measures the proportion of true positive detections among all positive predictions, while recall indicates the proportion of actual positives correctly identified. Average precision is the area under the precision-recall curve, providing a comprehensive score. FPS evaluates the inference speed, crucial for real-time anti-UAV applications. The formulas are:

$$ \text{Precision} = \frac{N_{TP}}{N_{TP} + N_{FP}} $$
$$ \text{Recall} = \frac{N_{TP}}{N_{TP} + N_{FN}} $$
$$ \text{AP} = \int_0^1 p(r) \, dr $$
$$ \text{FPS} = \frac{N_{\text{frames}}}{T_{\text{time}}} $$

where $N_{TP}$, $N_{FP}$, and $N_{FN}$ denote true positives, false positives, and false negatives, respectively; $p(r)$ is the precision-recall function; $N_{\text{frames}}$ is the number of processed frames; and $T_{\text{time}}$ is the time in seconds.

Comparison with State-of-the-Art Methods

I compare my improved YOLOv5 model against several mainstream detectors, including YOLOv4, MobileNet-YOLOv5, YOLOv5s, and YOLOv5n. All models are trained and tested under identical conditions to ensure fair comparison. The results, summarized in Table 2, demonstrate that my method achieves the highest precision and competitive recall while maintaining low computational complexity. Notably, the model attains an AP of 89.5% and an FPS of 160, outperforming others in terms of accuracy-speed trade-off. This makes it highly suitable for real-time anti-UAV surveillance in substations.

Table 2: Performance Comparison of Anti-UAV Detection Algorithms
Model Parameters (M) GFLOPs Precision (%) Recall (%) AP (%) FPS
YOLOv4 100.20 210.7 78.24 90.97 89.9 96
MobileNet-YOLOv5 3.60 7.4 86.10 77.90 84.7 134
YOLOv5s 7.20 16.5 89.10 82.60 88.0 156
YOLOv5n 1.90 4.5 85.30 80.70 85.5 158
My Improved Model 1.77 4.2 90.20 85.00 89.5 160

The table highlights that my model reduces parameters and GFLOPs by 6.8% and 6.7% compared to YOLOv5n, respectively, while improving AP by 4%. This lightweight design is advantageous for deployment on edge devices in substations for anti-UAV monitoring. The high FPS ensures that the system can process video streams in real-time, a critical requirement for detecting fast-moving drones.

Ablation Study

To analyze the contribution of each modification, I conduct an ablation study starting from the baseline YOLOv5n model. The results are shown in Table 3, where I incrementally add the four-scale fusion, CBAM, and C3TR modules. Experiment 2, with only the four-scale structure, shows a slight AP improvement, indicating that multi-scale features alone are insufficient. Experiment 3, incorporating CBAM and C3TR, achieves an AP of 88.2%, underscoring the importance of attention mechanisms. Experiment 4 combines four-scale fusion with CBAM, yielding better recall. My full model integrates all three components, achieving the highest AP of 89.5% and recall of 85.0%, validating the synergistic effect of these enhancements for anti-UAV detection.

Table 3: Ablation Study Results for Anti-UAV Detection Improvements
Experiment Four-Scale Fusion CBAM C3TR Precision (%) Recall (%) AP (%)
Baseline (YOLOv5n) No No No 85.3 80.7 85.5
Exp 2 Yes No No 87.4 79.9 85.9
Exp 3 No Yes Yes 90.5 81.6 88.2
Exp 4 Yes Yes No 86.1 81.2 86.3
My Full Model Yes Yes Yes 90.2 85.0 89.5

The ablation study confirms that each component contributes to overall performance, with the C3TR module providing the most significant boost in precision. This is crucial for anti-UAV applications, where false alarms must be minimized to avoid unnecessary alerts in substation security systems.

Detection Results and Analysis

I test my improved model on various real-world UAV videos to evaluate its practical efficacy. The detection results demonstrate robust performance across challenging scenarios, such as cluttered backgrounds, small target sizes, low-light conditions, and multiple UAV instances. For example, in images with heavy background interference, the model accurately localizes drones without false positives. In distant shots where UAVs appear as tiny objects, the four-scale fusion and attention mechanisms enable reliable detection. The model also handles fast-moving drones in dynamic environments, maintaining high FPS for real-time processing. These outcomes highlight the algorithm’s suitability for anti-UAV surveillance in substations, where accuracy and speed are paramount.

To quantify the improvement in small target detection, I compute the AP for objects of different sizes on the test set. My model achieves an AP of 87.3% for small objects (area < 32×32 pixels), compared to 82.1% for the baseline YOLOv5n. This 5.2% gain underscores the effectiveness of the proposed modifications. Additionally, the model’s robustness to varying lighting and weather conditions is validated through augmented test data, showing consistent performance drops of less than 3% in adverse scenarios. These results affirm that the algorithm can operate reliably in diverse substation environments for anti-UAV purposes.

Conclusion

In this paper, I present an improved YOLOv5-based target detection algorithm for anti-UAV applications in substations. The method addresses the challenges of detecting small, fast-moving drones by introducing a four-scale feature fusion structure, a Transformer-enhanced C3TR module, and CBAM attention mechanisms. These innovations enhance feature representation, improve small object detection, and increase model focus on relevant regions. Experimental results show that the algorithm achieves a precision of 90.2%, an AP of 89.5%, and an inference speed of 160 FPS, outperforming existing state-of-the-art methods in both accuracy and efficiency. The lightweight design, with reduced parameters and computational costs, makes it suitable for deployment on edge devices in substations for real-time anti-UAV monitoring.

Future work could explore further optimizations, such as incorporating temporal information from video sequences or adapting the model to other critical infrastructure settings. Additionally, expanding the dataset to include more varied UAV types and environmental conditions would enhance generalization. Overall, this research contributes to advancing anti-UAV technology, offering a practical solution for safeguarding substations against unauthorized drone intrusions. The integration of deep learning techniques with real-time constraints paves the way for more intelligent and responsive security systems in the power grid and beyond.

Scroll to Top