YOLOv7-EPAN for Defect Detection in Solar Panels Infrared Images

Infrared thermal imaging has become a crucial tool for inspecting solar panels in large-scale photovoltaic plants. However, aerial infrared images of solar panels often suffer from complex backgrounds, low contrast, and small target defects, leading to high false-negative rates. To address these challenges, I present an enhanced defect detection framework based on YOLOv7, named YOLOv7-EPAN. First, I propose a novel CS-ELAN module that integrates CSWin Transformer into the efficient layer aggregation network. This module captures global contextual information while suppressing irrelevant background features, significantly improving the representation of small defects on solar panels. Second, I construct an Efficient Path Aggregation Network (EPAN) built upon CS-ELAN blocks, which enhances multi-scale feature interaction and enriches semantic information across different resolution layers. Third, I optimize the regression loss function by combining the Normalized Wasserstein Distance (NWD) loss with the original CIoU loss, making the model more sensitive to high-quality anchor boxes and improving localization accuracy for tiny defects. Extensive experiments on a real-world aerial infrared solar panel dataset demonstrate that my method achieves an mAP50 of 81.5% and mAP50:95 of 42.1%, outperforming the baseline YOLOv7 by 6.4% and 3.3%, respectively. The proposed approach effectively reduces missed detections of small defects in complex backgrounds, showing great potential for intelligent inspection of solar panels.

Performance comparison of different detection models on the solar panel infrared dataset
Model mAP50 (%) mAP50:95 (%) APS (%) APM (%) Params (M) FPS (f/s)
SSD 52.9 19.6 25.6 23.75 23.75 16
RetinaNet 70.1 24.3 34.1 32.24 32.24 40
YOLOv3 76.3 33.1 31.8 62.6 62.6 92
YOLOv4 72.7 30.4 35.2 63.9 63.9 97
YOLOv5s 76.7 33.6 30.8 7.02 7.02 101
YOLOv5l 78.0 34.7 37.6 46.1 46.1 62
YOLOX 78.9 8.94 8.94 89
TPH-YOLOv5 77.6 37.1 36.3 45.4 45.4 60
YOLOv7 (baseline) 75.1 38.8 32.4 36.4 37.2 120
YOLOv8 79.9 33.8 36.7 3.0 3.0 200
YOLOv7-EPAN (Ours) 81.5 42.1 37.4 37.9 35.3 83

1. Introduction

Solar panels are the core components of photovoltaic power stations, and they must be inspected regularly to ensure safe and efficient operation. With the rapid expansion of solar farms, manual inspection has become impractical. Unmanned aerial vehicles (UAVs) equipped with infrared cameras are now widely adopted. However, the infrared images captured by UAVs present three major challenges: (1) defects occupy only a small portion of the image, making them small targets; (2) the images have low contrast and complex backgrounds, including shadows, dust, and plant reflections; (3) there is high intra-class variability and inter-class similarity among defect types. Traditional image processing methods, such as thresholding and morphological operations, are sensitive to noise and lack generalization. Deep learning-based object detectors, especially single-stage models like YOLO, have shown promise in real-time detection but still struggle with small defects on solar panels under complex backgrounds.

To overcome these limitations, I propose an improved detection model based on YOLOv7, specifically designed for infrared defect detection of solar panels. The main contributions are:

  • I introduce the CS-ELAN module, which integrates the CSWin Transformer’s cross-shaped window attention mechanism into the efficient layer aggregation network. This module enhances global context extraction and suppresses irrelevant background information.
  • I construct an Efficient Path Aggregation Network (EPAN) using CS-ELAN blocks as the fundamental building unit. EPAN facilitates richer multi-scale feature fusion and strengthens the representation capability for small defects.
  • I optimize the bounding box regression loss by combining Normalized Wasserstein Distance (NWD) loss with CIoU loss, making the model focus on high-quality anchor boxes and improving localization accuracy for tiny targets.
  • Extensive experiments on a real aerial infrared solar panel dataset demonstrate that my method achieves state-of-the-art performance, with mAP50 reaching 81.5%, which is 6.4% higher than the original YOLOv7.

2. Related Work

Defect detection of solar panels using infrared images has been studied with both traditional image processing and deep learning methods. Traditional approaches often rely on histogram analysis, thresholding, and morphological operations. For instance, some researchers used B-spline fitting to suppress noise and detect hot spots. Others employed the Otsu method combined with visible-infrared fusion to reduce false alarms. However, these methods suffer from poor generalization and are easily affected by environmental variations.

In recent years, deep learning-based detectors have become dominant. Two-stage detectors like Faster R-CNN provide high accuracy but are too slow for real-time UAV inspection. Single-stage detectors, especially the YOLO series, offer a good trade-off between speed and accuracy. YOLOv7, proposed in 2022, achieved state-of-the-art performance in real-time object detection by introducing trainable bag-of-freebies and efficient network architectures. However, direct application of YOLOv7 to infrared solar panel images still leads to missed detections of small defects due to insufficient feature extraction from complex backgrounds. Some works have attempted to improve small target detection using attention mechanisms or feature pyramid enhancements. For example, TPH-YOLOv5 added a transformer prediction head, but it increased model size. My work focuses on embedding a lightweight global attention mechanism into the backbone and neck of YOLOv7, specifically tailored for solar panel defect detection.

3. Methodology

3.1 Overview of YOLOv7

YOLOv7 is a single-stage detector that consists of a backbone, a neck, and a head. The backbone extracts multi-scale feature maps using CBS (Conv-BN-SiLU) layers, ELAN (Efficient Layer Aggregation Network) modules, and MPConv blocks. The neck employs a path aggregation feature pyramid network (PAFPN) with E-ELAN modules to fuse features from different scales. The head uses RepVGG blocks and 1×1 convolutions to produce final predictions. The loss function includes classification loss (BCEWithLogitsLoss), confidence loss (BCEWithLogitsLoss), and regression loss (CIoU Loss). While YOLOv7 is powerful, its ELAN modules rely solely on convolutions, which have limited receptive fields and may fail to capture global context, especially for small defects on solar panels. Moreover, the CIoU loss is sensitive to small bounding box displacements, hindering accurate localization.

3.2 CS-ELAN Module

To enhance the model’s ability to extract global features and suppress background noise, I propose the CS-ELAN module. This module replaces the standard 3×3 convolution in ELAN with a combination of 1×3 and 3×1 convolutions, and inserts a CSWin Transformer block after the first convolution branch. The CSWin Transformer uses cross-shaped window self-attention, which splits the feature map into horizontal and vertical stripes, enabling efficient global information exchange. The structure of CS-ELAN is shown below (described verbally).

The input feature \( x_{in} \in \mathbb{R}^{H \times W \times C} \) first passes through two 1×1 convolutions to produce \( x_1 \) and \( x_2 \) with \( C_1 = C/2 \). Then \( x_1 \) goes through a Conv3 block (with 1×3 and 3×1 convolutions) to yield \( x_3 \) with \( C_2 = C/4 \). After tensor reshaping, it enters the CSWin block. The CSWin block computes horizontal and vertical self-attention in parallel and concatenates the results:

$$ \text{CSWin-Attention}(X) = \text{Concat}(H_1(X), H_2(X), \dots, H_K(X)) W^O $$

where \( H_n(X) = \text{Attention}(XW_n^Q, XW_n^K, XW_n^V) \) for \( n \le K/2 \) (horizontal stripes), and \( H_n(X) = \text{V-Attention}_n(X) \) for \( n > K/2 \) (vertical stripes). The stripe width is set adaptively based on feature map size. After CSWin, the output is reshaped and passed through another Conv3 block to obtain \( x_5 \). Finally, \( x_1, x_2, x_3, x_4, x_5 \) are concatenated along the channel dimension and fused by a 1×1 convolution to produce the final output \( x_{out} \) with \( C_5 = C \).

3.3 Efficient Path Aggregation Network (EPAN)

To further leverage the CS-ELAN module for multi-scale feature fusion, I design EPAN as the neck network. EPAN takes three feature maps from the backbone: \( C_3 \) (downsampled by 8), \( C_4 \) (downsampled by 16), and \( C_5 \) (downsampled by 32). These correspond to spatial sizes of 80×64, 40×32, and 20×16 for an input of 640×512 pixels. The top-down pathway first adjusts \( C_5 \) via convolution to get \( C_5′ \), then upsamples it and concatenates with a convolution-processed \( C_4 \). The concatenated feature is fed into a CS-ELAN module to produce \( C_4′ \). Similarly, after upsampling and concatenation with \( C_3 \), another CS-ELAN generates \( P_3 \). The bottom-up pathway takes \( P_3 \), downsamples it via MP (MaxPool) module, concatenates with \( C_4′ \), and passes through CS-ELAN to produce \( P_4 \). The same operation yields \( P_5 \). The final outputs \( P_3, P_4, P_5 \) are used for detection at different scales. The stripe widths for CSWin in these three scales are set to 8, 8, and 4 respectively to ensure proper receptive fields.

3.4 Loss Function Optimization

The original YOLOv7 uses CIoU loss for bounding box regression:

$$ \mathcal{L}_{\text{CIoU}} = 1 – \text{IoU} + \frac{\rho^2(b, b^{gt})}{c^2} + \alpha v $$

where \( v = \frac{4}{\pi^2} \left( \arctan\frac{w^{gt}}{h^{gt}} – \arctan\frac{w}{h} \right)^2 \), and \( \alpha = \frac{v}{(1-\text{IoU})+v} \). While CIoU considers overlap, center distance, and aspect ratio, it is highly sensitive to small displacements, which is detrimental for tiny defects on solar panels. To mitigate this, I introduce the Normalized Wasserstein Distance (NWD) loss. The NWD models bounding boxes as 2D Gaussian distributions \(\mathcal{N}_a\) and \(\mathcal{N}_b\). The Wasserstein distance between them is:

$$ W_2^2(\mathcal{N}_a, \mathcal{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 defined as:

$$ \mathcal{L}_{\text{NWD}} = 1 – \exp\left( -\frac{W_2^2}{c} \right) $$

where \( c \) is a constant related to the dataset. I combine it with CIoU loss using a balance factor \( \lambda \):

$$ \mathcal{L}_{\text{reg}} = (1 – \lambda) \mathcal{L}_{\text{NWD}} + \lambda \mathcal{L}_{\text{CIoU}} $$

Ablation experiments show that \( \lambda = 0.5 \) yields the best performance. The overall loss becomes:

$$ \mathcal{L}_{\text{total}} = \mathcal{L}_{\text{reg}} + \mathcal{L}_{\text{cls}} + \mathcal{L}_{\text{obj}} $$

where \( \mathcal{L}_{\text{cls}} \) and \( \mathcal{L}_{\text{obj}} \) are BCEWithLogitsLoss for classification and objectness.

4. Experiments

4.1 Dataset and Implementation Details

I use a real dataset of aerial infrared images of solar panels captured by a UAV equipped with an infrared camera. The dataset contains 3,013 images with a resolution of 640×512 pixels. Three types of defects are annotated: cell failure, diode failure, and occlusion. In total, there are 9,234 bounding boxes. The dataset is split into training (2,553 images) and testing (460 images) sets at a ratio of approximately 5:1. The proportion of small, medium, and large objects follows the COCO definition: most defects are small (area < 32²).

The experiments are conducted on an Ubuntu 18.04 system with PyTorch 1.11.0, an Intel i9-12900 CPU, and an NVIDIA RTX 3090 Ti GPU (24 GB). Input images are resized to 640×640. Training uses SGD optimizer with initial learning rate 0.01, momentum 0.937, weight decay 0.0005, batch size 4, and 400 epochs. Cosine annealing is applied for learning rate scheduling. Data augmentation includes MixUp and Mosaic. Pre-trained weights from YOLOv7 are used for initialization.

4.2 Evaluation Metrics

I report mAP50 (IoU threshold 0.5), mAP50:95 (average over IoU thresholds 0.5:0.95, step 0.05), APS (small objects), APM (medium objects), Params (model parameters), and FPS (frames per second).

4.3 Ablation Study

I perform stepwise ablation to validate each improvement. The baseline is YOLOv7. Adding the CS-ELAN module and replacing the neck with EPAN (called Baseline+A) improves mAP50 from 75.1% to 80.3% (+5.2%) and mAP50:95 from 38.8% to 40.9% (+2.1%). The small object detection APS improves by 3.1%. The parameter count drops from 37.2M to 35.3M due to efficient design, but FPS decreases from 120 to 83, still satisfying real-time requirements.

Next, I incorporate the optimized loss function with different \( \lambda \) values. The best result occurs at \( \lambda = 0.5 \) (Baseline+A+D), achieving mAP50 = 81.5% and mAP50:95 = 42.1%. Compared to Baseline+A, APS increases by 1.9% and APM by 1.4%, confirming that the loss optimization improves localization of small and medium defects. The loss curves show faster convergence and smoother descent with the hybrid loss.

To further illustrate the effectiveness, I generate Grad-CAM heatmaps for five typical scenes. The heatmaps show that my model focuses more precisely on defect regions while suppressing background clutter, unlike the original YOLOv7 which sometimes highlights irrelevant areas.

4.4 Comparison with State-of-the-Art

I compare my YOLOv7-EPAN with SSD, RetinaNet, YOLOv3, YOLOv4, YOLOv5s/l, YOLOX, TPH-YOLOv5, YOLOv7, and YOLOv8. All models are trained and tested on the same dataset. My method achieves the highest mAP50 (81.5%), mAP50:95 (42.1%), APS (37.4%), and APM (37.9%). The improvements are consistent across all defect categories: cell failure (+0.5%), diode failure (+1.0%), and occlusion (+18.2%) compared to YOLOv7. The significant boost in occlusion detection is attributed to the improved handling of small and variably shaped defects. Though FPS is lower than YOLOv8 (200 f/s), my model still runs at 83 f/s, more than sufficient for real-time UAV inspection. In terms of parameters, my model has only 35.3M, lighter than TPH-YOLOv5 (45.4M) and YOLOv5l (46.1M).

4.5 Qualitative Results

Visual comparisons on five representative test images show that my method successfully detects all defects without false positives or missed detections, whereas other models (YOLOv7, TPH-YOLOv5, YOLOv5, YOLOv8) often miss small defects, generate false alarms, or produce inaccurate bounding boxes. For instance, in a scene with shaded solar panels, my model correctly identifies a tiny occlusion that YOLOv7 overlooks. In another image with low contrast, my model locates a diode failure that YOLOv8 misclassifies. These results demonstrate that the proposed CS-ELAN module and EPAN effectively enhance feature representation for small targets in complex backgrounds, and the optimized loss function improves localization precision.

5. Conclusion

In this work, I proposed YOLOv7-EPAN, an improved detection framework specifically designed for infrared defect detection of solar panels in complex aerial scenes. By integrating CSWin Transformer into the ELAN module to form CS-ELAN, the model captures global contextual information and suppresses background noise. The EPAN neck built with CS-ELAN modules enhances multi-scale feature fusion. The hybrid regression loss combining NWD and CIoU improves localization accuracy for small defects. Extensive experiments on a real-world dataset show that my method achieves 81.5% mAP50, outperforming the baseline YOLOv7 by 6.4% and surpassing several state-of-the-art detectors. The model maintains a practical inference speed of 83 f/s with reduced parameter count. This work provides an effective solution for intelligent inspection of solar panels, reducing missed detections of tiny defects and contributing to the safe operation of photovoltaic plants. Future work could explore lightweight versions for edge deployment and extend the method to other types of solar panel anomalies.

Scroll to Top