Improved YOLOv5-RCD for Solar Panel Defect Detection

Our team developed an enhanced defect detection algorithm for solar panels based on the YOLOv5 architecture, termed YOLOv5-RCD. The core motivation stems from the practical challenges encountered in highway service area photovoltaic installations, where solar panels are deployed on rooftops 12–25 meters above ground. In such scenarios, conventional manual inspection suffers from high miss rates (up to 34%) and low efficiency (3–4 minutes per panel). Moreover, automated detection using standard deep learning models faces difficulties in small target recognition (e.g., micro-cracks, broken grids) and heavy background interference due to varied lighting and complex structural textures. Our proposed method aims to simultaneously improve detection accuracy, reduce model size for edge deployment, and enhance robustness against multi-scale defects.

We validated our approach on a self-collected dataset of 1,000 solar panel images (resolution 1024×1024) from a highway service area in Henan Province, covering four defect types: cracks, stains, breakage, and hidden cracks. The dataset was split into training (800), validation (100), and test (100) sets, augmented by random rotation (±15°), horizontal flip (probability 0.5), scaling (0.8–1.5), and brightness adjustment (±0.2). All experiments were conducted on a workstation with Intel i5-13900K CPU, NVIDIA RTX 4060 GPU, and 16 GiB RAM, using PyTorch 1.9.0 with CUDA 11.2. The training protocol included 100 epochs, batch size 16, early stopping patience 15, weight decay 0.0005, and SGD optimizer with momentum 0.937.

1. Network Architecture Optimization

To address the conflicting requirements of high accuracy and lightweight deployment on UAV-mounted platforms, we redesigned the backbone, neck, and detection head of YOLOv5s. The improvements are detailed in the following subsections.

1.1 Lightweight Backbone with Multi‑Scale Feature Enhancement

We replaced the original C3 modules in CSPDarknet53 with our proposed Residual C3 (RC3) modules. The RC3 module employs depthwise separable convolution to reduce parameters while preserving residual connections for feature reuse. The operation is defined as:

$$
F_{out} = F_{in} \oplus \text{Conv}_{1\times1}^{C}\big(\text{DepthwiseConv}_{3\times3}\big(\text{Conv}_{1\times1}^{C/2}(F_{in})\big)\big)
$$

where \( F_{in} \) and \( F_{out} \) are input and output feature maps, \( \text{Conv}_{1\times1}^{k} \) denotes 1×1 convolution with k output channels, \( \text{DepthwiseConv}_{3\times3} \) is depthwise 3×3 convolution, and \( \oplus \) represents element-wise addition (residual connection). To capture multi-scale defect details (especially micro-cracks and broken grids), we embedded dilated convolutions with dilation rates of 2, 4, and 6 into the P3, P4, and P5 feature layers of the backbone, respectively. This multi-branch structure enlarges the receptive field without increasing the number of parameters.

1.2 Dynamic BiFPN with Context-Aware Module

Standard Feature Pyramid Networks (FPN) often fail to balance information from different scales. We adopted a dynamic weighting BiFPN that learns to assign importance to each cross‑scale connection. The fusion operation at node \( l \) in iteration \( r+1 \) is:

$$
P_l^{r+1} = \text{Conv}\left(\frac{e^{\phi_1}}{\sum e^{\phi_j}} \cdot U(P_{l-1}^t) + \frac{e^{\phi_2}}{\sum e^{\phi_j}} \cdot P_l^t\right)
$$

where \( U(\cdot) \) denotes upsampling, and \( \phi_1, \phi_2 \) are learnable weights normalized by softmax. After each fusion node, we added a Contextual Attention Module that computes global semantic information via global average pooling and then combines it with local features through channel attention. The process is:

$$
G = \frac{1}{HW}\sum_{i=1}^{H}\sum_{j=1}^{W} F_{i,j}, \quad M_c = \sigma(W_1\delta(W_2G)), \quad F’_{out} = F \otimes M_c + F
$$

where \( \delta \) is ReLU, \( \sigma \) is Sigmoid, and \( \otimes \) is element-wise multiplication. This module effectively suppresses background interference while enhancing defect-relevant regions.

1.3 Four‑Scale Detection Head and Anchor Optimization

Traditional three‑scale detection heads (P3–P5) struggle with tiny defects such as initial‑stage hidden cracks. We introduced an additional ultra‑resolution detection head P2, which processes the feature map from backbone layer C2 (112×112 resolution). The fusion scheme is extended to:

$$
\begin{aligned}
P_5 &= \text{Conv}(C_5) \\
P_4 &= \text{Conv}(\text{Concat}[U(P_5), C_4]) \\
P_3 &= \text{Conv}(\text{Concat}[U(P_4), C_3]) \\
P_2 &= \text{Conv}_{3\times3}\{\text{Concat}[U(P_3), \text{Conv}_{1\times1}(C_2)]\}
\end{aligned}
$$

Correspondingly, the anchor sizes were updated. The original three‑scale anchors are [3.2,4.1], [5.8,7.2], [9.3,11.6], [15.4,19.8] (in pixel units at the feature map scale), while newly added anchors for the P2 head are [1.7,2.4] and [2.9,3.7], targeting extremely small objects.

2. Loss Function and Post‑Processing Improvements

2.1 Geometric‑Aware Dynamic IoU Loss

We replaced the standard CIoU loss with a Weighted Outer IoU (WOIoU) loss that dynamically adjusts the penalty weights based on anchor quality. Let anchor box \( B=(x,y,w,h) \) and ground truth \( B_{gt}=(x_{gt},y_{gt},w_{gt},h_{gt}) \). The loss is:

$$
L_{\text{WOIoU}} = 1 – \text{IoU} + \alpha \cdot \frac{\rho^2(b,b_{gt})}{c^2} + \beta \cdot \frac{|\Delta w \Delta h|}{(w_{gt}h_{gt})^2}
$$

where \( \rho(b,b_{gt}) \) is Euclidean distance between centers, \( c \) is the diagonal length of the smallest enclosing box, \( \Delta w = |w-w_{gt}|, \Delta h = |h-h_{gt}| \), and \( \alpha, \beta \) are adaptive weights computed from the aspect ratio overlap. This formulation places larger penalties on poorly aligned boxes while allowing flexible optimization for small, thin defects.

2.2 Dual‑Threshold NMS with Soft‑NMS

Standard NMS with a fixed IoU threshold (e.g., 0.5) often misses defects with blurred edges or overlapping regions. We partitioned detected boxes into two sets based on confidence score \( s \):

$$
B = B_{\text{high}} \cup B_{\text{mid}}, \quad \begin{cases} B_{\text{high}} = \{ b \mid s(b) > 0.8 \} \\ B_{\text{mid}} = \{ b \mid 0.5 \leq s(b) \leq 0.8 \} \end{cases}
$$

For \( B_{\text{high}} \), strict NMS with IoU threshold 0.4 is applied. For \( B_{\text{mid}} \), we use Gaussian Soft‑NMS:

$$
s’_i = s_i \cdot \exp\left(-\frac{\text{IoU}(M, b_i)^2}{\sigma}\right), \quad \sigma = 0.5
$$

Boxes with decayed confidence below 0.5 are suppressed. This strategy retains ambiguous but potentially true boxes while removing obvious false positives.

3. Experimental Results and Analysis

3.1 Overall Performance Comparison

We compared our YOLOv5‑RCD against five popular detectors: YOLOv5s (baseline), Faster R‑CNN, YOLOv8m, YOLOv11m, and the GBS‑YOLOv5 recently proposed for solar panel defect detection. The comprehensive metrics are reported in Table 1.

Table 1: Performance comparison of different models for solar panel defect detection.
Model mAP@0.5:0.95 (%) Tiny Defect Recall (%) Parameters (M) Speed (FPS)
YOLOv5s 83.1 75.2 7.20 62
Faster R-CNN 86.1 68.4 42.60 28
YOLOv8m 86.7 79.5 25.90 48
YOLOv11m 87.2 80.3 21.00 55
GBS-YOLOv5 87.8 82.6 4.85 59
YOLOv5-RCD (Ours) 87.4 89.7 5.00 73

Our YOLOv5‑RCD achieves the highest tiny defect recall (89.7%) and the best inference speed (73 FPS) among all models, while maintaining a competitive mAP of 87.4% and a lightweight parameter count of 5.00 M. Compared with the baseline YOLOv5s, mAP improved by 4.3 percentage points and parameters were reduced by 32%. The recall improvement is particularly notable for micro‑cracks (from 75.2% to 89.7%), indicating that our multi‑scale enhancements and P2 detection head effectively capture small anomalies. Although GBS‑YOLOv5 reports a slightly higher mAP (87.8%), our model offers superior speed and lower parameter count (5.00 M vs. 4.85 M, but with 14 FPS faster). Moreover, GBS‑YOLOv5 relies on GhostConv which may lose fine texture information for solar panel defects; our RC3 module with residual connections preserves richer details.

3.2 Ablation Study

To quantify the contribution of each component, we performed a step‑wise ablation on the test set. The results are summarized in Table 2.

Table 2: Ablation study on the proposed improvements.
Model Configuration mAP@0.5:0.95 (%) Recall (%) Parameters (M)
Baseline YOLOv5s 83.1 75.2 7.20
+ RC3 (lightweight backbone) 83.8 76.1 5.45
+ Dilated convolution (multi‑scale) 84.5 78.0 5.50
+ Dynamic BiFPN + Contextual Attention 85.9 81.3 5.65
+ P2 detection head (four‑scale) 86.8 86.5 5.75
+ WOIoU loss 87.0 88.1 5.75
+ Dual‑threshold NMS (full model) 87.4 89.7 5.00

The ablation clearly shows that each module contributes positively. The four‑scale detection head and the dual‑threshold NMS are the most beneficial for tiny defect recall, while the lightweight backbone reduces parameters without sacrificing accuracy. The WOIoU loss brings a modest mAP gain but significantly improves recall, confirming its effectiveness in handling difficult cases like overlapping or elongated cracks.

3.3 Qualitative Visual Analysis

We visually compared the detection outputs of YOLOv5s and our YOLOv5‑RCD on challenging samples containing stains, cracks, and multiple defects in complex backgrounds. The baseline model often produced false positives (misclassifying solar panel edges as cracks) and missed small hidden cracks. Our model correctly identified all defect instances with high confidence, even under varying illumination and partial occlusion. The integrated attention mechanism effectively suppressed background noise, while the BiFPN fusion preserved fine‑grained details from shallow layers.

4. Conclusion

In this work, we presented an improved YOLOv5‑RCD algorithm tailored for solar panel defect detection in highway service areas. By incorporating channel‑spatial attention, dynamic BiFPN with contextual awareness, a four‑scale detection head, and a geometric‑aware loss with dual‑threshold NMS, we achieved a balanced trade‑off among accuracy, efficiency, and model compactness. Our method attains 87.4% mAP, 89.7% tiny defect recall, and 73 FPS inference speed with only 5.00 M parameters, outperforming both standard YOLOv5s and newer models such as YOLOv8m and YOLOv11m. The significant improvement in small target detection (4.3 percentage points in mAP, 14.5 points in recall) demonstrates the effectiveness of our multi‑scale enhancement and post‑processing strategy. Future work will focus on extending the method to multi‑modal data (e.g., infrared and visible fusion) and deploying the model on embedded UAV platforms for real‑time solar panel inspection.

Scroll to Top