Defect Detection in Solar Panels via Deep Learning

In recent years, with the continuous advancement of global energy transformation, the photovoltaic industry has experienced unprecedented growth. Solar panels, as core devices for converting solar energy into electricity, have been widely applied across various sectors. However, surface defects on solar panels can significantly reduce power generation efficiency and pose serious threats to system operational reliability. Consequently, surface defect detection for solar panels has become critically important in both manufacturing quality control and operational maintenance. Despite the availability of various inspection methods, traditional approaches relying on manual visual inspection remain prevalent, which inherently suffer from low efficiency, subjective judgment, and high labor costs. To address these challenges, this research focuses on developing deep learning-based defect detection methods for solar panels, aiming to improve detection accuracy and efficiency simultaneously.

Deep learning, particularly convolutional neural networks (CNNs), has demonstrated remarkable success in various computer vision tasks, including object detection, image classification, and semantic segmentation. When applied to defect detection of solar panels, deep learning models can automatically learn hierarchical features from raw images, eliminating the need for manually designed feature extractors. This capability is particularly advantageous for detecting diverse defect types, such as cracks, scratches, black borders, electrical failures, and hot spots on solar panels. In this research, I systematically investigate and improve the YOLOv5 architecture for solar panel defect detection, addressing challenges like small object miss detection, complex background interference, and computational efficiency limitations.

Deep Learning Fundamentals for Solar Panel Inspection

Basic Principles of Neural Networks and Convolutional Neural Networks

The perceptron, proposed by Frank Rosenblatt in 1957, serves as the fundamental building block of neural networks. In a neural network, information transmission resembles biological cellular processes. The neuron model receives multiple inputs, each weighted according to its importance, and an activation function enhances the network’s representation and learning capabilities. The mathematical expression for signal transmission can be formulated as:

$$Z = F\left(\sum_{i=1}^{n} w_i x_i + b\right)$$

where \(x_i\) represents the neuron input, \(w_i\) denotes the corresponding weight, \(b\) is the bias term, and \(F\) represents the activation function. Convolutional neural networks (CNNs) are deep feedforward neural networks with local connections and weight sharing, first proposed by Yann Lecun in 1995. CNNs typically consist of input layers, convolutional layers, pooling layers, fully connected layers, and output layers. The convolutional operation applies filters to input data, with the convolution kernel sliding across the input matrix and computing element-wise multiplications followed by summation, thereby extracting localized features from the input data. Pooling layers perform downsampling operations to reduce spatial dimensions and computational load while preserving essential features. Two common pooling operations are max pooling, which retains the most prominent features within each receptive field, and average pooling, which performs low-pass filtering to preserve regional mean information.

Activation layers introduce nonlinearity into the network, enabling deep networks to learn complex patterns. Several activation functions are commonly employed in defect detection models for solar panels:

Sigmoid function:

$$\sigma(x) = \frac{1}{1 + e^{-x}}$$

Tanh function:

$$\tanh(x) = \frac{2}{1 + e^{-2x}} – 1$$

ReLU function:

$$\text{ReLU}(x) = \max(0, x)$$

Swish function:

$$\text{Swish}(x) = x \cdot \sigma(x)$$

These activation functions play crucial roles in determining the network’s ability to capture complex features from solar panel surface images, with ReLU being particularly popular for its simplicity and fast convergence properties.

Deep Learning-Based Object Detection Algorithms

Modern object detection algorithms can be broadly categorized into two-stage detectors and one-stage detectors. Two-stage detectors, such as the R-CNN family, initially generate candidate regions and then perform classification and bounding box regression on these regions. Faster R-CNN integrates region proposal generation with object detection, achieving end-to-end training through a region proposal network (RPN). However, these methods are computationally expensive and often result in slower inference speeds.

In contrast, one-stage detectors such as SSD and the YOLO family directly predict object categories and bounding box coordinates in a single pass, offering significantly faster detection speeds. YOLOv1 divided the input image into an \(7 \times 7\) grid, where each cell predicts bounding boxes and class probabilities. YOLOv2 introduced DarkNet-19 and anchor boxes to improve performance. YOLOv3 contributed multi-scale detection and residual connections. YOLOv5 further enhanced the architecture through CSPNet backbone, PANet neck, and various training strategies.

YOLOv5 is particularly notable for its balanced performance in both accuracy and efficiency, making it a suitable baseline for solar panel defect detection tasks. The network structure of YOLOv5 can be decomposed into four main components: the input end, backbone network, neck network, and detection head. The input module applies image normalization, scaling, and various data augmentation techniques. The backbone extracts features through a CSPNet architecture, composed of multiple CSP modules stacked to learn hierarchical features at different levels. The neck network follows a combination of Feature Pyramid Network (FPN) and Path Aggregation Network (PAN) to fuse features at different scales. The detection head uses anchor boxes at three different scales to predict object locations and classifications, followed by non-maximum suppression (NMS) to remove overlapping detections.

The loss function of YOLOv5 consists of three components: classification loss, confidence loss, and bounding box regression loss. The classification loss and confidence loss both employ binary cross-entropy, which are expressed as:

$$L_{\text{cls}} = -\sum_{i \in \text{Pos}} \sum_{j \in \text{cla}} \left[\hat{O}_{ij} \ln(O_{ij}) + (1 – \hat{O}_{ij}) \ln(1 – O_{ij})\right]$$

$$L_{\text{obj}} = -\sum_{i} \left[\hat{C}_i \ln(C_i) + (1 – \hat{C}_i) \ln(1 – C_i)\right]$$

For bounding box regression, YOLOv5 uses the GIoU loss function, which improves upon standard IoU by considering the distance and shape information between predicted and ground-truth boxes:

$$L_{\text{GIoU}} = \text{IoU} – \frac{A_C – A_U}{A_C}$$

where \(A_C\) represents the area of the smallest enclosing rectangle of the two bounding boxes, and \(A_U\) denotes the area of their union. This formulation helps the model optimize bounding box localization more accurately, particularly in scenarios with low overlap or non-overlapping boxes, which frequently occur when detecting small defects on solar panels.

Improved Detection Algorithm for Solar Panel Defects with Attention and Feature Fusion

Although the original YOLOv5 provides reasonable detection capability, it encounters challenges when applied to solar panel defect detection. These challenges stem from the complex background interferences, the variety of defect sizes and shapes, and the presence of small-scale defects that are often missed. In this chapter, I propose enhancements to the YOLOv5 algorithm by incorporating attention mechanisms and improved feature fusion networks, aiming to boost detection performance for solar panel surface defects.

Attention Mechanisms

Attention mechanisms allow neural networks to focus on important regions and features within input images, filtering out irrelevant information and enhancing the representation of meaningful content. I explore two attention mechanisms: Convolutional Block Attention Module (CBAM) and Coordinate Attention (CA).

CBAM Attention Mechanism operates through two sequential parts: a channel attention module and a spatial attention module. The channel attention module generates a channel attention map by combining average-pooled and max-pooled features through a shared multi-layer perceptron, expressed as:

$$M_c(F) = \sigma\left(\text{MLP}(\text{AvgPool}(F)) + \text{MLP}(\text{MaxPool}(F))\right)$$

The spatial attention module then captures spatial relationships by applying convolution on channel-wise pooled features:

$$M_s(F) = \sigma\left(f^{7 \times 7}\left([\text{AvgPool}(F); \text{MaxPool}(F)]\right)\right)$$

By integrating these two modules sequentially, CBAM enhances feature extraction by focusing on both informative channels and salient spatial locations, significantly improving detection robustness for defects with diverse visual characteristics on solar panels.

Coordinate Attention (CA) addresses the limitations of global pooling by decomposing it into two parallel one-dimensional feature encoding operations. This maintains precise positional information while capturing long-range dependencies. The coordinate information embedding is performed along the horizontal and vertical directions:

$$z_c^h(h) = \frac{1}{W}\sum_{0 \leq i < W} x_c(h, i)$$

$$z_c^w(w) = \frac{1}{H}\sum_{0 \leq j < H} x_c(j, w)$$

Following the coordinate information embedding, the generated coordinate attention can be expressed as:

$$y_c(i, j) = x_c(i, j) \times g_c^h(i) \times g_c^w(j)$$

where \(g^h\) and \(g^w\) are the attention weights computed through convolutional transformations and Sigmoid activation functions. By preserving positional awareness, CA enables the model to accurately localize defective regions on solar panels while maintaining computational efficiency.

Network Model mAP/% P/% R/%
YOLOv5 81.9 69.3 81.1
YOLOv5 + CA 82.3 68.6 82.1
YOLOv5 + CBAM 83.5 69.1 81.9

The experimental results reveal that both attention mechanisms improve the mAP compared with the baseline YOLOv5. Specifically, introducing the CA module resulted in a 0.4% increase in mAP, whereas incorporating CBAM achieved a 1.6% improvement, reaching 83.5% mAP. The enhanced recall values also indicate that attention modules help reduce missed detections, which is critical for identifying relatively inconspicuous defects on solar panels.

Feature Fusion Network Improvements

While PANet in YOLOv5 provides solid multi-scale feature fusion capability, there remains room for improvement when handling small targets in photovoltaic applications. I investigate two advanced feature fusion architectures: the Adaptive Spatial Feature Fusion (ASFF) module and the Bidirectional Feature Pyramid Network (BiFPN).

ASFF introduces attention weight mechanisms to adaptively combine features from different scales, filtering conflicting spatial information and enhancing the learning capability for multi-scale object detection. The feature fusion calculation can be defined as:

$$y_{ij}^{l} = \alpha_{ij}^{l} \cdot x_{ij}^{1 \rightarrow l} + \beta_{ij}^{l} \cdot x_{ij}^{2 \rightarrow l} + \gamma_{ij}^{l} \cdot x_{ij}^{3 \rightarrow l}$$

where \(\alpha_{ij}^{l}\), \(\beta_{ij}^{l}\), and \(\gamma_{ij}^{l}\) denote the adaptive spatial weights for features from three different levels, and \(\alpha_{ij}^{l} + \beta_{ij}^{l} + \gamma_{ij}^{l} = 1\). The Softmax function normalizes these weights to the range [0,1], ensuring that the summation of the weighted contributions equals unity.

BiFPN incorporates two key improvements over conventional feature pyramids. First, it enables bidirectional multi-scale feature fusion through cross-scale connections, allowing features to flow both top-down and bottom-up. Second, it introduces weighted feature fusion by assigning learnable weights to each input feature, using a fast normalized fusion method based on ReLU activation:

$$O_i = \sum_j \frac{w_j}{\epsilon + \sum_k w_k} \cdot I_j$$

BiFPN simplifies the PANet structure by removing nodes with low contribution, adding skip connections between nodes at the same level, and repeating the fusion blocks for deeper feature integration. This approach achieves more efficient and flexible feature fusion, improving detection accuracy for solar panel defects at various scales.

Network Model mAP/% P/% R/%
YOLOv5 81.9 69.3 81.1
YOLOv5 + ASFF 82.5 74.3 78.6
YOLOv5 + BiFPN 84.1 68.7 85.3

From the comparison, the BiFPN-based model achieved the highest recall at 85.3% and the highest mAP at 84.1%. Although ASFF achieved the highest precision at 74.3%, its lower recall value constrained its overall mAP performance. BiFPN demonstrated balanced performance in precision and recall, making it a more effective feature fusion strategy for the detection tasks on solar panels.

Dataset Construction and Experimental Setup

For this research, I utilized a publicly available solar panel defect image dataset created by a university research team. The original dataset contains 1016 images, which was relatively limited for training robust deep learning models. To expand the dataset and improve model generalization, I performed data augmentation through flipping, filtering, gray-level transformations, and other techniques. After augmentation, the dataset was expanded to 4000 images. The dataset was divided into training and validation sets following an 8:2 ratio. It includes normal solar panel images as well as five distinct types of defect categories: cracks, scratches, black_border, no_electricity, and hot_spot.

The experimental platform used an RTX 2080 GPU cloud server, with PyTorch version 1.11.0 and CUDA version 11.3. During training, the input image size was set to 640×640 pixels, the Adam optimizer was employed, training was conducted for 400 epochs, the batch size was set to 16, momentum was 0.937, and the initial learning rate was set to 0.001. The model was initialized with the “yolov5s.pt” pre-trained weights.

Ablation Study and Comparative Analysis

Based on the attention mechanism and feature fusion network improvements, I constructed four combined models: YOLOv5 + CBAM + BiFPN, YOLOv5 + CBAM + ASFF, YOLOv5 + CA + BiFPN, and YOLOv5 + CA + ASFF. The ablation study results are presented in the following table:

Network Model mAP/% P/% R/%
YOLOv5 81.9 69.3 81.1
YOLOv5 + CBAM + ASFF 85.7 83.5 84.97
YOLOv5 + CA + ASFF 84.5 82.8 81.6
YOLOv5 + CBAM + BiFPN 88.6 84.1 85.5
YOLOv5 + CA + BiFPN 86.6 81.4 85.9

The experimental results demonstrate that all four combined improvement models outperform the original YOLOv5. Among them, the combination of CBAM and BiFPN yielded the highest mAP value of 88.6%, representing a 6.7% improvement over the baseline. This combination also achieved a precision of 84.1% and a recall of 85.5%, demonstrating its effectiveness in both reducing false positives and minimizing missed detections. The loss function curves indicate that the improved models converged faster than the original YOLOv5, confirming that the attention mechanism and feature fusion networks contribute to more efficient optimization.

Furthermore, when examining the detection results for each individual defect class, I observed notable improvements. The no_electricity category, which was the most challenging class for the original YOLOv5 with only 73.2% mAP, showed a dramatic improvement to 92.3% mAP through the CBAM + BiFPN combination. Similarly, hot_spot detection improved from 81.9% to 91.5%, and scratch detection improved from 76.1% to 83.1%. These results indicate that the improved algorithm is particularly effective for detecting small targets and defects with subtle visual appearances on solar panels. However, the inference time also increased from 0.0146 s to 0.032 s due to the increased network complexity.

Lightweight Improvement for Solar Panel Surface Defect Detection

While the attention-based and feature fusion-based improvements significantly enhanced detection accuracy, they also increased model parameters and computational costs, making deployment on resource-constrained devices challenging. To address this limitation, I conducted a lightweight improvement study on the YOLOv5 model for efficient solar panel defect detection without sacrificing accuracy.

Backbone Network Replacement with EfficientNetv2

I selected EfficientNetv2 as the lightweight backbone network to replace the original CSPNet in YOLOv5. EfficientNetv2 is a highly efficient and lightweight feature extraction network that achieves state-of-the-art accuracy while keeping parameter efficiency and training speed advantageous. It employs Mobile Inverted Bottleneck Convolution (MBConv) modules, which integrate depthwise separable convolutions and squeeze-and-excitation blocks. An improved fused MBConv module replaces the 1×1 convolution and 3×3 depthwise convolution with a standard 3×3 convolution in shallow layers, further optimizing training efficiency. I adopted the EfficientNetv2-S variant as the base backbone network. The network structure of the improved backbone incorporates a Stem block for initial feature processing, followed by multiple stages of MBConv and fused MBConv layers, integrated with a SPPF (Spatial Pyramid Pooling Fast) structure at the end.

Incorporating Bottleneck Transformer

To strengthen the feature representation capability of the backbone, I introduced the Bottleneck Transformer (BoTNet) module. BoTNet integrates multi-head self-attention (MHSA) into the residual bottleneck blocks, replacing the 3×3 spatial convolution in certain stages. The self-attention mechanism enables the network to capture global contextual relationships, which is valuable for identifying distributed defects on solar panels. The attention mechanism calculates queries, keys, and values from the input feature map and computes the attention weights as:

$$\text{Attention}(Q, K, V) = \text{Softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right)V$$

By combining MBConv’s efficient local feature extraction with BoTNet’s global modeling capability, the improved network can attend to important regions within complex backgrounds, thereby enhancing detection performance for small and subtle defects on solar panels.

Neck Network Improvement and Loss Function Optimization

To further improve multi-scale feature fusion while keeping the model lightweight, I replaced the PANet structure in YOLOv5’s neck with BiFPN. BiFPN enables efficient bidirectional feature fusion with learnable weights, facilitating comprehensive integration of features at different resolutions. This is particularly important for solar panel defect detection because defects often appear at various scales, and properly fused multi-scale features directly contribute to detection robustness.

Additionally, I replaced the original loss function with the PolyLoss function. PolyLoss is derived from the Taylor polynomial expansion of commonly used loss functions, providing flexibility to adjust polynomial coefficients for different datasets:

$$\mathcal{L}_{\text{Poly}} = \sum_{i=1}^{\infty} \alpha_i (1 – P_t)^{i}$$

where \(\alpha_i\) represents the polynomial coefficient and \(P_t\) is the predicted probability for the target label. By adjusting the first polynomial coefficient, the loss function can be tuned to handle positive and negative sample imbalance effectively, leading to improved detection performance on small target datasets. This modification enhanced the model’s generalization capabilities and its robustness against various defect types on solar panels.

Experimental Setup and Evaluation Metrics

This experiment was conducted on an RTX 3090 GPU cloud server using PyTorch 1.11.0 and CUDA 11.3. The image input size was set to 640×640 pixels, SGD optimizer was employed with a batch size of 16, momentum of 0.937, and initial learning rate of 0.001. The dataset was divided into training, validation, and test sets with a ratio of 6:2:2. Evaluation metrics included recall (R), precision (P), mean average precision (mAP), and frames per second (FPS).

The precision and recall calculations are:

$$P = \frac{TP}{TP + FP}$$

$$R = \frac{TP}{TP + FN}$$

where TP is the number of true positives, FP is the number of false positives, and FN is the number of false negatives. The average precision (AP) is calculated as the area under the precision-recall curve, and mAP is the mean of AP across all defect categories.

Ablation Study Results

To validate the contribution of each improvement component, I performed an ablation study. The experimental results are presented in the following table:

Model Description FPS mAP/% P/% R/% Model Size/MB
YOLOv5s 60.53 81.9 69.3 81.1 7.2
YOLOv5s + Efficientnetv2 75.6 83.2 82.6 81.4 4.1
YOLOv5s + Efficientv2 + BoTNet 74.2 86.3 84.4 83.2 4.7
YOLOv5s + Efficientv2 + BoTNet + BiFPN 66.7 91.8 88.6 86.5 5.6
YOLOv5s + Efficientv2 + BoTNet + BiFPN + PolyLoss 66.4 92.4 88.4 87.6 5.6

From the ablation study, several important observations can be made. Replacing the backbone with EfficientNetv2 increased the FPS from 60.53 to 75.6 while slightly improving the mAP by 1.3%, and notably reducing model size from 7.2 MB to 4.1 MB. This confirms that EfficientNetv2 successfully achieves the intended lightweight objective. Adding BoTNet improved mAP by 3.1% with only a marginal increase in model size. Incorporating BiFPN into the neck network significantly improved mAP to 91.8%, representing a 5.5% improvement over the previous configuration. Finally, the introduction of PolyLoss further refined the detection performance, achieving the highest mAP of 92.4% with a recall of 87.6%, while maintaining a model size of only 5.6 MB.

Comparison with State-of-the-Art Methods

To evaluate the overall performance of the improved lightweight model, I compared it with several mainstream detection algorithms, including YOLOv3, YOLOv5s, YOLOv8s, and Faster R-CNN. The comparison of model parameters and inference delays is presented in the following table:

Model Model Size/MB FLOPs Inference Delay/ms
YOLOv3 23.5 13.0 3.0
YOLOv5s 7.2 16.0 7.2
YOLOv8s 11.1 28.7 6.4
Faster R-CNN 15.9 14.8 5.5
YOLOv5-ours 5.6 8.3 2.7

The improved model achieves the smallest model size of 5.6 MB and the lowest inference delay of 2.7 ms, alongside a reduced computational complexity of 8.3 GFLOPs. When comparing detection accuracy across these algorithms, the superiority of the proposed improvement is fully demonstrated:

Model P/% R/% mAP/%
YOLOv3 80 76.7 78.6
YOLOv5s 69.3 81.1 81.9
YOLOv8 81.9 83.6 84.4
Faster R-CNN 80.6 78.7 80.4
YOLOv5-ours 88.4 87.6 92.4

The improved lightweight YOLOv5 model achieved a mAP of 92.4%, which surpasses YOLOv3 by 13.8%, YOLOv5s by 10.5%, YOLOv8 by 8.0%, and Faster R-CNN by 12.0%. Notably, these accuracy gains are accompanied by a significant reduction in model parameters and computational demands. The model parameter count is approximately three-quarters that of the original YOLOv5s, and the computational cost is reduced to roughly half, while the inference speed is about 2.5 times faster. This exceptional balance between speed and accuracy makes the improved model particularly suitable for real-time solar panel defect detection applications.

The learning curve for the improved model shows stable and rapid convergence. Throughout the training process spanning 400 epochs, the loss values gradually decrease and reach stability, indicating that the model effectively learns meaningful representations from the solar panel defect dataset without significant overfitting. The precision-recall curves demonstrate that the improved model maintains high precision across varying recall values, reflecting its reliable classification ability across different defect categories.

The detection results of the improved model on the solar panel dataset show that it can accurately identify common defect types, including cracks, scratches, black borders, electrical failures, and hot spots. More importantly, defects on solar panels that are small in scale, such as scratches and black borders, can be successfully localized and classified. This validation confirms that the lightweight improved model retains excellent detection capability while being efficiently deployable to mobile devices and edge computing platforms.

Conclusions and Future Directions

In this research, I systematically investigated deep learning-based defect detection methods for solar panels. Building upon the YOLOv5 architecture, I proposed and validated several improvements to address the specific challenges encountered in solar panel surface defect detection.

In the first phase of this research, I focused on improving detection accuracy through attention mechanisms and feature fusion networks. Through systematic experiments with CBAM and CA attention mechanisms, combined with BiFPN and ASFF feature fusion structures, I identified the optimal combination of CBAM + BiFPN, which elevated the mAP to 88.6%, an improvement of 6.7% over the original YOLOv5. This approach proved particularly effective in detecting small defects such as scratches and less obvious defects like short circuits in solar panels, demonstrating the importance of fine-grained feature extraction and multi-scale feature fusion in photovoltaic defect detection.

In the second phase, I addressed the practical challenge of model deployment on resource-constrained devices by developing a lightweight improvement strategy for solar panel defect detection. By replacing the original backbone with EfficientNetv2, introducing BoTNet for enhanced feature representation, improving the neck network with BiFPN, and optimizing the loss function using PolyLoss, the final model achieved a mAP of 92.4% with an FPS improvement of approximately 10% and a substantial reduction in model size to 5.6 MB. This remarkable balance between detection accuracy and computational efficiency significantly enhances the model’s practical applicability in real-world solar panel inspection systems.

Despite the promising performance achieved, there are still several areas deserving further investigation. Future research directions may include expanding the dataset with more diverse defect patterns and imaging conditions to enhance model generalization for solar panel inspections in various environments. Additionally, exploring more advanced lightweight module designs, such as neural architecture search and knowledge distillation techniques, could further optimize the trade-off between model performance and deployment efficiency. Incorporating more recent architectures and innovations from the detection community may yield additional performance gains. Finally, evaluating the proposed model on embedded hardware platforms, such as NVIDIA Jetson or mobile processors, would provide valuable insights into the practical deployment considerations for automated solar panel inspection systems in industrial and field environments.

In conclusion, this research provides a comprehensive investigation and effective methodology for deep learning-based defect detection of solar panels. The improved algorithms offer significant gains in detection accuracy while maintaining advantageous computational efficiency, making them valuable tools for quality assurance and operational maintenance in the growing photovoltaic industry.

Scroll to Top