Defect Detection of Solar Panels Using YOLO-Based Methods

Solar energy is widely recognized as one of the most promising renewable energy sources due to its abundance and environmental friendliness. Solar panels, as the core components of photovoltaic systems, directly determine the efficiency and stability of power generation. Any surface defects such as scratches, cracks, hot spots, black edges, or disconnection can significantly degrade the performance of solar panels, leading to reduced power output and shortened service life. Therefore, developing accurate and efficient defect detection methods for solar panels is of great practical importance.

Traditional manual inspection methods are time-consuming, subjective, and prone to errors, especially for subtle defects. With the rapid advancement of deep learning, convolutional neural networks have revolutionized the field of industrial defect detection. Among various deep learning models, the YOLO family has become a dominant approach for real-time object detection tasks due to its excellent balance between speed and accuracy. In this work, I present two optimized YOLO-based algorithms specifically designed for solar panel defect detection: a lightweight model named LPV-YOLO and an attention-enhanced model named PVA-YOLO. These methods aim to overcome the challenges of limited computational resources and the difficulty of detecting small-scale defects.

An example of a solar panel is shown below.

1. Background and Motivation

The global push for carbon neutrality has accelerated the deployment of large-scale photovoltaic power stations. To ensure the long-term reliability of solar panels, automated optical inspection systems are urgently needed. Surface defects on solar panels can be categorized into several typical types: breakage, scratches, hot spots, black edges, and disconnection. These defects often have significant variations in shape, size, and contrast. Some are very narrow and elongated, while others are large and irregular. The diversity of defects makes detection a challenging task.

Classic image processing techniques rely on manually designed features such as texture, color, and shape. Although these methods achieve reasonable results under controlled conditions, they are not robust to changes in lighting and background. In contrast, deep learning methods automatically learn hierarchical feature representations from data, offering superior generalization and accuracy. However, deploying deep networks in industrial environments requires a trade-off between detection performance and computational efficiency. Many existing detectors are too heavy for real-time processing on embedded devices. Therefore, my first approach focuses on building a lightweight network using the YOLOv5 architecture.

Another critical challenge is that small defects, such as thin scratches, are often missed by conventional detectors. To address this issue, my second approach improves the YOLOv9 architecture by integrating advanced feature extraction modules and attention mechanisms, which can capture fine-grained details more effectively.

2. Dataset and Preprocessing

The experiments in this study are based on a solar panel multi-defect dataset containing images of size 600×600 pixels. The dataset originally contains 1,107 images and 4,235 annotated defect instances. After examining the dataset, I found that some labels were incomplete or inaccurate. To improve the quality of the dataset, I used the LabelImg tool to re-annotate all images. The re-annotation process increased the number of labels to 4,631.

To alleviate the class imbalance and improve the model’s robustness, I employed Cycle-GAN for data augmentation. Cycle-GAN is an unpaired image-to-image translation network that can synthesize new defect images while preserving the content of the original images. The architecture includes two generators and two discriminators, trained with a cycle consistency loss. The total loss is defined as:

$$Loss = Loss_{GAN} + \lambda Loss_{cycle}$$

where \(Loss_{GAN}\) ensures the generated images are visually similar to the target domain, and \(Loss_{cycle}\) guarantees that the translation is reversible. The cycle consistency loss is expressed as:

$$Loss_{cycle} = \mathbb{E}_{x \sim P_{data}(x)} \| F(G(x)) – x \|_1 + \mathbb{E}_{y \sim P_{data}(y)} \| G(F(y)) – y \|_1$$

After augmentation, the dataset was expanded to 4,463 images with 14,444 defect instances. The augmented dataset was split into training and validation sets using an 8:2 ratio. The validation set was exclusively composed of original images to ensure an unbiased evaluation.

3. Lightweight Detection Method: LPV-YOLO

3.1 Overview

The first proposed method, named LPV-YOLO, is built upon the YOLOv5s baseline. The goal is to dramatically reduce the number of parameters and computational cost while maintaining high detection accuracy. The network structure consists of four parts: input, backbone, neck, and detection head. Three major improvements are introduced:

  • A lightweight GhostMConv module and a C3MGhost module are designed to replace the standard convolutional layers and C3 modules in the backbone and neck.
  • An improved spatial pyramid pooling module (MSSPPF) is developed by integrating the SimAM attention mechanism with Mish activation.
  • A Squeeze-and-Excitation (SE) attention block is embedded into the neck network to enhance channel-wise feature recalibration.

3.2 Lightweight Convolutional Modules

The Ghost module generates redundant feature maps using cheap linear operations instead of expensive convolutions. It first applies a small number of standard convolutions to produce intrinsic feature maps, and then performs a series of linear transformations to generate additional ghost feature maps. Given an input feature map with dimension \(c \times h \times w\), a standard convolution kernel of size \(k\), and an output channel size \(n\), the computational cost of a standard convolution is:

$$C_{std} = n \cdot h’ \cdot w’ \cdot c \cdot k \cdot k$$

The Ghost module splits the output channels into two parts: one part is generated by standard convolution with \(n/s\) channels, and the other part is obtained by applying cheap linear operations with average kernel size \(d\) to the first part. The computational cost of the Ghost module is:

$$C_{ghost} = \frac{n}{s} \cdot h’ \cdot w’ \cdot c \cdot k \cdot k + (s-1) \cdot \frac{n}{s} \cdot h’ \cdot w’ \cdot d \cdot d$$

The compression ratio can be approximated as:

$$r = \frac{C_{std}}{C_{ghost}} \approx \frac{s \cdot c}{s + c – 1} \approx s$$

This shows that the computational cost is reduced by approximately a factor of \(s\).

In this work, I replaced the activation function in the Conv module with the Mish activation function, which is defined as:

$$Mish(x) = x \cdot \tanh(\ln(1 + e^{x}))$$

This activation function provides a smooth, non-monotonic function that helps to avoid vanishing gradients and improves generalization. The resulting CBM (Conv-Batch-Mish) module is then combined with the Ghost bottleneck structure to form GhostMConv. Furthermore, I constructed a C3MGhost module by integrating several GhostMConv branches with residual connections. These two modules are used to replace all conventional convolutional layers (except the first one) and C3 modules in YOLOv5s. This change reduces the number of parameters from 7.23M to about 3.71M, a reduction of approximately 49%.

3.3 Improved Spatial Pyramid Pooling with SimAM

The original SPP module uses max-pooling with different kernel sizes and concatenates the results. In YOLOv5, SPPF is a fast version that uses serial pooling with the same kernel size. To further improve feature fusion without increasing parameters, I proposed the MSSPPF module. It first applies Mish activation, then performs multi-scale pooling through serial max-pooling, and finally incorporates the parameter-free attention module SimAM.

SimAM estimates the importance of each neuron by measuring its linear separability from surrounding neurons. The energy function for a target neuron \(t\) is given by:

$$e_t = \frac{4(\sigma^2 + \lambda)}{(t – \mu)^2 + 2\sigma^2 + 2\lambda}$$

Here, \(\mu\) and \(\sigma^2\) are the mean and variance of all neurons in the channel, and \(\lambda\) is a regularization coefficient. A lower energy value indicates that the neuron is more important. The attention weights are computed using a sigmoid function:

$$\tilde{X} = X \cdot \text{sigmoid}\left(\frac{1}{E}\right)$$

where \(E\) is the matrix of all energy values. This module does not add any parameters yet it effectively enhances the feature representation. The MSSPPF module compensates for the accuracy loss caused by the lightweight backbone and improves the detection of small defects.

3.4 Embedding SE Attention in the Neck

The SE attention block adaptively recalibrates channel-wise feature responses by explicitly modeling the interdependencies between channels. The SE module first performs global average pooling to obtain a channel descriptor, then applies two fully connected layers to generate a set of calibration weights, and finally rescales the input feature maps.

Given an input feature map \(U \in \mathbb{R}^{H \times W \times C}\), the channel-wise statistics are calculated as:

$$z_c = \frac{1}{H \times W} \sum_{i=1}^{H} \sum_{j=1}^{W} U_c(i,j)$$

Then the excitation operation is:

$$s = \sigma(W_2 \cdot \delta(W_1 \cdot z))$$

where \(\sigma\) is the sigmoid activation, \(\delta\) is ReLU, and \(W_1, W_2\) are the weights of the two fully connected layers. In LPV-YOLO, I inserted SE after each C3MGhost module in the neck network. This mechanism emphasizes the most informative channels and suppresses irrelevant ones, thereby improving the detection accuracy of subtle defects alongside the lightweight design.

3.5 Experimental Results for LPV-YOLO

All experiments for LPV-YOLO were conducted on a Windows 10 system with an NVIDIA GeForce RTX 2080Ti GPU, Python 3.8, and CUDA 11.1. The input image size was 640×640. The training parameters are listed below:

Table 1: Training parameters for LPV-YOLO
Parameter Value
Optimizer SGD
Epochs 300
Batch size 16
Momentum 0.937
Initial learning rate 0.001
Weight decay 0.0005

To evaluate the model, I used precision, recall, mAP@0.5, mAP@0.5:0.95, parameter count, model size, FLOPs, and FPS. The formulas for precision and recall are:

$$P = \frac{TP}{TP+FP}, \quad R = \frac{TP}{TP+FN}$$

The mean average precision is computed as:

$$mAP = \frac{1}{N} \sum_{i=1}^{N} AP_i$$

where \(AP_i\) is the area under the precision-recall curve for class \(i\).

Table 2 shows the detection performance of LPV-YOLO for each defect type.

Table 2: Detection performance of LPV-YOLO on each defect type
Defect Precision (%) Recall (%) mAP@0.5 (%) mAP@0.5:0.95 (%)
Breakage 88.7 89.7 93.2 65.7
Hot spot 87.6 87.8 92.5 60.3
Black edge 91.1 85.5 97.1 62.7
Scratch 80.1 85.7 87.0 46.4
Disconnection 96.0 96.9 99.1 90.5
All 88.7 91.1 93.8 65.1

Ablation experiments were carried out to verify each improvement. The results are shown in Table 3.

Table 3: Ablation experiments for LPV-YOLO
Model mAP (%) Params (M) Size (MB) FLOPs (G) FPS
YOLOv5s (baseline) 94.4 7.23 13.70 16.5 91.7
+ MGhost 92.1 3.70 7.42 8.2 67.1
+ MGhost + MSSPPF 93.3 3.70 7.36 8.2 65.5
+ MGhost + MSSPPF + SE 93.8 3.71 7.40 8.3 70.4

Compared with the original YOLOv5s, LPV-YOLO reduces the number of parameters by 49%, model size by 46%, and FLOPs by 50%, while only losing 0.6% in mAP. This demonstrates an excellent trade-off between speed and precision, making it suitable for real-time solar panel inspection on resource-constrained devices.

4. Attention-Based Detection Method: PVA-YOLO

4.1 Overview

Although LPV-YOLO achieves notable lightweight performance, the detection of fine defects such as scratches remains challenging. To further boost accuracy, I proposed a second method named PVA-YOLO, which is based on the YOLOv9 architecture. YOLOv9 introduces programmable gradient information (PGI) and a generalized efficient layer aggregation network (GELAN), which improve information flow and reduce information bottlenecks. In this work, I enhanced YOLOv9 from three aspects:

  • Using the k-means++ clustering algorithm to generate anchor boxes that are better matched to the solar panel defect dataset.
  • Designing a new feature extraction module called RepNCSPELAN_TCA by reparameterizing a three-branch convolution and adding coordinate attention.
  • Introducing a parallel attention module (PAM) that combines channel attention and spatial attention to better capture fine details.

4.2 Anchor Box Generation with k-means++

Although YOLOv9 is initially an anchor-free detector, the introduction of prior anchor boxes can still benefit the model by providing better initial guesses for bounding box regression. I applied the k-means++ clustering algorithm to the re-annotated solar panel dataset. The algorithm aims to find \(k\) cluster centers that minimize the Euclidean distance between each label box and its nearest center. The distance function is:

$$D(x) = \min_{c \in C} \|x – c\|^2$$

The probability of selecting a sample x as the next cluster center is proportional to its distance from the already selected centers:

$$P(x) = \frac{D(x)^2}{\sum_{x’ \in X} D(x’)^2}$$

By using this improved initialization strategy, the generated anchor boxes are more stable and representative. The resulting nine anchor sizes for the solar panel dataset are listed in Table 4.

Table 4: Anchor box sizes generated by k-means++
Width 20 21 21 22 50 64 122 123 146
Height 34 62 119 202 44 109 50 171 588

These anchors cover the diverse aspect ratios of solar panel defects, including very thin and elongated objects like scratches and black edges.

4.3 RepNCSPELAN_TCA Module

In YOLOv9, the RepNCSPELAN4 module is used for feature extraction. To enhance its capability for small defects, I restructured the convolution branches and introduced coordinate attention. First, I designed a Three Convolution Branch Reparameter Module (RepConvN_T) that consists of one \(1 \times 1\) convolution and two \(3 \times 3\) convolutions in parallel. In the training stage, these branches are learned independently; at inference time, they are fused into a single convolution through reparameterization, thereby reducing inference cost while preserving the feature richness.

Based on this module, I constructed the RepNBottleneck_T bottleneck and the RepNCSP_T cross-stage partial network. Combining these components with a coordinate attention block resulted in the RepNCSPELAN_TCA module. The coordinate attention mechanism encodes both channel and direction-aware information. Given an input feature tensor, the two attention maps are computed along the horizontal and vertical directions using average pooling. The output of coordinate attention can be expressed as:

$$S = \sigma(Conv([F_h, F_w]))$$

where \(F_h\) and \(F_w\) are the embeddings of horizontal and vertical features, and \(\sigma\) is the sigmoid activation. This module allows the network to capture long-range dependencies while maintaining precise positional information, which is especially useful for detecting elongated scratch defects.

4.4 Parallel Attention Module

To simultaneously enhance channel and spatial features, I proposed the Parallel Attention Module (PAM). This module combines a channel attention branch and a spatial attention branch in parallel. The channel attention branch uses both global average pooling and max pooling to obtain descriptors, then passes them through a shared multi-layer perceptron to generate channel weights. The spatial attention branch applies average pooling and max pooling along the channel dimension, followed by a convolution layer to generate a spatial weight map.

Let \(F\) be the input feature map. The channel attention output is:

$$M_c(F) = \sigma(MLP(AvgPool(F)) + MLP(MaxPool(F)))$$

The spatial attention output is:

$$M_s(F) = \sigma(Conv^{7 \times 7}([AvgPool(F); MaxPool(F)]))$$

In the parallel design, the original input is multiplied by the channel attention and the spatial attention separately, and then the two enhanced features are summed element-wise:

$$F’ = F \odot M_c(F) + F \odot M_s(F)$$

This additive parallel formulation preserves both complementary aspects without overwhelming the original features. PAM improves the model’s ability to focus on discriminative regions, which significantly improves the detection of small and low-contrast solar panel defects.

4.5 Experimental Results for PVA-YOLO

The PVA-YOLO experiments were conducted on an NVIDIA GeForce RTX 4090 GPU with Python 3.8 and CUDA 11.8. The same dataset and evaluation protocol were used. The training parameters are shown in Table 5.

Table 5: Training parameters for PVA-YOLO
Parameter Value
Optimizer SGD
Epochs 300
Batch size 16
Momentum 0.937
Initial learning rate 0.001
Weight decay 0.0005

To demonstrate the effectiveness of each proposed component, I conducted a series of ablation experiments. The results are shown in Table 6. In the table, marker ① denotes the k-means++ anchor boxes, ② denotes the RepNCSPELAN_TCA module, and ③ denotes the PAM attention.

Table 6: Ablation experiments for PVA-YOLO
YOLOv9 ① ② ③ AP breakage AP hot spot AP black edge AP scratch AP disconnection mAP@0.5 mAP@0.5:0.95
√ 95.0 91.0 97.5 87.1 97.8 93.7 68.9
√ √ 96.7 90.0 97.6 89.9 97.5 94.3 72.7
√ √ 97.8 91.4 99.0 91.4 98.8 95.7 70.0
√ √ 97.7 91.6 99.3 90.2 98.8 95.5 74.4
√ √ √ 98.2 91.7 99.4 91.7 98.9 96.0 76.1
√ √ √ 97.7 91.3 99.4 92.0 98.8 95.9 75.5
√ √ √ 98.1 92.7 99.2 92.2 98.9 96.2 76.2
√ √ √ √ 98.5 92.7 99.2 92.2 98.6 96.3 76.5

From the table, it is clear that each improvement contributes positively. The baseline YOLOv9 achieves mAP@0.5 of 93.7%. When all improvements are integrated, PVA-YOLO reaches mAP@0.5 of 96.3%, which is an increase of 2.6%. More impressively, the strict metric mAP@0.5:0.95 improves by 7.6%, from 68.9% to 76.5%. This indicates that the model produces much more precise and confident localization.

In particular, the detection of scratches improves from 87.1% AP to 92.2% AP, showing that the parallel attention and the coordinated anchor boxes greatly help in recognizing extremely thin defects.

4.6 Comparison with Other Models

To further assess the superiority of PVA-YOLO, I compared it with several widely used object detection models on the same dataset. The results are presented in Table 7.

Table 7: Performance comparison of different models
Model Precision (%) Recall (%) F1 (%) mAP@0.5 (%) mAP@0.5:0.95 (%)
YOLOv5 88.6 91.2 90.0 93.8 65.1
YOLOX 81.6 86.5 83.9 80.8 49.8
SSD 75.6 81.8 78.6 77.7 45.4
Faster-RCNN 84.5 82.8 65.2 87.8 60.8
YOLOv9 88.9 89.2 89.0 93.7 68.9
YOLOv7 88.4 90.7 89.5 94.2 66.8
YOLOv8 87.5 84.7 86.1 92.7 65.6
YOLOv10 85.3 83.7 84.5 90.6 53.9
YOLOv11 85.0 84.3 84.6 89.7 52.8
GHB-YOLO 90.2 89.8 90.0 93.2 66.3
PB-YOLO 91.0 93.5 92.2 96.5 73.1
YOLOv5-scSE 92.7 91.3 92.0 96.1 75.4
PVA-YOLO 91.6 93.4 92.5 96.3 76.5

PVA-YOLO outperforms all other compared models on mAP@0.5:0.95, and its mAP@0.5 is only 0.2% lower than PB-YOLO, while the higher strict metric indicates better localization quality. The improvements in precision, recall, and F1 score demonstrate that PVA-YOLO strikes an excellent balance between correctly identifying defects and minimizing false positives.

5. Discussion

Both proposed methods address the specific challenges of solar panel defect detection from different perspectives. LPV-YOLO focuses on model compression, enabling deployment on edge devices with limited computational resources. It reduces the parameter count by nearly half while keeping a real-time speed of 70 FPS. However, its accuracy on scratch defects is only 87% AP, indicating that lightweight architectures may suffer from a decreased ability to capture extremely fine details.

PVA-YOLO, on the other hand, takes the opposite approach by enhancing the representational capacity of the network. The introduction of k-means++ anchors, the restructured feature extraction module, and the parallel attention mechanism collectively improve the detection of small defects. The mAP@0.5:0.95 metric benefits the most, showing a 7.6% relative improvement over the baseline YOLOv9. This is particularly important in industrial applications where precise localization is required for automated repair and sorting.

In terms of long-term usability, both models can be integrated into a complete photovoltaic inspection system. LPV-YOLO can be deployed on camera-equipped edge devices for fast screening, while PVA-YOLO can be used in a central server for high-precision re-inspection. The two-stage hierarchical approach can significantly reduce false negatives and improve overall product quality.

6. Conclusion

In this thesis, I have presented two YOLO-based algorithms for solar panel defect detection. The first algorithm, LPV-YOLO, is a lightweight network that achieves a good balance between speed and accuracy. By replacing standard convolutions with Ghost modules and incorporating attention mechanisms, the model reduces parameters by 49% and FLOPs by 50% while maintaining a high mAP of 93.8% on the solar panel dataset. The second algorithm, PVA-YOLO, is an attention-enhanced network that significantly boosts detection precision. Using k-means++ anchor clustering, a reparameterized feature extraction module, and a parallel attention mechanism, PVA-YOLO improves mAP@0.5 to 96.3% and mAP@0.5:0.95 to 76.5%, confirming its superiority in detecting fine defects.

Future work will explore the deployment of these models on dedicated hardware such as FPGA or Jetson devices. I also intend to investigate semi-supervised and self-supervised learning methods to reduce the dependency on large annotated datasets. Furthermore, incorporating temporal information from video streams could improve the robustness of defect detection under varying illumination conditions. Ultimately, these advances will contribute to the continuous improvement of photovoltaic quality control and the global transition to clean energy.

Scroll to Top