Improved YOLOv8 for Solar Panels Defect Detection

In the field of renewable energy, the performance and quality of solar panels directly influence the efficiency and reliability of photovoltaic systems. Solar panels are typically exposed to harsh outdoor environments, suffering from continuous weathering, which can lead to various defects such as dirt accumulation, electrical damage, physical damage, foreign object coverage, and hot spots. These defects may cause energy loss, reduced lifespan, and system failures. Early and accurate detection of these defects is crucial for improving the overall performance of solar panels. However, training and testing deep learning models require substantial computational resources, while terminal devices for solar panels defect detection often have limited computing power. This poses a significant challenge for practical applications. Therefore, reducing model complexity and computational cost while maintaining detection accuracy is an important research issue.

Many researchers have worked on this topic. For instance, some proposed a K-means clustering method based on HSV space for processing infrared images of solar panels. Others designed a solar panel recognition model to remove background noise and isolate panels from infrared images for rapid hot spot detection. A real-time multivariant deep learning model was also introduced to address this problem. Another approach used a SimAM-AdaYOLOv5 algorithm with adaptive learning of feature scales and receptive fields, incorporating SimAM attention to enhance feature extraction. However, these methods often require more computational resources and time for training and inference, and they may lack the ability to capture location information effectively.

In recent years, deep learning models have been widely used in object detection, image classification, and semantic segmentation. Compared with traditional methods, deep learning learns feature representations from large amounts of data, offering better generalization, higher accuracy, and stronger robustness. Deep learning-based object detection methods are mainly divided into two categories: one-stage detectors such as YOLO and SSD, and two-stage detectors such as Faster R-CNN. Some improved algorithms, like the enhanced Dn-YOLOv7, combine denoising convolutional neural networks with coordinate convolution to improve noise reduction and small target detection. Another YOLOv8-EL method uses GauGAN for data augmentation and introduces a context aggregation module to suppress background noise, achieving higher accuracy. Particle swarm optimization has also been integrated into YOLOv8 to optimize model parameters. Despite these advances, many methods still suffer from high parameter counts and computational loads, leaving room for lightweight improvements.

Considering the limited computational resources and the need for both detection accuracy and model compactness, we propose a lightweight defect detection algorithm for distributed solar panels based on YOLOv8. Our approach aims to reduce computational cost, parameter size, and model volume while suppressing background noise interference. The main contributions of this work are as follows:

  1. We adopt the lightweight StarNet architecture as the feature extraction backbone, effectively reducing model complexity by removing numerous branch structures.
  2. We introduce the Triplet attention mechanism into the backbone to enhance multi-scale feature extraction capability.
  3. We design the SPPF-AM module to improve spatial information perception and adapt to targets of different scales.
  4. We replace the original C2f module with C2f_DSConv2D, which combines deformable convolution to reduce computational complexity and parameter count while maintaining efficiency.
  5. We incorporate the Spatial Context-Aware Module (SCAM) into the feature fusion network to adaptively fuse semantic information from different levels, reduce noise, and suppress irrelevant background interference.
  6. We design ECIoU to replace CIoU, enhancing bounding box regression fitting and accelerating convergence.

Figure 1 in the original paper shows the overall structure of the improved YOLOv8 network, which serves as the baseline for our modifications. In the following sections, we describe each improvement in detail.

1. Lightweight Backbone: StarNet

To reduce model complexity while maintaining feature extraction capability, we replace the original YOLOv8n backbone with StarNet. StarNet is a hierarchically structured network with four stages, using convolutional layers for downsampling and improved Demo blocks for feature extraction. It replaces Layer Normalization with Batch Normalization for efficiency and inserts depthwise convolution (DW-Conv) at the end of each block, following MobileNeXt design. The channel expansion factor is set to 4, and network width doubles at each stage. The GELU activation is replaced by ReLU6 to follow MobileNetv2 design. The core operation of StarNet is the “star operation” (element-wise multiplication), which can exponentially increase implicit feature dimensions without additional computational cost.

The star operation in a single layer can be expressed as:

$$(W_1^T X + B_1) * (W_2^T X + B_2)$$

For simplicity, we combine weights and biases: let $\tilde{W} = [W, B]^T$ and $\tilde{X} = [X, 1]^T$, then the operation becomes $(\tilde{W}_1^T \tilde{X}) * (\tilde{W}_2^T \tilde{X})$. Considering a single output channel and single element input, we have $\omega_1, \omega_2, x \in \mathbb{R}^{(d+1) \times 1}$. The operation expands to:

$$(\omega_1^T x) * (\omega_2^T x) = \sum_{i=1}^{d+1} \sum_{j=1}^{d+1} \omega_1^i \omega_2^j x_i x_j$$

This expression contains $\frac{(d+2)(d+1)}{2}$ distinct terms, including nonlinear cross terms. Thus, a star operation in $d$-dimensional space implicitly represents a feature space of approximately $\left(\frac{d}{2}\right)^2$ dimensions. By stacking multiple layers, the implicit dimension grows exponentially. For example, with 10 layers of width 128, the implicit dimension becomes roughly $2^{10^4}$, effectively infinite. This allows StarNet to achieve high-dimensional nonlinear mapping without increasing computational complexity.

Table 1 shows the architecture of StarNet used in our model.

Stage Output Size StarNet Block
Stem H/4 × W/4 Conv 3×3, stride 2; Conv 3×3, stride 2
Stage 1 H/4 × W/4 Demo block × 2, channels C1
Stage 2 H/8 × W/8 Demo block × 2, channels C2 = 2C1
Stage 3 H/16 × W/16 Demo block × 4, channels C3 = 2C2
Stage 4 H/32 × W/32 Demo block × 2, channels C4 = 2C3

2. Triplet Attention Mechanism

To improve small target feature extraction, we add the Triplet attention module at the end of the backbone. Triplet captures interactions between different dimensions, reducing irrelevant information and focusing on target features. It consists of three parallel branches that compute attention across (C, H), (C, W), and (C, H, W) dimensions. Each branch performs a rotation, Z-Pool, convolution, and sigmoid activation, then averages the outputs. The final output is:

$$Y = \frac{1}{3} \left( \hat{X}_1 \sigma(\psi_1(\hat{X}_1^*)) + \hat{X}_2 \sigma(\psi_2(\hat{X}_2^*)) + X \sigma(\psi_3(\hat{X}_3^*)) \right)$$

where $\sigma$ is sigmoid and $\psi$ denotes standard convolution. This mechanism helps the model better focus on small defects in solar panels.

3. SPPF-AM Module

The original SPPF in YOLOv8 uses max pooling of different kernel sizes to fuse multi-scale features. However, it tends to focus on edge information while ignoring background context, which may affect accuracy. We propose SPPF-AM, which adds both MaxPool2d and AdaptiveMaxPool2d after the input convolution. MaxPool2d selects the maximum value in each local window, effectively capturing salient features. AdaptiveMaxPool2d dynamically adjusts pooling window size to output a fixed size, preserving global maximum information. The two branches are concatenated to fuse local and global features. This enhances the model’s perception of spatial information and improves adaptability to different defect scales.

The SPPF-AM module can be described as:

$$\text{Input} \rightarrow \text{Conv} \rightarrow [\text{MaxPool2d}, \text{AdaptiveMaxPool2d}] \rightarrow \text{Concat} \rightarrow \text{Output}$$

This design helps the network better handle defects of varying sizes in solar panels.

4. C2f_DSConv2D Module

To reduce memory usage and increase speed, we introduce DSConv (Distribution-Shift Convolution) into the C2f module, forming C2f_DSConv2D. DSConv consists of a Variable Quantization Kernel (VQK) and a distribution shift component. VQK stores variable-length integer values that are fixed after setting, reducing storage. The distribution shift component includes Kernel Distribution Shifter (KDS) and Channel Distribution Shifter (CDS). KDS quantizes the depth of each block, while CDS adjusts channel distribution. DSConv produces outputs equivalent to standard convolution but with significantly smaller kernel sizes, reducing parameters and computational complexity.

By replacing the standard convolution in C2f with DSConv, the C2f_DSConv2D module maintains feature extraction capability while achieving lower computational cost and faster inference. This is particularly beneficial for real-time defect detection on resource-constrained devices.

5. Spatial Context-Aware Module (SCAM)

To suppress noise and background interference, we integrate SCAM into the feature fusion network. SCAM is inspired by GCNet and SCP, using three branches. The first branch uses global average pooling (GAP) and global max pooling (GMP) to integrate global information. The second branch uses a 1×1 convolution to generate linear transformed features. The third branch simplifies key-value pairs with 1×1 convolution. Finally, matrix multiplication and Hadamard product are used to obtain the output, which contains both cross-channel and spatial context information.

The operation at each pixel can be expressed as:

$$Q_j^i = P_j^i + a_j^i \sum_{n=1}^{N_i} \frac{\exp(\omega_{qk} P_j^i)}{\sum_{m=1}^{N_i} \exp(\omega_{qk} P_m^i)} \cdot \omega_v P_j^i$$

where

$$a_j^i = \frac{\exp([\text{avg}(P_i); \max(P_i)] P_j^i)}{\sum_{n=1}^{N_i} \exp([\text{avg}(P_i); \max(P_i)] P_n^i)} \cdot \omega_v$$

Here, $\text{avg}(\cdot)$ and $\max(\cdot)$ are GAP and GMP, respectively. This module effectively aligns local features and reduces noise, improving the accuracy of detecting weak defects on solar panels.

6. ECIoU Loss Function

The original YOLOv8 uses CIoU loss for bounding box regression. However, because solar panel defects vary greatly in size and shape, we design ECIoU by combining CIoU and EIoU. CIoU considers overlap, center distance, and aspect ratio consistency, while EIoU also accounts for width and height differences. The ECIoU loss is:

$$\text{ECIoU} = 1 – \text{IoU} + \alpha v + \frac{\rho^2(b, b^{gt})}{c^2} + \frac{\rho^2(h, h^{gt})}{c_h^2} + \frac{\rho^2(w, w^{gt})}{c_w^2}$$

where $\alpha = \frac{v}{(1-\text{IoU})+v}$, $v = \frac{4}{\pi^2} \left( \arctan \frac{w^{gt}}{h^{gt}} – \arctan \frac{w}{h} \right)^2$, $c$ is the diagonal length of the smallest enclosing box, $c_w$ and $c_h$ are its width and height. This loss accelerates convergence and improves fitting ability for boundary boxes, leading to more precise defect localization in solar panels.

7. Experiments

7.1 Experimental Setup

We conducted experiments on a computer with an NVIDIA GeForce RTX 4060 GPU, 16 GB RAM, Windows 10, Python 3.8, PyTorch 1.12, and CUDA 12.2. The batch size was 16, training for 200 epochs. We used SGD optimizer with initial learning rate 0.01, momentum 0.9, weight decay 0.001. Learning rate decayed linearly to 0.

7.2 Dataset

Since there is no public dataset for solar panel defects, we collected images using a DJI M300 drone with a Zenmuse H20T camera. The dataset includes five defect types: hot spots, physical damage, electrical damage, foreign object coverage, and dirt. A total of 12,533 images were manually labeled using LabelImg. The dataset was split into training (70%), testing (20%), and validation (10%) sets. Table 2 shows the distribution.

Defect Type Number of Images
Hot spots 1,506
Physical damage 2,200
Electrical damage 1,880
Foreign object coverage 3,900
Dirt 3,047

7.3 Evaluation Metrics

We use precision (P), recall (R), mean average precision at IoU=0.5 (mAP@0.5), number of parameters (Params in millions), and computational cost (GFLOPs). Precision is defined as:

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

Recall is:

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

AP is the area under the precision-recall curve for a single class, and mAP is the average of AP over all classes.

7.4 Transfer Learning

We first pre-trained the YOLOv8n model on COCO2017, then transferred the weights to our solar panels defect detection task. The model was fine-tuned on our dataset.

7.5 Ablation Study

We conducted ablation experiments to evaluate each improvement. Results are shown in Table 3. The baseline YOLOv8n achieves mAP@0.5 of 85.9%. Adding StarNet reduces parameters by 26.3% and GFLOPs by 19.8%, with slight mAP drop to 85.6%. Adding Triplet or SPPF-AM increases parameters and GFLOPs but improves mAP. C2f_DSConv2D reduces parameters by 9.9% and GFLOPs by 5.6%, achieving mAP 86.4%. SCAM improves mAP to 86.9%. ECIoU alone yields 87.6%. The full model (all improvements) achieves mAP 89.7%, with parameters reduced by 35% and GFLOPs reduced by 29.6% compared to baseline.

SN Triplet SPPF-AM C2f_DS SCAM ECIoU GFLOPs R (%) mAP@0.5 (%) Params (M)
× × × × × × 8.1 83.9 85.9 5.7
× × × × × 6.5 84.2 85.6 4.2
× × × × × 21.5 84.5 86.4 11.7
× × × × × 8.3 84.4 85.1 5.9
× × × × × 7.3 84.4 86.4 5.4
× × × × × 8.0 85.2 86.9 5.8
× × × × × 8.2 85.6 87.6 5.7
5.7 87.1 89.7 3.7

7.6 Comparison with State-of-the-Art

We compared our model with several popular detectors on the same dataset. Results are in Table 4. Our model achieves the highest mAP@0.5 (89.7%) and precision (90.1%), while having the smallest parameter count (3.7M) and GFLOPs (5.7). Faster R-CNN and SSD have much larger model sizes and lower accuracy. YOLOv5n, YOLOv7-tiny, YOLOv8n, YOLOv8s, YOLOv9t, and RE-DETR all underperform our model in both accuracy and efficiency.

Model P (%) R (%) mAP@0.5 (%) Params (M) GFLOPs
Faster R-CNN 56.3 74.1 76.3 108.2 302.8
SSD 68.5 73.8 78.5 93.1 150.5
EfficientDet 77.3 75.2 80.4 70.7 90.8
YOLOv5n 80.6 85.7 87.7 4.0 8.6
YOLOv7-tiny 79.3 65.4 72.3 11.5 13.2
YOLOv8n 80.6 83.9 85.9 5.7 8.1
YOLOv8s 81.2 84.7 89.0 21.2 28.4
YOLOv9t 82.2 85.3 86.4 5.0 10.7
RE-DETR 83.3 84.2 87.5 38.3 230.6
Ours 90.1 87.1 89.7 3.7 5.7

7.7 Visualization of Detection Results

We visualized detection results on sample images. Compared with YOLOv5n, YOLOv7-tiny, YOLOv8n, YOLOv8s, and YOLOv9t, our model successfully detects all targets without false positives or missed detections. Other models sometimes miss small defects or produce overlapping boxes. Our model demonstrates superior perception and localization capabilities, especially for weak and small defects on solar panels.

7.8 Generalization Test on PVELAD Dataset

To verify generalization, we tested our model on the public PVELAD dataset, which contains 36,543 near-infrared images with 12 defect classes. Results in Table 5 show that our model maintains high mAP (88.9%) while reducing parameters (3.9M) and GFLOPs significantly. This indicates strong generalization ability across different solar panels defect datasets.

Model P (%) R (%) mAP@0.5 (%) Params (M)
YOLOv8n 81.2 84.0 85.0 5.7
Ours 87.6 86.4 88.9 3.9

To illustrate our approach in a real-world scenario, consider the following image of a solar panel installation captured by a drone, which is typical for defect inspection tasks. Such images often contain complex backgrounds and varying lighting conditions, making accurate defect detection challenging.

8. Conclusion

In this work, we proposed a lightweight defect detection algorithm for solar panels, named SN-YOLOv8, based on the YOLOv8n baseline. By replacing the backbone with StarNet, introducing Triplet attention, designing SPPF-AM, adopting C2f_DSConv2D, integrating SCAM, and using ECIoU loss, we significantly reduced model parameters and computational cost while improving detection accuracy. Experimental results on our collected dataset and the public PVELAD dataset show that our model achieves 90.1% precision and 89.7% mAP@0.5, with only 3.7M parameters and 5.7 GFLOPs. This is a 35% reduction in parameters and 29.6% reduction in GFLOPs compared to the baseline YOLOv8n. The model outperforms several state-of-the-art detectors in both accuracy and efficiency.

The proposed method is well-suited for deployment on resource-limited devices such as drones or embedded systems for real-time solar panels defect inspection. Future work will focus on further improving detection accuracy for specific defect types like hot spots and electrical damage, and on hardware acceleration to enable onboard processing on dual-light drones.

Scroll to Top