In the context of the global energy transition, the efficient and accurate detection of defects in solar panels is critical for ensuring the reliability and longevity of photovoltaic systems. This paper presents an improved YOLOv8-based algorithm for detecting cracks, grid breaks, and spot defects on solar panels. The proposed method integrates three key enhancements: a novel C2f-MS module that reduces parameter count and computational cost while enhancing multi-scale feature extraction, the incorporation of Normalized Gaussian Wasserstein Distance (NWD) into the loss function to improve small target detection, and the replacement of standard Non-Maximum Suppression (NMS) with Soft-NMS to reduce false positives in dense scenarios. Extensive experiments on a proprietary dataset of solar panels defects demonstrate that the proposed algorithm achieves a mAP@50 of 89.5% and mAP@[0.5:0.95] of 49.8%, while reducing parameters by 9.57% and FLOPs by 6.1% compared to the baseline YOLOv8n. The results show that our method not only improves detection accuracy but also offers a lighter model suitable for real-world deployment on edge devices.
1. Introduction
The rapid adoption of solar panels as a renewable energy source has necessitated robust quality control measures to identify defects such as cracks, grid breaks, and dirt spots during manufacturing and operation. Traditional manual inspection is time-consuming and error-prone, prompting the shift toward automated computer vision methods. Deep learning-based object detection, particularly the YOLO family, has shown promise due to its real-time performance and high accuracy. However, existing models often struggle with small defects, high computational cost, and excessive parameters, making them less suitable for deployment on resource-constrained devices. To address these challenges, we propose an improved YOLOv8n model tailored for solar panels defect detection. Our contributions include:
- A novel C2f-MS module that employs multi-scale depthwise separable convolutions to reduce model complexity while capturing richer multi-scale features.
- Integration of Normalized Gaussian Wasserstein Distance (NWD) into the CIoU loss to enhance sensitivity toward small defects common in solar panels.
- Replacement of NMS with Soft-NMS to mitigate false positives in clustered defect regions.
- Comprehensive ablation studies and comparisons with state-of-the-art models demonstrate superior performance in terms of accuracy, parameter count, and computational load.
2. Related Work
Defect detection in solar panels has been explored using various deep learning architectures. Early works employed two-stage detectors like Faster R-CNN, but they suffer from slower inference speeds. One-stage detectors like YOLOv3, YOLOv5, and YOLOv7 have been adapted for solar panel inspection by incorporating attention mechanisms, feature pyramid networks, and lightweight modules. For instance, Li et al. (2023) fused attention with multi-scale features to detect defects. Zhou et al. (2022) used YOLOv3 with K-means clustering for solar panel EL images. More recently, improved YOLOv5 variants introduced GhostConv and SE attention to reduce parameters. However, these methods either fail to handle tiny defects or still have relatively high computational burdens. Our work builds upon YOLOv8n, the latest lightweight YOLO version, and enhances it with multi-scale feature fusion, a loss function robust to small objects, and a more intelligent suppression mechanism.
3. Proposed Method
The baseline YOLOv8n architecture consists of a backbone (Conv, SPPF, C2f), a neck (Upsample, Concat, C2f), and a decoupled head. We introduce three modifications to improve its performance on solar panels defect detection.
3.1 Improved C2f Module: C2f-MS
The standard C2f module in YOLOv8 uses standard convolutions, which are computationally expensive. Inspired by depthwise separable convolution and scale-aware modulation, we design a new multi-scale convolution block called MSConv. As illustrated in the following structure (not shown), MSConv splits the input channels into three groups: half of the channels are left untouched (identity mapping), one quarter are convolved with a 3×3 kernel, and the remaining quarter with a 5×5 kernel. All branches are then concatenated and fused via a 1×1 convolution. This design captures multi-scale spatial information while significantly reducing computational cost. The new C2f-MS module replaces the original C2f in the backbone and neck only for layers where the channel count exceeds 512, as these layers contribute most to the model’s complexity.
The computational complexity of a standard convolution with kernel size k, input channels C_in, output channels C_out, and spatial size H×W is:
$$ FLOPs_{conv} = k^2 \cdot C_{in} \cdot C_{out} \cdot H \cdot W $$
For the proposed MSConv, with half channels identity, quarter 3×3, and quarter 5×5, the total FLOPs become:
$$ FLOPs_{MSConv} = \left( \frac{1}{4}C_{in} \cdot 9 + \frac{1}{4}C_{in} \cdot 25 \right) \cdot C_{out} \cdot H \cdot W = \frac{34}{4}C_{in}C_{out}HW = 8.5 C_{in}C_{out}HW $$
Compared to a standard 3×3 convolution (9·C_in·C_out·H·W) or 5×5 convolution (25·C_in·C_out·H·W), MSConv is more parameter-efficient while benefiting from multi-scale features. Additionally, the ablation study in Table 1 shows optimal performance when using kernel sizes [3,5] and replacing C2f in high-channel layers.
| Kernel Sizes [k1,k2] | Type I (channels>512) | Type II (channels<512) | Type III (all) | |||
|---|---|---|---|---|---|---|
| mAP@50 | mAP@[0.5:0.95] | mAP@50 | mAP@[0.5:0.95] | mAP@50 | mAP@[0.5:0.95] | |
| [1,3] | 0.886 | 0.458 | 0.857 | 0.443 | 0.853 | 0.432 |
| [1,5] | 0.881 | 0.454 | 0.870 | 0.443 | 0.880 | 0.443 |
| [1,7] | 0.882 | 0.447 | 0.872 | 0.447 | 0.861 | 0.435 |
| [3,5] | 0.887 | 0.453 | 0.882 | 0.454 | 0.871 | 0.452 |
| [3,7] | 0.866 | 0.446 | 0.871 | 0.446 | 0.870 | 0.445 |
| [5,7] | 0.882 | 0.448 | 0.868 | 0.447 | 0.882 | 0.459 |
3.2 NWD Loss for Small Object Detection
The original YOLOv8 uses CIoU loss, which relies on Intersection over Union (IoU). However, for small defects on solar panels (e.g., tiny cracks or spots), IoU is highly sensitive to pixel shifts and becomes zero when predictions do not overlap with ground truth, hindering gradient propagation. To overcome this, we incorporate Normalized Gaussian Wasserstein Distance (NWD). NWD models bounding boxes as 2D Gaussian distributions and computes the Wasserstein distance between them. The normalized distance is defined as:
$$ \zeta_{NWD}(N_a, N_b) = \exp\left( -\frac{\sqrt{W_2^2(N_a, N_b)}}{C} \right) $$
where C is a dataset-dependent constant, and W_2^2 is the 2nd-order Wasserstein distance. NWD is sensitive to both position and shape, and it provides non-zero gradients even when boxes do not overlap, making it ideal for small targets. We combine NWD with the original CIoU loss as a weighted addition to maintain overall convergence speed while improving small object detection. The final loss becomes:
$$ L_{total} = L_{CIoU} + \lambda \cdot L_{NWD} $$
where λ is a balancing hyperparameter (set to 0.5 in our experiments).
3.3 Soft-NMS for Dense Defects
Standard NMS greedily suppresses all boxes with IoU above a threshold (e.g., 0.7) relative to the highest-scoring box. In solar panels defect images, multiple defects may appear in close proximity, causing NMS to incorrectly discard valid detections. Soft-NMS addresses this by decaying the confidence scores of overlapping boxes rather than removing them outright. The decay function is Gaussian:
$$ s_i = s_i \cdot e^{-\frac{IoU(\mathcal{M}, b_i)^2}{\sigma}}, \quad \forall b_i \notin \mathcal{D} $$
where s_i is the score of box b_i, M is the highest-scoring box, and σ is a hyperparameter (set to 0.5). This allows multiple overlapping detections to survive if they have high confidence, thus improving recall in crowded scenarios. Soft-NMS replaces NMS in the post-processing step of YOLOv8.
4. Experiments and Results
4.1 Dataset and Implementation Details
We use a dataset of 600 original images of solar panels defects obtained from PP PaddlePaddle (AI Studio), including three defect types: cracks, grid breaks, and dirt spots. Data augmentation (flip, rotation) expanded the dataset to 2400 images, split into 1920 training and 480 validation images. All images are resized to 640×640. Experiments are conducted on an Ubuntu 20.04 system with an NVIDIA RTX 3070 Ti 8GB GPU, CUDA 11.7, PyTorch 1.13.1. Training hyperparameters: initial learning rate 0.01, momentum 0.937, optimizer AdamW, IoU threshold 0.7, batch size 32, and 8 workers.
4.2 Ablation Studies
We perform ablation experiments to evaluate the contribution of each proposed improvement. Results are shown in Table 2.
| C2f-MS | NWD | Soft-NMS | Parameters (10^6) | GFLOPs | mAP@50 (%) | mAP@[0.5:0.95] (%) | FPS |
|---|---|---|---|---|---|---|---|
| ✗ | ✗ | ✗ | 3.0 | 8.2 | 87.0 | 45.7 | 76.34 |
| ✓ | ✗ | ✗ | 2.7 | 7.7 | 88.7 | 45.3 | 66.67 |
| ✗ | ✓ | ✗ | 3.0 | 8.2 | 88.0 | 45.5 | 76.34 |
| ✗ | ✗ | ✓ | 3.0 | 8.2 | 88.8 | 49.2 | 67.11 |
| ✓ | ✓ | ✗ | 2.7 | 7.7 | 89.0 | 46.1 | 64.94 |
| ✓ | ✓ | ✓ | 2.7 | 7.7 | 89.5 | 49.8 | 59.88 |
Key observations: (1) Each individual improvement boosts mAP@50. (2) Soft-NMS contributes most to mAP@[0.5:0.95] due to its ability to retain overlapping detections. (3) The combination of all three yields the best accuracy, with mAP@50 increasing by 2.5% (from 87.0% to 89.5%) and mAP@[0.5:0.95] by 4.1% (from 45.7% to 49.8%), while parameters drop by 9.57% and GFLOPs by 6.1%. FPS decreases slightly due to the additional Soft-NMS computation but remains acceptable for real-time applications.
4.3 Comparison with State-of-the-Art
We compare our proposed method with several baseline models: YOLOv3, YOLOv3-Tiny, YOLOv5s, YOLOv7, YOLOv7-Tiny, and the method of Li et al. [6]. Results are summarized in Table 3.
| Model | Parameters (10^6) | GFLOPs | mAP@50 (%) | mAP@[0.5:0.95] (%) |
|---|---|---|---|---|
| Li et al. [6] | 49.6 | 299.3 | 76.2 | 41.3 |
| YOLOv3 | 103.7 | 283.0 | 89.3 | 47.9 |
| YOLOv3-Tiny | 12.1 | 19.0 | 86.9 | 43.5 |
| YOLOv5s | 9.1 | 24.0 | 86.9 | 45.5 |
| YOLOv7 | 37.2 | 105.1 | 86.5 | 43.6 |
| YOLOv7-Tiny | 6.0 | 13.2 | 80.4 | 38.3 |
| Ours | 2.7 | 7.7 | 89.5 | 49.8 |
Our method achieves the highest mAP@50 and mAP@[0.5:0.95] with the smallest model size (only 2.7M parameters, 7.7 GFLOPs). Compared to YOLOv3, our mAP@50 is comparable but with 38× fewer parameters. The lightweight nature makes our model ideal for embedded deployment on edge devices inspecting solar panels in real-time.
4.4 Qualitative Analysis
Figure 1 (below) shows qualitative detection results on sample images of solar panels defects. The proposed method correctly detects all three defect types (crack, grid break, spot) with higher confidence scores compared to the baseline YOLOv8n. In the original label (top row), only ground truth boxes are shown. The second row shows YOLOv8n predictions, which produce multiple redundant boxes for the same defect and occasionally miss a small spot. Our method (third row) eliminates duplicate boxes and captures small defects that were previously missed. This demonstrates the effectiveness of Soft-NMS in reducing false positives and the NWD loss in improving small object detection.

5. Conclusion
In this work, we presented an improved YOLOv8-based algorithm for detecting defects in solar panels. By introducing the C2f-MS module, we reduced model parameters and FLOPs while enhancing multi-scale feature representation. The integration of NWD loss significantly improved the detection of small defects, and Soft-NMS effectively suppressed false positives in dense defect regions. Ablation and comparison experiments demonstrate that our method achieves superior accuracy (89.5% mAP@50, 49.8% mAP@[0.5:0.95]) with a much lighter architecture (2.7M parameters, 7.7 GFLOPs) compared to existing models. This makes it highly suitable for real-time defect inspection of solar panels in industrial and field environments. Future work will extend the dataset to include more defect types and further optimize the model for edge deployment.
