SN-YOLOv8: A Lightweight Algorithm for Solar Panel Defect Detection

The reliable operation and energy output of photovoltaic systems are fundamentally tied to the integrity of their core component: the solar panel. These panels, often deployed in harsh outdoor environments, are susceptible to various defects such as hot spots, physical damage, cell cracks, soiling, and foreign object covering. Timely and accurate detection of these anomalies is crucial for maintaining system efficiency, preventing power loss, and ensuring operational safety. However, deploying sophisticated defect detection models on edge devices, such as inspection drones or on-site monitoring systems, presents significant challenges due to constraints in computational power and memory.

Traditional image processing methods and early deep learning approaches often struggle with the complexities of real-world solar panel inspection. Challenges include low contrast between defects and background, varying scales of defects, complex and variable backgrounds (e.g., rooftops, fields), and the inherent need for real-time or near-real-time processing on resource-limited hardware. Many existing models prioritize accuracy at the expense of model size and computational cost, making them unsuitable for practical, scalable deployment. The goal, therefore, is to develop a model that achieves an optimal balance: high detection accuracy coupled with lightweight architecture for efficient inference.

This work addresses these challenges by proposing a novel, lightweight algorithm named SN-YOLOv8 for solar panel defect detection. Our approach is built upon the efficient YOLOv8n architecture but introduces a series of strategic enhancements designed to reduce parameters and computations while boosting accuracy and robustness, especially for defective solar panels. The core contributions include the adoption of the StarNet backbone for efficient feature extraction, the integration of a Triplet attention mechanism, a redesigned spatial pyramid module (SPPF-AM), a novel bottleneck block (C2f_DSConv2D), a Spatial Context-Aware Module (SCAM), and an advanced loss function (ECIoU). Comprehensive experiments demonstrate that our model significantly outperforms existing methods, offering a practical solution for the intelligent inspection of solar panels.

Methodology: The SN-YOLOv8 Architecture

The overall architecture of SN-YOLOv8 is illustrated in the diagram below. It retains the general neck and head structure of YOLOv8 but revolutionizes the backbone and introduces critical modules within the feature fusion paths.

1. Lightweight Backbone: StarNet

To drastically reduce the model’s complexity, we replace the original CSPDarknet backbone with StarNet. StarNet’s efficiency stems from its innovative “star operation,” which enables an exponential expansion of implicit feature dimensions without a proportional increase in computational cost. A standard convolutional layer followed by activation learns features in an explicit, linear subspace. The star operation, in contrast, performs an element-wise multiplication of two linearly transformed input streams, creating a rich, high-order implicit feature space.

Consider an input vector \(x \in \mathbb{R}^{(d+1) \times 1}\) (appending a 1 for bias). Let \(ω_1, ω_2 \in \mathbb{R}^{(d+1) \times 1}\) be the weights for two linear transformations. The star operation is defined as:

$$(ω_1^T x) * (ω_2^T x) = \sum_{i=1}^{d+1} ω_{1i} x_i * \sum_{j=1}^{d+1} ω_{2j} x_j$$

This can be expanded into a sum of pairwise terms:

$$= \sum_{i=1}^{d+1}\sum_{j=1}^{d+1} (ω_{1i} ω_{2j}) (x_i x_j)$$

This results in approximately \((d/2)^2\) unique, non-linear terms (\(x_i x_j\)), effectively projecting the input into a much higher-dimensional implicit space \(\mathbb{R}^{(d/2)^2}\) within a single, computationally cheap layer. When stacked over \(l\) layers, the implicit dimensionality grows exponentially as \(\mathbb{R}^{(d/2)^{2^l}}\), allowing a very compact network to capture extremely complex features pertinent to solar panel defects. The StarNet backbone significantly reduces parameters and FLOPs while maintaining strong representational power.

2. Triplet Attention for Cross-Dimensional Interaction

To enhance the model’s ability to capture fine-grained defect features on solar panels, we integrate the Triplet attention mechanism at the end of the backbone. Standard channel or spatial attention mechanisms process information along a single dimension. Triplet attention efficiently captures cross-dimensional dependencies between channel (C), height (H), and width (W) axes through three parallel branches.

  • Branch 1: Rotates the input tensor to interact C with H, applies Z-pool (concat of max and avg pool), a convolution, and a sigmoid to generate weights, then rotates back.
  • Branch 2: Similar to Branch 1 but rotates to interact C with W.
  • Branch 3: Applies Z-pool, convolution, and sigmoid directly on the spatial dimensions (H, W) to capture spatial attention.

The outputs of the three branches are averaged to produce the final refined feature map. This structured cross-talk allows the network to focus on salient defect regions across all dimensions, improving the detection of small and subtle anomalies on solar panels.

3. SPPF-AM: Enhanced Spatial Pyramid Pooling

The original Spatial Pyramid Pooling Fast (SPPF) module in YOLOv8 uses multiple fixed-size max-pooling layers to create multi-scale features. We enhance it to SPPF-AM by incorporating an Adaptive Max Pooling layer alongside the standard Max Pooling layers. The Adaptive Max Pooling layer dynamically adjusts its kernel size to produce a fixed-size output (e.g., 1×1, 5×5), capturing the most salient feature from the entire feature map at a truly global scale. This addition provides the model with a flexible, global contextual view, making it more robust to defects on solar panels that vary greatly in size and shape. The concatenated outputs from different pooling paths yield a more comprehensive multi-scale representation.

4. C2f_DSConv2D: Efficient Bottleneck with Deformable Kernels

The C2f module in YOLOv8’s neck is computationally intensive. We propose C2f_DSConv2D, which replaces the standard convolutions within the bottleneck with DSConv (Distributed Shift Convolution). DSConv decomposes the convolution operation into two components: a Variable Quantized Kernel (VQK) that stores low-bit integer values, and a Distribution Shifter that applies learned shifts to these kernels and across channels. This design decouples the storage format from the computation, drastically reducing memory footprint and accelerating computation while maintaining performance close to standard convolution. This replacement makes the feature fusion process in the neck much more efficient, which is critical for processing the high-resolution images often needed for solar panel inspection.

5. Spatial Context-Aware Module (SCAM)

Solar panel images can be noisy, with backgrounds like rooftops, grass, or soil interfering with defect detection. To suppress irrelevant background information and enhance target features, we introduce SCAM into the feature fusion network. SCAM explicitly models pixel-wise spatial context relationships. It uses a combination of Global Average Pooling (GAP) and Global Max Pooling (GMP) to gather channel-wise statistics, which are then used to weight the importance of spatial contexts. The core operation can be summarized as refining a pixel’s feature by aggregating information from all other pixels, weighted by their learned relevance. This allows the network to differentiate defective regions from complex backgrounds on solar panels more effectively.

The output for pixel \(j\) in feature map \(i\) is computed as:

$$Q_i^j = P_i^j + a_i^j \sum_{n=1}^{N_i} \frac{\exp(\omega_{qk} P_i^n)}{\sum_{m=1}^{N_i} \exp(\omega_{qk} P_i^m)} \cdot \omega_v P_i^n$$

where \(a_i^j\) is an attention weight derived from the GAP and GMP aggregated features. This module aligns local features with global context, reducing the loss of subtle defect information.

6. ECIoU Loss: Improved Bounding Box Regression

Accurate localization of defects is as important as identifying them. We replace the CIoU loss with our designed ECIoU (Enhanced Complete IoU) loss. CIoU considers overlap area, center-point distance, and aspect ratio. ECIoU builds upon this by directly incorporating penalties for width and height discrepancies, leading to faster and more stable convergence. The formula for ECIoU Loss is:

$$
\mathcal{L}_{ECIOU} = 1 – IoU + \frac{\rho^2(\mathbf{b}, \mathbf{b}^{gt})}{c^2} + \frac{\rho^2(w, w^{gt})}{c_w^2} + \frac{\rho^2(h, h^{gt})}{c_h^2}
$$

where \(\mathbf{b}\) and \(\mathbf{b}^{gt}\) are the predicted and ground-truth box centers, \(c\) is the diagonal length of the smallest enclosing box, \(c_w\) and \(c_h\) are its width and height, and \(\rho\) denotes the Euclidean distance. This loss provides more precise gradient signals for aspect ratio, enhancing the model’s ability to fit bounding boxes tightly around irregularly shaped defects on solar panels.

Experiments and Results

Dataset and Implementation Details

Due to the lack of a large public dataset for solar panel defects, we constructed our own using a DJI M300 drone equipped with a Zenmuse H20T camera. The dataset contains 12,533 annotated images across five common defect types found in solar panels: Hot Spot, Physical Damage, Cell Crack (Electrical Damage), Foreign Object, and Soiling. The dataset was split into 70% for training, 20% for validation, and 10% for testing. All models were trained from scratch on this dataset for 200 epochs using SGD optimizer, with an initial learning rate of 0.01.

Table 1: Distribution of Defects in the Solar Panel Dataset
Defect Type Number of Instances
Hot Spot 1,506
Physical Damage 2,200
Cell Crack 1,880
Foreign Object 3,900
Soiling 3,047
Total 12,533

Evaluation Metrics

We use standard object detection metrics: Precision (P), Recall (R), and mean Average Precision at IoU threshold 0.5 (mAP@0.5). To assess model efficiency, we report the number of parameters (Params) and computational complexity in Giga Floating Point Operations (GFLOPs).

Ablation Study

We conducted a systematic ablation study to validate the contribution of each proposed component. The baseline is the standard YOLOv8n model. The results are summarized in the table below.

Table 2: Ablation Study on the Solar Panel Defect Dataset
Model Variant Params (M) GFLOPs Precision (%) Recall (%) mAP@0.5 (%)
YOLOv8n (Baseline) 5.7 8.1 80.6 83.9 85.9
+ StarNet (SN) 4.2 6.5 81.0 84.2 85.6
SN + Triplet 8.0 15.5 80.5 82.0 84.5
SN + Triplet + SPPF-AM 8.0 15.5 81.8 82.0 84.5
SN + Triplet + SPPF-AM + C2f_DSConv2D 3.9 5.7 84.3 83.2 85.0
SN + Triplet + SPPF-AM + C2f_DSConv2D + SCAM 3.9 5.7 87.2 86.5 88.6
SN-YOLOv8 (Full Model + ECIoU) 3.7 5.7 90.1 87.1 89.7

The analysis reveals several key insights: 1) The StarNet backbone effectively reduces parameters and GFLOPs by 26.3% and 19.8% respectively with minimal accuracy drop. 2) Adding Triplet and SPPF-AM initially increases model size but lays the groundwork for feature enhancement. 3) The introduction of C2f_DSConv2D dramatically reduces the parameters and GFLOPs of the neck network, recovering and surpassing the efficiency of the baseline. 4) The SCAM module provides a substantial boost in Precision, Recall, and mAP, demonstrating its effectiveness in suppressing background noise for solar panel images. 5) The final model with ECIoU loss achieves the best performance, with mAP@0.5 reaching 89.7%, an improvement of 4.2% over the baseline, while having 35% fewer parameters and 29.6% lower computational cost.

Comparison with State-of-the-Art Models

We compare SN-YOLOv8 against a range of popular object detection models on our solar panel defect dataset. The results are presented below.

Table 3: Performance Comparison with State-of-the-Art Models on Solar Panel Defect Detection
Model Params (M) GFLOPs Precision (%) mAP@0.5 (%)
Faster R-CNN 108.2 302.8 56.3 76.3
SSD 93.1 150.5 68.5 78.5
EfficientDet-D0 70.7 90.8 77.3 80.4
YOLOv5n 4.0 8.6 80.6 87.7
YOLOv7-tiny 11.5 13.2 79.3 72.3
YOLOv8n (Baseline) 5.7 8.1 80.6 85.9
YOLOv8s 21.2 28.4 81.2 89.0
YOLOv9t 5.0 10.7 82.2 86.4
SN-YOLOv8 (Ours) 3.7 5.7 90.1 89.7

The results clearly demonstrate the superiority of our approach. While two-stage detectors (Faster R-CNN) and other one-stage detectors (SSD, EfficientDet) are either too heavy or less accurate for this task, our model strikes an exceptional balance. Compared to the lightweight YOLO family members, SN-YOLOv8 achieves the highest precision (90.1%) and a competitive mAP (89.7%), second only to the much larger YOLOv8s. Crucially, it does so with the lowest parameter count (3.7M) and the lowest computational cost (5.7 GFLOPs) among all YOLO variants shown. This makes it ideally suited for real-world deployment on devices with limited resources for inspecting solar panels.

Generalization Ability

To verify the generalization capability of SN-YOLOv8 beyond our proprietary dataset, we evaluated it on the public PVELAD dataset, which contains near-infrared images of solar panels with various defects. The results confirm our model’s robustness.

Table 4: Generalization Test on the Public PVELAD Dataset
Model mAP@0.5 (%) Params (M)
YOLOv8n 85.0 5.7
SN-YOLOv8 (Ours) 88.9 3.9

SN-YOLOv8 achieves a significant 3.9% improvement in mAP over the baseline YOLOv8n on this external dataset, while maintaining its lightweight advantage. This demonstrates that the architectural improvements are not dataset-specific and can generalize well to different imaging conditions and defect types across solar panels.

Conclusion

In this work, we presented SN-YOLOv8, a highly efficient and accurate algorithm tailored for the defect detection of solar panels. By integrating a suite of innovative components—the StarNet backbone for lightweight feature extraction, Triplet attention for cross-dimensional feature refinement, the SPPF-AM module for enhanced multi-scale context, the C2f_DSConv2D block for efficient feature fusion, the SCAM module for background suppression, and the ECIoU loss for precise localization—we have successfully addressed the key challenges of model size, computational cost, and detection accuracy in a unified framework.

Extensive experiments on a custom solar panel defect dataset and a public benchmark validate the effectiveness of our approach. SN-YOLOv8 reduces the parameter count by 35% and computational load by 29.6% compared to the baseline YOLOv8n, while simultaneously increasing the mAP@0.5 by 4.2% to 89.7% and achieving a leading precision of 90.1%. This exceptional performance-efficiency trade-off makes it a compelling choice for practical deployment in resource-constrained environments, such as onboard drones for automated solar farm inspection.

Future work will focus on further optimizing the detection of specific defect types like hot spots and micro-cracks, potentially through targeted data augmentation or dedicated detection heads. Additionally, we plan to implement hardware-aware optimizations and deploy the model on embedded systems to validate its performance in real-time field applications for the maintenance and monitoring of solar panels.

Scroll to Top