In recent years, the rapid proliferation of unmanned aerial vehicles (UAVs) has posed significant security risks to critical infrastructure, such as electrical substations. As a key component in power transmission and distribution systems, substations require robust protection against unauthorized drone intrusions, often referred to as “black flights.” Traditional anti-drone detection methods, including radar, radio frequency sensing, and electro-optical systems, face limitations in accurately identifying small, fast-moving drones amidst complex backgrounds. To address these challenges, I propose an enhanced anti-drone target detection algorithm based on YOLOv5, specifically optimized for substation environments. This approach leverages deep learning techniques to achieve high precision and real-time performance, ensuring reliable anti-drone surveillance. The algorithm incorporates a four-scale feature fusion structure, a Transformer encoder-integrated C3 module, and a convolutional channel attention mechanism, collectively improving small-target detection and feature representation. In this article, I detail the methodology, experimental validation, and comparative analysis, demonstrating the algorithm’s efficacy in anti-drone applications.
The need for effective anti-drone measures in substations stems from the potential for drones to cause physical damage, data breaches, or operational disruptions. Drones, being small and agile, are difficult to detect using conventional sensors, especially in cluttered settings like substations with various electrical equipment. Vision-based anti-drone systems offer a cost-effective solution by analyzing image data, but they must overcome issues such as low resolution, occlusions, and environmental variability. My work focuses on adapting YOLOv5, a state-of-the-art object detection framework, for this purpose. By refining its architecture, I aim to enhance detection accuracy while maintaining computational efficiency, making it suitable for deployment in resource-constrained substation monitoring systems. The anti-drone capability is critical for safeguarding infrastructure, and this algorithm contributes to that goal by providing a lightweight yet powerful detection tool.

To set the context, let me review existing target detection algorithms and their applicability to anti-drone scenarios. Object detection methods are broadly categorized into two-stage and single-stage approaches. Two-stage algorithms, like Faster R-CNN, generate region proposals before classification, offering high accuracy but at the cost of speed. Single-stage algorithms, such as YOLO (You Only Look Once) and SSD (Single Shot MultiBox Detector), perform detection in a single pass, balancing speed and precision. For anti-drone tasks, real-time processing is essential, as drones can move quickly and require immediate response. YOLOv5, particularly its Nano variant (YOLOv5n), is favored for its lightweight design, with only 1.9 million parameters, making it ideal for embedded systems in substations. However, standard YOLOv5 struggles with small targets like drones, necessitating architectural improvements. My algorithm builds on YOLOv5n by introducing multi-scale feature fusion and attention mechanisms, specifically tailored for anti-drone detection in complex environments.
The core of my improved anti-drone algorithm lies in three key modifications: a four-scale feature fusion structure, a C3TR module with Transformer encoder, and a convolutional block attention module (CBAM). These enhancements address common issues in drone detection, such as small object size, background clutter, and information loss in deep networks. Below, I describe each component in detail, supported by mathematical formulations and structural diagrams. The overall goal is to boost the model’s ability to identify drones with high recall and precision, ensuring reliable anti-drone performance in substation settings.
Four-Scale Feature Fusion Structure
In the original YOLOv5 framework, feature fusion is performed using a combination of Feature Pyramid Network (FPN) and Path Aggregation Network (PAN), which operate at three scales (e.g., 20×20, 40×40, and 80×80 feature maps). While effective for medium and large objects, this structure often misses small drones due to insufficient resolution in shallow layers. To improve small-target detection for anti-drone applications, I extend this to a four-scale fusion by adding a larger-scale detection layer at 160×160 resolution. This layer captures finer-grained details from earlier convolutional stages, enhancing the model’s sensitivity to tiny objects.
The input image is resized to 640×640 pixels and passed through a backbone network based on CSPDarknet53. After five downsampling operations with stride 2, padding 1, and kernel size 2, I obtain feature maps at four different scales: 20×20, 40×40, 80×80, and 160×160. The 160×160 feature map, derived from a 4× downsampling, retains rich spatial information and is used for detecting small drones. The fusion process involves upsampling and concatenation across scales, as shown in the following equations for feature aggregation:
Let $$F_i$$ represent the feature map at scale i, where i ∈ {1,2,3,4} corresponding to 20×20, 40×40, 80×80, and 160×160 resolutions. The fusion output at scale j is computed as:
$$ F_j’ = \text{Concat}(\text{UpSample}(F_{j+1}), F_j) $$
for j = 1,2,3, and for the largest scale (160×160), additional connections from deeper layers are incorporated. This multi-scale approach ensures that both semantic and positional features are leveraged, crucial for anti-drone detection where drones may appear at varying distances. The anchor box sizes are adjusted accordingly, as summarized in Table 1.
| Receptive Field | Feature Map Size | Anchor Box Dimensions |
|---|---|---|
| Small | 160×160 | [5,6], [10,13], [15,11] |
| Medium | 80×80 | [30,61], [8,14], [33,23] |
| Large | 40×40 | [62,45], [16,30], [59,119] |
| Very Large | 20×20 | [30,61], [62,45], [373,326] |
The anchor boxes are determined using K-Means clustering on the COCO2017 dataset, optimized for drone-like objects. This four-scale structure significantly improves recall for small drones, a vital aspect of anti-drone systems.
Improved C3TR Module with Transformer Encoder
The C3 module in YOLOv5, based on Cross Stage Partial (CSP) architecture, reduces computational cost through bottleneck operations. However, for anti-drone detection, capturing long-range dependencies and contextual information is essential, as drones may be partially occluded or blend into backgrounds. I enhance this by embedding a Transformer encoder into the C3 module, creating a C3TR module. The Transformer encoder, originally designed for natural language processing, excels at modeling relationships between sequence elements, which translates well to image patches in computer vision.
The Transformer encoder consists of multi-head self-attention and multi-layer perceptron (MLP) blocks, with layer normalization and dropout for stability. Given an input feature map $$X \in \mathbb{R}^{H \times W \times C}$$, it is first flattened into patches and linearly projected to queries (Q), keys (K), and values (V). The attention mechanism is defined as:
$$ \text{Attention}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right) V $$
where $$d_k$$ is the dimension of K. Multi-head attention extends this by running multiple attention operations in parallel, concatenating the results. This allows the model to focus on different spatial regions, enhancing feature discrimination for drones. The C3TR module replaces the bottleneck in C3 with three Transformer encoder layers, maintaining parameter efficiency while improving feature extraction. Mathematically, if the original C3 output is $$Y = \text{C3}(X)$$, the C3TR output becomes:
$$ Y’ = \text{Conv}(\text{Concat}(\text{Transformer}(X_{\text{reduced}}), X_{\text{shortcut}})) $$
where $$X_{\text{reduced}}$$ is a reduced-channel version of X, and the shortcut connection preserves gradient flow. This modification is applied in the deeper layers of the network, where feature maps have lower resolution, minimizing computational overhead. By integrating Transformer encoders, the model better captures global context, aiding in anti-drone scenarios where drones might be distant or amidst complex substation equipment.
Convolutional Block Attention Module (CBAM)
Attention mechanisms have proven effective in highlighting relevant features while suppressing noise. For anti-drone detection, where drones constitute a small portion of the image, focused attention is crucial. I incorporate CBAM into the neck network of YOLOv5, specifically before each prediction head. CBAM combines channel and spatial attention in a sequential manner, refining features dynamically.
Given an intermediate feature map $$F \in \mathbb{R}^{H \times W \times C}$$, the channel attention module computes a weight vector $$M_c(F) \in \mathbb{R}^{1 \times 1 \times C}$$ using global average and max pooling, followed by an MLP with shared weights. This is expressed as:
$$ M_c(F) = \sigma(\text{MLP}(\text{AvgPool}(F)) + \text{MLP}(\text{MaxPool}(F))) $$
$$ = \sigma(W_1(W_0(F_{\text{avg}})) + W_1(W_0(F_{\text{max}}))) $$
where $$\sigma$$ is the sigmoid activation, $$W_0$$ and $$W_1$$ are MLP weights, and $$F_{\text{avg}}$$ and $$F_{\text{max}}$$ are pooled features. The spatial attention module then generates a weight map $$M_s(F’) \in \mathbb{R}^{H \times W \times 1}$$ based on the channel-refined feature $$F’ = M_c(F) \otimes F$$, where $$\otimes$$ denotes element-wise multiplication. It uses concatenated average and max pooling along the channel axis, followed by a 7×7 convolution:
$$ M_s(F’) = \sigma(f^{7 \times 7}([\text{AvgPool}(F’); \text{MaxPool}(F’)])) $$
The final output is $$F” = M_s(F’) \otimes F’$$. By applying CBAM at multiple scales, the model learns to emphasize drone-related features, such as propellers or distinct shapes, while ignoring irrelevant background elements like power lines or transformers. This targeted attention boosts precision in anti-drone tasks, reducing false positives.
Experimental Setup and Dataset
To validate my anti-drone algorithm, I conduct experiments using a composite dataset of drone images. The dataset combines the Real World dataset (51,446 images) and the Det Fly dataset (13,798 images), covering diverse environments such as skies, urban areas, fields, and mountains, with multiple viewpoints (e.g., front, top, bottom). This variety simulates real-world substation scenarios where drones may appear from different angles. Images are resized to 640×640 and augmented with techniques like Mosaic, MixUp, and Copy-Paste to enhance robustness. The dataset is split into training, validation, and test sets, ensuring a balanced evaluation of anti-drone performance.
The experiments are performed on a system with an NVIDIA GeForce 1080Ti GPU, Intel Core i7-10700 CPU, CUDA 10.1, PyTorch 1.11.0, and Python 3.8. The model is trained for 100 epochs with a batch size of 16, using stochastic gradient descent (SGD) optimizer with momentum 0.937. The learning rate is initialized at 0.01, with a warm-up phase for the first 3 epochs and cosine annealing decay to 0.0001. These settings ensure stable convergence and prevent overfitting, critical for generalizing to unseen anti-drone cases.
Evaluation Metrics
I assess the anti-drone algorithm using standard object detection metrics: precision, recall, average precision (AP), and frames per second (FPS). Precision measures the proportion of correct drone detections among all detections, while recall indicates the fraction of actual drones detected. AP, computed as the area under the precision-recall curve, provides a holistic view of performance across confidence thresholds. FPS gauges real-time capability, essential for anti-drone surveillance. The formulas are as follows:
Precision: $$ P = \frac{N_{TP}}{N_{TP} + N_{FP}} $$
Recall: $$ R = \frac{N_{TP}}{N_{TP} + N_{FN}} $$
Average Precision: $$ AP = \int_0^1 p(r) \, dr $$
Frames per Second: $$ \text{FPS} = \frac{N_{\text{frames}}}{T_{\text{time}}} $$
where $$N_{TP}$$ is true positives, $$N_{FP}$$ is false positives, $$N_{FN}$$ is false negatives, $$p(r)$$ is precision at recall r, $$N_{\text{frames}}$$ is number of processed frames, and $$T_{\text{time}}$$ is time in seconds. Higher AP and FPS values indicate better anti-drone effectiveness and efficiency.
Comparison with State-of-the-Art Algorithms
I compare my improved YOLOv5 algorithm against several baseline models: YOLOv4, MobileNet-YOLOv5, YOLOv5s, and YOLOv5n. All models are trained on the same dataset under identical conditions. The results, summarized in Table 2, highlight the advantages of my approach for anti-drone applications.
| 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 Algorithm | 1.77 | 4.2 | 90.20 | 85.00 | 89.5 | 160 |
My algorithm achieves the highest precision (90.2%) and competitive recall (85.0%), with an AP of 89.5%, close to YOLOv4 but with significantly lower computational cost. The parameter count is reduced by 6.8% compared to YOLOv5n, and GFLOPs decrease by 6.7%, demonstrating lightweight design. Importantly, the FPS reaches 160, surpassing all baselines and meeting real-time requirements for anti-drone systems. This balance of accuracy and speed makes it suitable for substation deployment, where resources are limited and rapid response is needed.
Ablation Studies
To dissect the contribution of each component, I perform ablation studies by incrementally adding modifications to the base YOLOv5n model. The results, shown in Table 3, confirm the effectiveness of my enhancements for anti-drone detection.
| Experiment | Four-Scale Fusion | CBAM | C3TR Module | Precision (%) | Recall (%) | AP (%) |
|---|---|---|---|---|---|---|
| Base (YOLOv5n) | No | No | No | 85.3 | 80.7 | 85.5 |
| Exp 1 | Yes | No | No | 87.4 | 79.9 | 85.9 |
| Exp 2 | No | Yes | Yes | 90.5 | 81.6 | 88.2 |
| Exp 3 | Yes | Yes | No | 86.1 | 81.2 | 86.3 |
| Full Model | Yes | Yes | Yes | 90.2 | 85.0 | 89.5 |
The four-scale fusion alone (Exp 1) improves precision but has limited impact on recall, as small drones remain challenging. Adding CBAM and C3TR (Exp 2) boosts AP significantly, highlighting the importance of attention and context modeling. The full model, integrating all three components, achieves the best recall and AP, indicating synergistic effects. Notably, the recall increase from 80.7% to 85.0% reduces missed detections, crucial for reliable anti-drone operations where every intrusion must be identified.
Visual Detection Results
I test the algorithm on diverse drone videos to showcase its anti-drone capabilities in realistic substation-like settings. The model successfully detects drones under various conditions: against cluttered backgrounds, at close range, as distant small objects, and in low-light environments. For instance, in scenarios with multiple tiny drones against sky or equipment, the algorithm accurately localizes them with high confidence scores. The attention mechanisms help suppress false positives from similar-shaped objects, such as birds or debris, ensuring focused anti-drone monitoring. These results underscore the algorithm’s robustness, making it a viable solution for substation security.
Mathematical Formulation of Loss Function
To optimize the anti-drone detection, I use the same loss function as YOLOv5, which combines classification loss, objectness loss, and bounding box regression loss. The total loss is given by:
$$ L_{\text{total}} = \lambda_{\text{cls}} L_{\text{cls}} + \lambda_{\text{obj}} L_{\text{obj}} + \lambda_{\text{box}} L_{\text{box}} $$
where $$L_{\text{cls}}$$ is binary cross-entropy for class prediction, $$L_{\text{obj}}$$ is cross-entropy for object confidence, and $$L_{\text{box}}$$ is Complete IoU (CIoU) loss for bounding box accuracy. The weights $$\lambda_{\text{cls}}$$, $$\lambda_{\text{obj}}$$, and $$\lambda_{\text{box}}$$ are set to balance the terms. CIoU loss considers overlap area, center distance, and aspect ratio, defined as:
$$ L_{\text{box}} = 1 – \text{IoU} + \frac{\rho^2(b, b^{gt})}{c^2} + \alpha v $$
where IoU is intersection over union, $$\rho$$ is Euclidean distance between box centers, c is diagonal length of the minimal enclosing box, and v measures aspect ratio consistency. This loss enhances localization precision for drones, which often have irregular orientations.
Computational Complexity Analysis
My algorithm’s lightweight nature is analyzed through parameter and FLOP counts. The reduction in parameters from 1.90M to 1.77M is achieved by pruning redundant connections in the C3TR module and efficient attention design. The FLOPs decrease from 4.5G to 4.2G, implying faster inference. This is critical for anti-drone systems deployed on edge devices in substations, where power and memory are constrained. The four-scale fusion adds minimal overhead due to shallow layer processing, and CBAM’s computational cost is negligible as it operates on pooled features. Overall, the model maintains a trade-off between complexity and performance, enabling sustainable anti-drone monitoring.
Future Directions for Anti-Drone Research
While my algorithm shows promise, anti-drone detection can be further improved. Future work may explore integrating temporal information from video streams to track drone movements, using 3D convolutions for depth-aware detection, or incorporating adversarial training to counter evasion techniques. Additionally, federated learning could enable collaborative anti-drone networks across multiple substations without sharing sensitive data. The ongoing evolution of drone technology necessitates continuous updates to anti-drone algorithms, ensuring they remain effective against emerging threats.
Conclusion
In this article, I present an improved YOLOv5-based algorithm for anti-drone target detection in substations. By introducing a four-scale feature fusion structure, a Transformer-enhanced C3TR module, and a convolutional attention mechanism, the model achieves high accuracy and real-time speed. Experimental results demonstrate superior performance compared to state-of-the-art methods, with 90.2% precision, 89.5% AP, and 160 FPS. The lightweight design, with only 1.77 million parameters, makes it suitable for embedded deployment. This work contributes to the growing field of anti-drone security, offering a practical solution for protecting critical infrastructure. As drone threats evolve, such advanced detection systems will play a vital role in ensuring safety and reliability in power grids and beyond.
