YOLOv7-EPAN for Solar Panel Infrared Image Defect Detection

In the pursuit of carbon peak and carbon neutrality goals, the photovoltaic power generation industry has experienced rapid expansion. Solar panels, as the core components of photovoltaic power stations, are frequently installed in harsh environments. Long-term exposure to environmental factors leads to various defects, such as cell failure, diode failure, and occlusion, which cause localized heating and threaten the safe operation of the entire station. Therefore, regular and reliable defect detection of solar panels is essential. With the increasing scale of photovoltaic plants, traditional manual inspection methods have become inadequate. Unmanned aerial vehicle (UAV) inspection equipped with infrared cameras has emerged as the mainstream approach. However, aerial infrared images of solar panels present significant challenges: the defects are often very small due to high flight altitudes, the images have low contrast and complex backgrounds, and small target defects are easily missed. To address these issues, we propose a novel defect detection method named YOLOv7-EPAN. This method enhances the YOLOv7 baseline by introducing a CSWin Transformer fused efficient layer aggregation network (CS-ELAN), constructing an efficient path aggregation feature pyramid network (EPAN), and optimizing the loss function to improve small target localization accuracy. Extensive experiments on a real aerial infrared solar panel dataset demonstrate that our method achieves a 6.4% improvement in mAP50 and 3.3% improvement in mAP50:95 over the original YOLOv7, effectively solving the problem of small target defect detection under complex backgrounds.

Introduction

Solar panels are crucial for converting solar energy into electricity. Defects such as hot spots, cracks, and diode failures not only reduce power generation efficiency but can also lead to fire hazards. Regular inspection of solar panels is vital for the safe and efficient operation of photovoltaic plants. Traditional image processing methods, such as thresholding, morphological operations, and histogram analysis, have been used for defect detection in infrared images. For instance, some researchers employed B-spline fitting to suppress noise in infrared images for hot spot detection, while others used the Otsu method combined with visible and infrared image fusion to reduce false alarms. However, these traditional methods suffer from long processing times, poor generalization, and high sensitivity to environmental variations. They are not suitable for intelligent large-scale inspection.

Deep learning-based methods, particularly object detection algorithms, have shown great promise in solar panel defect detection. They can automatically learn discriminative features and provide accurate localization, meeting the demands of intelligent inspection. Among them, one-stage detectors like YOLO series have gained popularity due to their balance between speed and accuracy. However, when applied to aerial infrared solar panel images, these methods often struggle with small targets and complex backgrounds. The YOLOv7 algorithm, proposed in 2022, achieves state-of-the-art performance in many object detection benchmarks. Its backbone uses efficient layer aggregation networks (ELAN) and the neck employs a path aggregation feature pyramid network (PAFPN) enhanced by extended ELAN (E-ELAN). Despite these strengths, YOLOv7 still faces challenges in detecting small solar panel defects because convolutional kernels in ELAN tend to capture local information and can be distracted by irrelevant background noise. Moreover, the original loss function (CIoU) is sensitive to small bounding box offsets, hindering accurate localization of tiny defects.

To overcome these limitations, we propose a YOLOv7-EPAN (Efficient Path Aggregation Network) model specifically designed for solar panel infrared image defect detection. Our contributions are threefold. First, we integrate the CSWin Transformer into the ELAN module to create CS-ELAN, which captures global contextual information via cross-shaped window self-attention, suppressing background interference and enhancing defect features. Second, we construct an efficient path aggregation feature pyramid network (EPAN) based on CS-ELAN to strengthen multi-scale feature interaction, enriching semantic information and improving feature expressiveness. Third, we refine the regression loss by combining the Normalized Wasserstein Distance (NWD) loss with CIoU loss, making the model focus on high-quality prior boxes and improving small target localization. Experimental results on a real aerial infrared solar panel dataset demonstrate the superiority of our method compared to mainstream detectors.

YOLOv7 Baseline

YOLOv7 is a real-time object detector that achieves high accuracy and speed. The model consists of an input stage, a backbone, a neck, and a head. The input resizes images to 640×640. The backbone uses CBS (Conv + BN + SiLU) layers, ELAN modules, and MPConv (MaxPool + Conv) to extract multi-scale features at downsampling strides of 8, 16, and 32. The neck, based on the path aggregation feature pyramid network (PAFPN), incorporates E-ELAN modules to fuse features from different scales. The head applies RepVGG blocks and 1×1 convolutions to produce final predictions. The original loss function includes confidence loss (BCEWithLogits), classification loss (BCEWithLogits), and regression loss (CIoU). CIoU considers overlap area, center distance, and aspect ratio but is sensitive to small object displacements.

Proposed YOLOv7-EPAN

CS-ELAN Module

The original ELAN module uses stacked convolutions to aggregate features, which tends to focus on local receptive fields and may ignore global context. To address this, we propose the CS-ELAN module, which integrates CSWin Transformer’s cross-shaped window attention mechanism. CSWin Transformer splits the multi-head attention into two groups: one performs horizontal stripe self-attention and the other vertical stripe self-attention. The outputs are concatenated. This design efficiently captures global spatial information while maintaining computational efficiency.

Given an input feature map X ∈ ℝH×W×C, the horizontal self-attention for stripe n is computed as:

$$
\text{H-Attention}_n(X) = \text{Attention}(X_n W_n^Q, X_n W_n^K, X_n W_n^V)
$$

where Xn ∈ ℝSW×W×C, SW is the stripe width, and WnQ,K,V ∈ ℝC×dk. The vertical attention is defined analogously. The final output is:

$$
\text{CSWin-Attention}(X) = \text{Concat}(h^1, h^2, …, h^K) W^O
$$

where hk is either horizontal or vertical attention output depending on the head index.

As shown in Figure (reference to CS-ELAN structure), our CS-ELAN module reduces the number of 3×3 convolutions by decomposing them into 1×3 and 3×1 convolutions (Conv3 block). The input xin passes through two 1×1 convolutions to produce x1 and x2 (each with C/2 channels). Then x1 is fed into a Conv3 block to obtain x3 (C/4 channels). After tensor reshaping, a CSWin block processes the feature to produce x4 (C/4 channels). Another Conv3 block yields x5. Finally, x1, x2, x3, x4, and x5 are concatenated along the channel dimension and passed through a final 1×1 convolution to produce the output xout with C channels. The process is formulated as:

$$
\begin{aligned}
x_1 &= \text{CBS}(x_{in}) \\
x_2 &= \text{CBS}(x_{in}) \\
x_3 &= \text{Conv3}(x_1) \\
y &= \text{TensorRefactor}(x_3) \\
y &= \text{CSWin}(y) \\
x_4 &= \text{TensorRefactor}(y) \\
x_5 &= \text{Conv3}(x_4) \\
x_{out} &= \text{CBS}(\text{Cat}(x_1, x_2, x_3, x_4, x_5))
\end{aligned}
$$

This design enables the module to capture both local and global features, enhancing the representation of small solar panel defects while suppressing background clutter.

EPAN: Efficient Path Aggregation Feature Pyramid Network

Multi-scale feature fusion is critical for detecting objects of varying sizes. To fully exploit CS-ELAN, we build an EPAN that connects the backbone’s three feature layers C3 (stride 8), C4 (stride 16), and C5 (stride 32) with top-down and bottom-up pathways, as illustrated in Figure (reference to EPAN structure). The input feature sizes are 80×64, 40×32, and 20×16 for the infrared images of 640×512 resolution.

In the top-down path, C5′ is obtained after a convolution, then upsampled and concatenated with the convolved C4. This combined feature is processed by a CS-ELAN module to produce C4′. Similarly, C4′ is upsampled and concatenated with convolved C3, then processed by another CS-ELAN to yield P3. In the bottom-up path, P3 is downsampled via an MP module, concatenated with C4′, and passed through a CS-ELAN to obtain P4. Finally, P4 is downsampled, concatenated with C5′, and processed to get P5. The three output feature maps {P3, P4, P5} are used for detecting small, medium, and large solar panel defects. The stripe width SW for CSWin in each CS-ELAN is set to 8, 8, and 4 for the three scales, respectively, to match the spatial dimensions and provide sufficient receptive fields.

Improved Loss Function

The original YOLOv7 uses CIoU as the regression loss. CIoU is defined as:

$$
\text{Loss}_{\text{CIoU}} = 1 – \text{IoU} + \frac{\rho^2(b, b^{gt})}{c^2} + \alpha v
$$
$$
v = \frac{4}{\pi^2} \left( \arctan\frac{w^{gt}}{h^{gt}} – \arctan\frac{w}{h} \right)^2
$$
$$
\alpha = \frac{v}{(1 – \text{IoU}) + v}
$$

Where b and bgt are the predicted and ground truth box centers, c is the diagonal distance of the smallest enclosing box, and v measures aspect ratio similarity. However, CIoU is sensitive to small offsets, which impairs small solar panel defect localization.

We introduce the Normalized Wasserstein Distance (NWD) loss, which models bounding boxes as 2D Gaussian distributions and measures their similarity. For bounding boxes A=(cxa, cya, wa, ha) and B=(cxb, cyb, wb, hb), the 2nd-order Wasserstein distance is:

$$
W_2^2(N_a, N_b) = \| [cx_a, cy_a, \frac{w_a}{2}, \frac{h_a}{2}]^T – [cx_b, cy_b, \frac{w_b}{2}, \frac{h_b}{2}]^T \|_2^2
$$

The NWD loss is then:

$$
\text{Loss}_{\text{NWD}} = 1 – \exp\left(-\frac{\sqrt{W_2^2(N_a, N_b)}}{c}\right)
$$

Where c is a constant related to the dataset. To ensure stable convergence, we combine NWD and CIoU with a balance factor λ:

$$
\text{Loss}_{re} = (1 – \lambda) \text{Loss}_{\text{NWD}} + \lambda \text{Loss}_{\text{CIoU}}
$$

Through ablation experiments, we set λ = 0.5 as the optimal value, which yields the best trade-off between small target precision and overall accuracy.

Experiments

Experimental Setup

All experiments were conducted on an Ubuntu 18.04 system with PyTorch 1.11.0, an Intel i9-12900 CPU, an NVIDIA GeForce RTX 3090 Ti (24 GB), and Python. The training parameters follow YOLOv7’s default settings: input size 640×640, batch size 4, epochs 400, SGD optimizer with initial learning rate 0.01, momentum 0.937, weight decay 0.0005, and cosine annealing scheduler. Data augmentation includes MixUp and Mosaic to improve generalization. We used the pre-trained YOLOv7 weights.

Dataset

The aerial infrared solar panel dataset was captured by a UAV equipped with an infrared camera at a photovoltaic power plant under clear weather conditions. It contains 3013 images with resolution 640×512. Three defect categories are labeled: cell failure, diode failure, and occlusion. There are 9234 bounding boxes in total. The dataset is split into a training set (2553 images, 7668 boxes) and a test set (460 images, 1566 boxes). The distribution of small, medium, and large objects (based on COCO definition) shows that most defects are small (area < 32² pixels). Detailed statistics are provided in the table below.

Dataset Summary
Subset Images Boxes Cell Failure Diode Failure Occlusion
Train 2553 7668 5894 1367 407
Test 460 1566 1382 119 65

Evaluation Metrics

We use mean Average Precision (mAP50 and mAP50:95), APS (area < 32² pixels), and APM (32²–96² pixels) as accuracy metrics. Model complexity is measured by parameters (Params), and speed by frames per second (FPS).

Ablation Studies

We conducted ablation experiments to verify each proposed improvement. The baseline is YOLOv7. We step-by-step add: (A) replacing ELAN with CS-ELAN and constructing EPAN; (B) substituting the loss function with a weighted combination (λ=0.1, 0.3, 0.5, 0.7, 0.9). The results are summarized in the following table.

Ablation Results (all values in %)
Group Modules mAP50 mAP50:95 APS APM Params (M) FPS
1 Baseline 75.1 38.8 32.4 36.4 37.2 120
2 Baseline + A 80.3 40.9 35.5 36.5 35.3 83
3 Baseline + A + B (λ=0.1) 80.9 40.6 35.8 36.2 35.3 83
4 Baseline + A + C (λ=0.3) 80.6 40.3 35.6 35.2 35.3 83
5 Baseline + A + D (λ=0.5) 81.5 42.1 37.4 37.9 35.3 83
6 Baseline + A + E (λ=0.7) 79.9 40.5 36.1 35.7 35.3 83
7 Baseline + A + F (λ=0.9) 77.3 39.7 34.1 36.4 35.3 83

From the table, adding CS-ELAN and EPAN (Group 2) improves mAP50 by 5.2% and APS by 3.1% compared to the baseline, while reducing parameters by 1.9M. The speed decreases from 120 FPS to 83 FPS but still meets real-time requirements. Among loss function variants, λ=0.5 yields the best overall accuracy, with mAP50 reaching 81.5% and APS 37.4%. The loss curves (not shown as per guidelines) indicated faster and more stable convergence. These results confirm the effectiveness of each component.

Comparison with State-of-the-Art

We compared our YOLOv7-EPAN with popular detectors: SSD, RetinaNet, YOLOv3, YOLOv4, YOLOv5s, YOLOv5l, TPH-YOLOv5, YOLOX, YOLOv7, and YOLOv8. All models were trained and tested on the same dataset under identical conditions. The results are shown below.

Performance comparison with state-of-the-art detectors
Method AP50 Cell AP50 Diode AP50 Occlusion mAP50 APS APM Params (M) FPS
SSD 35.1 87.5 36.2 52.9 19.6 25.6 23.75 16
RetinaNet 57.6 93.4 59.3 70.1 24.3 34.1 32.24 40
YOLOv3 74.7 90.2 64.2 76.3 33.1 31.8 62.6 92
YOLOv4 77.5 92.9 47.6 72.7 30.4 35.2 63.9 97
YOLOv5s 77.2 94.0 58.9 76.7 33.6 30.8 7.02 101
YOLOv5l 77.1 91.8 65.1 78.0 34.7 37.6 46.1 62
YOLOX 79.4 93.7 63.4 78.9 8.94 89
TPH-YOLOv5 76.7 93.3 62.9 77.6 37.1 36.3 45.4 60
YOLOv7 78.7 93.9 52.6 75.1 32.4 36.4 37.2 120
YOLOv8 77.7 93.7 68.3 79.9 33.8 36.7 3.0 200
Ours 79.2 94.9 70.8 81.5 37.4 37.9 35.3 83

Our method achieves the highest mAP50 (81.5%), outperforming YOLOv7 by 6.4% and YOLOv8 by 1.6%. The AP for the occlusion class improved dramatically from 52.6% (YOLOv7) to 70.8%, demonstrating strong robustness to multi-scale small defects. APS reaches 37.4%, the best among all methods, which validates the effectiveness of our global attention and loss design. While YOLOv8 has higher FPS (200) and fewer parameters (3.0M), its accuracy is lower than ours. TPH-YOLOv5, which adds multiple attention heads, achieves 37.1% APS but at the cost of 45.4M parameters and 60 FPS. Our method strikes an excellent balance between accuracy, parameter count, and speed (83 FPS), sufficient for real-time UAV inspection of solar panels.

Qualitative Results

To visually demonstrate the superiority of our method, we compare detection results of several challenging test images. In scenes with small defects, low contrast, or background interference, our YOLOv7-EPAN consistently detects all solar panel defects with high confidence, while YOLOv7, YOLOv5, TPH-YOLOv5, and YOLOv8 often miss some defects or produce false positives. For example, in images where defects are tiny and similar to the background, our model successfully identifies them, whereas other detectors show missed detections. In images with strong background clutter (e.g., metal frames, wiring), our method avoids false alarms. These qualitative results confirm that our improvements enable robust small target detection under complex backgrounds, thanks to the global context from CSWin attention, multi-scale fusion in EPAN, and precise bounding box regression from the combined loss.

Conclusion

We presented YOLOv7-EPAN, a novel defect detection method for solar panel infrared images captured by UAVs. The key innovations include the CS-ELAN module that integrates cross-shaped window attention to capture global features while suppressing background noise, the EPAN network that strengthens multi-scale feature interaction, and an improved regression loss combining NWD and CIoU to enhance small target localization. Comprehensive experiments on a real-world aerial infrared solar panel dataset show that our method achieves 81.5% mAP50, surpassing the original YOLOv7 by 6.4% and other state-of-the-art detectors. The method also achieves 37.4% APS and 37.9% APM, demonstrating superior small target detection capability. With a parameter count of 35.3M and 83 FPS, it is suitable for real-time inspection of solar panels. Our approach provides a practical and effective solution for intelligent defect detection in large-scale photovoltaic plants, contributing to safer and more efficient solar energy production.

Scroll to Top