An Improved YOLOv5-RCD Framework for Solar Panels Defect Detection

In the rapidly expanding domain of photovoltaic energy, the reliable operation of solar panels is paramount to ensuring consistent power generation and economic viability. However, solar panels deployed in challenging environments, such as highway service areas, are susceptible to various defects including micro-cracks, hotspots, stains, and breakage. These defects not only degrade energy conversion efficiency but also pose safety risks. Traditional manual inspection methods are labor-intensive, time-consuming, and often miss small or subtle anomalies, especially in large-scale installations. With the advent of deep learning, object detection algorithms have become a cornerstone for automated solar panels inspection. Yet, existing models frequently struggle with the detection of small defects against complex backgrounds, and they often demand substantial computational resources unsuitable for real-time deployment on edge devices like drones. In this work, I present an enhanced detection algorithm named YOLOv5-RCD, designed specifically to address these challenges by integrating dynamic feature enhancement, multi-scale fusion, and lightweight architecture. The proposed method achieves significant improvements in both accuracy and efficiency for solar panels defect detection.

The primary contributions of this study are fourfold. First, I embed a combined channel-spatial attention mechanism into the backbone network to dynamically enhance defect feature responses while suppressing background noise. Second, I replace the conventional Feature Pyramid Network (FPN) with a dynamically weighted Bidirectional Feature Pyramid Network (BiFPN) to enable adaptive multi-scale feature fusion, thereby improving the detection of small-sized defects on solar panels. Third, I introduce a four-scale detection head and a dual-threshold Non-Maximum Suppression (NMS) strategy to further refine tiny defect localization. Fourth, I adopt a lightweight module design and mixed-precision quantization to reduce model parameters and inference latency, making the system suitable for real-time operation on resource-constrained platforms. Extensive experiments on a self-collected dataset of 1,000 solar panels images from a highway service area demonstrate that YOLOv5-RCD outperforms the baseline YOLOv5s by 4.3 percentage points in mean Average Precision (mAP) while reducing parameter count by 32%, achieving a good balance between accuracy and deployment efficiency.

Let us first consider the inherent difficulties in solar panels defect detection. As shown in the image below, solar panels often present a uniform surface with subtle variations, making it challenging to distinguish minor defects from normal texture or lighting artifacts.

The figure above illustrates a typical solar panel in a real-world environment. The reflective nature of the glass surface and the presence of dirt, shadows, and electrical busbars create a cluttered background that masks defects. This visual complexity underscores the need for robust feature extraction and adaptive attention mechanisms.

1. Methodology

1.1 Dataset Construction and Augmentation

To facilitate the study, I collected 1,000 RGB images of solar panels from a highway service area in China, each with a resolution of 1,024×1,024 pixels. The dataset covers diverse lighting conditions (sunny, overcast, dawn/dusk) and four defect categories: cracks, breakage, stains, and hidden cracks. Annotations were performed using LabelImg, and the dataset was split into training (800 images), validation (100), and test (100) sets. To enhance generalization, I applied a comprehensive data augmentation pipeline: random rotation (±15°), horizontal/vertical flipping, scaling (0.8–1.5), color jitter (brightness ±0.2, contrast adjustment), Gaussian noise addition, and a small-target enhancement technique that locally amplifies regions containing tiny defects. These augmentations simulate the variability encountered in real drone-based inspections of solar panels.

1.2 Backbone Lightweighting and Multi-Scale Feature Enhancement

The original YOLOv5s backbone (CSPDarknet53) is computationally intensive. I replace the C3 modules with Residual C3 (RC3) modules that employ depthwise separable convolutions to reduce parameters while preserving residual learning. The RC3 operation is defined as:

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

where \(F_{\text{in}}\) and \(F_{\text{out}}\) are input and output feature maps, \(\text{Conv}^{C}_{1\times1}\) denotes a 1×1 convolution with \(C\) output channels, and \(\oplus\) denotes element-wise addition. This design reduces parameters by about 32% compared to the original C3.

To capture defects at multiple scales, I embed dilated convolution branches into the P3, P4, and P5 feature layers. The dilation rates are set to 2, 4, and 6 respectively, expanding receptive fields without increasing parameter count. This is particularly beneficial for detecting elongated defects like micro-cracks and broken grid lines on solar panels. Table I summarizes the configuration of the enhanced backbone.

Table I: Configuration of the multi-scale dilated convolution branches in the backbone
Feature Layer Dilation Rate Receptive Field Gain Target Defect Scale
P3 2 Moderate Small cracks (width ~1-2 pixels)
P4 4 Large Medium stains (10-20 pixels)
P5 6 Very large Large breakage (>30 pixels)

1.3 Dynamic BiFPN and Context-Aware Module

I integrate a dynamically weighted BiFPN into the neck network. Unlike traditional FPN that uses fixed additive fusion, BiFPN assigns learnable weights to each cross-scale connection, allowing the network to emphasize features that are most informative for detecting solar panels defects. The fusion operation at a node 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 \(\phi_1\) and \(\phi_2\) are learnable weight parameters, and \(U\) denotes upsampling. After each fusion node, a Contextual Attention Module (CAM) is appended. CAM performs global average pooling to extract global context, then applies channel attention:

$$M_c = \sigma\big(W_1 \delta(W_2 G)\big)$$

where \(G\) is the global average pooled vector, \(\delta\) is ReLU, \(\sigma\) is Sigmoid, and \(W_1, W_2\) are fully-connected layers. The final output \(F’_{\text{out}} = F \odot M_c + F\) enriches local features with global semantic information, especially important for distinguishing defects from background clutter on solar panels.

1.4 Four-Scale Detection Head and Anchors

To improve the detection of tiny defects, I extend the original three-scale detection head (P3–P5) with an additional high-resolution P2 head. The feature pyramid now includes \(\{C2, C3, C4, C5\}\) from the backbone with resolutions 112×112, 56×56, 28×28, 14×14 respectively. The P2 head is constructed by:

$$P_2 = \text{Conv}_{3\times3}\big(\text{Concat}[U(P_3), \text{Conv}_{1\times1}(C_2)]\big)$$

The set of anchor boxes is updated to include smaller sizes for P2. The new anchor matrix is:

$$A = \begin{bmatrix} 3.2 & 4.1 \\ 5.8 & 7.2 \\ 9.3 & 11.6 \\ 15.4 & 19.8 \end{bmatrix} \cup \begin{bmatrix} 1.7 & 2.4 \\ 2.9 & 3.7 \end{bmatrix}_{P2}$$

where the additional anchors in the P2 row cover extremely small defect scales (down to 1.7×2.4 pixels), enabling the model to capture tiny cracks and stains on solar panels that are frequently missed by standard detectors.

1.5 Loss Function and Post-Processing

I adopt a geometry-aware dynamic IoU loss (WoU) which adds a penalty for aspect ratio mismatch and adaptively weights the centroid distance. The loss for an anchor box \(B=(x,y,w,h)\) and ground truth \(B^{gt}\) is:

$$L_{\text{WoU}} = 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(\cdot)\) is Euclidean distance between centers, \(c\) is diagonal of smallest enclosing box, \(\Delta w = |w – w^{gt}|\), \(\Delta h = |h – h^{gt}|\), and \(\alpha, \beta\) are adaptive weights based on anchor quality.

For post-processing, I propose a confidence-aware dual-threshold NMS. Detection boxes are first split into high-confidence (\(s > 0.8\)) and medium-confidence (\(0.5 \le s \le 0.8\)) sets. High-confidence boxes undergo standard NMS with IoU threshold 0.4; medium-confidence boxes are processed using Gaussian Soft-NMS with decay factor \(\sigma = 0.5\):

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

Boxes with final confidence below 0.5 are suppressed. This strategy reduces false positives while preserving genuine medium-confidence detections of ambiguous defects on solar panels.

2. Experiments and Results

2.1 Implementation Details

All experiments are conducted on a workstation with Intel i5-13900K CPU, NVIDIA RTX 4060 GPU (16 GiB RAM). Software includes PyTorch 1.9.0, CUDA 11.2, Python 3.9. The model is trained for 100 epochs with batch size 16, early stopping patience 15, and weight decay 0.0005. Input images are resized to 640×640 to balance speed and accuracy. Mixed-precision training (FP16) is used to accelerate training and inference.

2.2 Comparison Algorithms and Metrics

I compare YOLOv5-RCD against several baselines: YOLOv5s (single-stage benchmark), Faster R-CNN (two-stage classic), YOLOv8m, YOLOv11m, and three recent custom methods (LIU et al., LW-PV, GBS-YOLOv5). The evaluation metrics include:

  • mAP@0.5:0.95 – mean Average Precision over IoU thresholds from 0.5 to 0.95 (step 0.05).
  • Small-target recall – Recall defined for objects with area < 32×32 pixels.
  • Parameter count (in millions).
  • Inference speed (FPS) on the test set.

Table II presents the quantitative comparison results.

Table II: Performance comparison of different detection models for solar panels defect detection
Model mAP@0.5:0.95 (%) Small-target Recall (%) Parameters (M) FPS (frames/s)
YOLOv5s (baseline) 83.1 75.2 7.20 62
Faster R-CNN 86.1 68.4 42.60 28
YOLOv5-RCD (ours) 87.4 89.7 5.00 73
YOLOv8m 86.7 79.5 25.90 48
YOLOv11m 87.2 80.3 21.00 55
LIU et al. 85.7 12.60 45
LW-PV 84.2 81.1 17.52
GBS-YOLOv5 87.8 82.6 4.85 59

From Table II, it is evident that YOLOv5-RCD achieves the highest small-target recall of 89.7%, which is 14.5 percentage points higher than the baseline YOLOv5s. The mAP reaches 87.4%, outperforming YOLOv5s by 4.3% and surpassing most competing methods. Notably, YOLOv5-RCD maintains the smallest parameter count (5.00 M) among all compared models except GBS-YOLOv5 (4.85 M), while still delivering superior speed (73 FPS). This validates the effectiveness of the lightweight design and multi-scale attention for solar panels defect detection.

2.3 Ablation Study

To isolate the contribution of each component, I conduct an ablation study where individual modules are removed from the full YOLOv5-RCD. The results are summarized in Table III.

Table III: Ablation study on the proposed modules for solar panels defect detection
Configuration mAP@0.5:0.95 (%) Small-target Recall (%) Parameters (M)
Baseline (YOLOv5s) 83.1 75.2 7.20
+ RC3 + dilated conv (backbone) 85.3 79.8 5.64
+ Dynamic BiFPN + CAM 86.4 83.1 5.48
+ 4-scale head + dual NMS 87.1 87.5 5.12
Full YOLOv5-RCD 87.4 89.7 5.00

Each modification yields incremental gains. The backbone lightweighting (RC3+dilated conv) alone improves mAP by 2.2% while reducing parameters by 21.7%. Adding BiFPN and CAM boosts small-target recall by 3.3%. The four-scale head and dual NMS contribute the largest gain in small-target recall (+4.4%). The full model shows that all components work synergistically to produce the best performance on solar panels defects.

2.4 Visual Analysis

Qualitative comparisons between YOLOv5s and YOLOv5-RCD on representative test images further illustrate the improvement. The baseline model often misses small stains and cracks, especially under low-contrast conditions. In contrast, YOLOv5-RCD accurately detects these defects with higher confidence and fewer false positives. For example, in an image with multiple overlapping defect types, the enhanced model correctly identifies all instances while the baseline misses two out of five cracks. The improvement is particularly pronounced for tiny defects that occupy less than 1% of the image area, confirming the effectiveness of the P2 detection head and attention mechanisms for solar panels inspection.

3. Discussion

The results demonstrate that YOLOv5-RCD effectively addresses the unique challenges of solar panels defect detection in highway service areas. The combination of channel-spatial attention and dynamic BiFPN allows the network to focus on defect-relevant regions despite severe background interference from wires, dust, and reflections. The lightweight backbone (5.00 M parameters) and mixed-precision inference enable real-time processing at 73 FPS on a modest GPU, making it feasible for deployment on drones or edge devices. The small-target recall of 89.7% is a critical achievement, as micro-cracks and early-stage stains are often the precursors to larger failures; early detection can prevent costly downtime.

One limitation of the current study is that the dataset primarily contains images from a single geographic region with specific panel types. The generalizability to other panel textures, aging levels, and climate conditions should be further validated. Additionally, while the model handles most defect categories well, the performance on hidden cracks (very fine sub-surface fractures) remains slightly lower than for visible stains. Future work could incorporate infrared or electroluminescence imaging to enhance detection of such defects. Furthermore, exploring knowledge distillation or neural architecture search may yield even more compact models suitable for ultra-low-power hardware.

4. Conclusion

In this work, I developed an improved YOLOv5-RCD algorithm for solar panels defect detection in complex environments such as highway service areas. By embedding SE channel and spatial attention into the backbone, integrating a dynamically weighted BiFPN with a contextual attention module, extending to a four-scale detection head, and employing a dual-threshold NMS strategy, the proposed model significantly enhances detection accuracy and efficiency. Experimental results show that YOLOv5-RCD achieves an mAP of 87.4%, small-target recall of 89.7%, and a parameter count of only 5.00 M, outperforming the baseline YOLOv5s and several state-of-the-art methods. The model runs at 73 FPS on a standard GPU, meeting real-time requirements. This study provides a practical solution for automated inspection of solar panels, contributing to the reliable operation of photovoltaic systems in transportation infrastructure.

Scroll to Top