Photovoltaic solar panels are critical components in renewable energy systems, but they often suffer from internal defects such as cracks, black spots, broken grids, and thick lines during manufacturing or long-term operation. These defects reduce power generation efficiency and may lead to system failures. Traditional detection methods, including manual inspection and non-destructive testing, are either subjective or inefficient when dealing with large-scale data. Deep learning-based object detection has emerged as a promising solution, yet challenges remain due to the small size of solar panel defects, large variations in their scales, and complex background interference. To address these issues, we propose an improved model named YOLO-RMFP, built upon the YOLOv8n framework. The model integrates a novel receptive field mixed attention mechanism, an enhanced spatial pyramid pooling module, a multi-scale feature fusion pyramid network, and a refined loss function to significantly boost detection accuracy and robustness for solar panel defects.

1. Receptive Field Mixed Attention (RFMA)
To enhance the model’s ability to focus on multi-scale features of solar panel defects while overcoming the parameter-sharing limitations of conventional multi-scale attention (e.g., EMA), we designed the RFMA module. It integrates an efficient multi-scale attention mechanism with receptive field attention. The input feature map is first split into groups via grouped convolution and normalization, yielding \(X = [X_0, X_1, \ldots, X_{G-1}], X_i \in \mathbb{R}^{(C/G) \times K_H \times K_W}\). Then, two parallel paths are employed: a 1×1 branch and a 3×3 branch.
In the 1×1 branch, 1D max-pooling is applied along horizontal and vertical directions to encode channel-wise information. For the horizontal direction, the operation is defined as:
$$z_{H}^{(C)}(H) = \max_{K_W} x_c(H, i) \tag{1}$$
After concatenating the two encoded results, a shared 1×1 convolution decomposes them into two vectors, followed by Sigmoid activation and another 1×1 convolution. The outputs are multiplied with the original input to produce the 1×1 branch result.
In the 3×3 branch, a 3×3 convolution captures multi-scale representation. The outputs of both branches then enter a cross-space learning stage. The 1×1 and 3×3 branch outputs are reshaped to the dimensions of 2D max-pooling, and then processed via 2D max-pooling:
$$z_c = \max_{K_H} \max_{K_W} x_c(i, j) \tag{2}$$
A Softmax function is applied to fit the pooled results, and Matmul matrix multiplication generates two spatial attention weight sets. These weights are summed and passed through a Sigmoid function to obtain the final feature map. Element-wise multiplication with the grouped convolution output followed by a convolution yields the RFMA output. This design allows the model to adaptively adjust receptive fields and emphasize critical regions, significantly improving the detection of tiny solar panel defects such as micro-cracks and hidden cracks.
2. SPPRFMA Module
We integrated the RFMA mechanism into the Spatial Pyramid Pooling Fast (SPPF) module of YOLOv8n via a residual connection, creating the SPPRFMA module. The original SPPF efficiently extracts multi-scale features through pooling kernels of different sizes. By adding RFMA, the module gains the ability to dynamically adjust receptive fields and assign weights to features, effectively suppressing background noise and enhancing focus on small solar panel defects. The structure is illustrated conceptually: after the standard SPPF path, the feature map is processed by RFMA and then combined with the input through residual addition. This improves the model’s sensitivity to subtle defect features and its robustness in complex environments, leading to higher detection accuracy for solar panels.
3. Multi-Scale Feature Fusion Pyramid Network (MSF-FPN)
To improve the fusion of shallow and deep features and reduce information loss for tiny defects across scales, we modified the Multi-Branch Auxiliary Feature Pyramid Network (MBA-FPN) to propose MSF-FPN. It consists of shallow auxiliary fusion and deep auxiliary fusion.
Shallow auxiliary fusion merges features from the same layer, high-resolution shallow details, and deep semantic information across levels. Let \(P_{n-1}, P_n, P_{n+1} \in \mathbb{R}^{H \times W \times C}\) denote feature maps at different resolutions from the backbone. \(U(\cdot)\) denotes upsampling, \(C2F(\cdot)\) denotes the C2F module, and \(C(\cdot)\) denotes convolution downsampling. The shallow fusion is expressed as:
$$
\begin{align}
P’_{n+1} &= \text{Concat}(P_{n+1}, C(P_n)) \\
P’_n &= \text{Concat}(P_n, C(P_{n-1}), U(C2F(P’_{n+1}))) \\
P’_{n-1} &= \text{Concat}(P_{n-1}, C(P_{n-2}), U(C2F(P’_n)))
\end{align} \tag{3}
$$
Deep auxiliary fusion uses cross-layer gradient-dense connections to drive intensive interaction among gradients and feature maps. The enhanced features are computed as:
$$
\begin{align}
P”_{n-1} &= \text{Concat}(P_{n-1}, C2F(P’_{n-1}), U(C2F(P’_n))) \\
P”_n &= \text{Concat}(C(C2F(P’_{n-1})), C(C2F(P”_{n-1})), P_n, C2F(P’_n), U(C2F(P’_{n+1}))) \\
P”_{n+1} &= \text{Concat}(C(C2F(P’_n)), C(C2F(P”_n)), P_{n+1}, C2F(P’_{n+1}))
\end{align} \tag{4}
$$
MSF-FPN preserves rich spatial details and enhances semantic interaction, effectively addressing the multi-scale feature fusion deficiency in solar panel defect detection and significantly improving detection performance.
4. Focaler-PIoU Loss Function
To improve localization accuracy and handle the sample imbalance issue (hard vs. easy defects), we replaced the original CIoU loss with a Focaler-PIoU loss. The PIoU loss uses an adaptive penalty factor \(P\) based on pixel-level differences:
$$P = \left( \frac{dw_1}{w_{gt}} + \frac{dw_2}{w_{gt}} + \frac{dh_1}{h_{gt}} + \frac{dh_2}{h_{gt}} \right) / 4 \tag{5}$$
where \(dw_1, dw_2, dh_1, dh_2\) are absolute distances between corresponding edges of the predicted box and ground truth box, and \(w_{gt}, h_{gt}\) are the ground truth width and height. The penalty function is:
$$f(x) = 1 – e^{-x^2} \tag{6}$$
$$PIoU = IoU – f(P), \quad -1 \le PIoU \le 1 \tag{7}$$
$$L_{PIoU} = 1 – PIoU = L_{IoU} + f(P), \quad 0 \le L_{PIoU} \le 2 \tag{8}$$
We then incorporate the Focaler-IoU idea to adjust the weight of hard samples. The Focaler-IoU maps IoU linearly within an interval \([d, u]\):
$$
IoU_{focaler} =
\begin{cases}
0, & IoU < d \\
\frac{IoU – d}{u – d}, & d \le IoU \le u \\
1, & IoU > u
\end{cases} \tag{9}
$$
The final Focaler-PIoU loss is:
$$L_{Focaler-PIoU} = L_{PIoU} + IoU – IoU_{focaler} \tag{10}$$
This formulation enables the model to focus more on difficult solar panel defect samples (e.g., small cracks) while reducing the influence of easy samples, thereby improving overall detection accuracy.
5. Experimental Setup and Dataset
We built a dataset of solar panel internal defects captured by infrared cameras, containing four types: cracks, black cores, broken grids, and thick lines. The original dataset had 782 images, which we augmented to 3150 images through rotation, noise addition, etc. The dataset was split into training (2520 images), testing (315 images), and validation (315 images) sets. Experiments were conducted on a system with an NVIDIA GeForce RTX 3070 Ti GPU, 32 GB RAM, and PyTorch 2.1.0 with CUDA 12.5. Training parameters are listed in the table below.
| Parameter | Value |
|---|---|
| Epochs | 150 |
| Batchsize | 2 |
| imgsz | 640 |
| lr0 | 0.01 |
| lrf | 0.01 |
6. Results and Analysis
6.1 Comparison with State-of-the-Art Models
We compared YOLO-RMFP with several mainstream object detectors: Faster R-CNN, Mask R-CNN, YOLOv5s, YOLOv7-tiny, YOLOv8n, and YOLOv10n. The evaluation metrics include mAP@0.5 (mean Average Precision at IoU threshold 0.5), frame rate (fps), and computational complexity (GFLOPs). Results are summarized in the following table.
| Model | mAP@0.5 (%) | Frame Rate (fps) | GFLOPs |
|---|---|---|---|
| Faster R-CNN | 86.0 | 52.3 | 134 |
| Mask R-CNN | 86.6 | 48.1 | 187 |
| YOLOv5s | 88.8 | 208.1 | 8.7 |
| YOLOv7-tiny | 84.7 | 103.8 | 13.2 |
| YOLOv8n | 91.1 | 211.1 | 8.1 |
| YOLOv10n | 85.7 | 205.7 | 8.4 |
| YOLO-RMFP | 94.2 | 201.4 | 9.9 |
Our proposed YOLO-RMFP achieves the highest mAP@0.5 of 94.2%, outperforming YOLOv8n by 3.1%, YOLOv5s by 5.4%, and the two-stage methods by over 7.5%. The frame rate of 201.4 fps is slightly lower than YOLOv8n but still well above real-time requirements, demonstrating an excellent trade-off between accuracy and speed for solar panel defect detection.
6.2 Ablation Study
To validate the effectiveness of each proposed component, we conducted ablation experiments by adding SPPRFMA, MSF-FPN, and Focaler-PIoU incrementally to the baseline YOLOv8n. The results are shown in the table below.
| SPPRFMA | MSF-FPN | Focaler-PIoU | mAP@0.5 (%) | mAP@0.5:0.95 (%) | Recall (%) | Precision (%) | Speed (fps) | GFLOPs |
|---|---|---|---|---|---|---|---|---|
| 91.1 | 62.8 | 87.3 | 88.4 | 211.1 | 8.1 | |||
| √ | 91.9 | 64.9 | 88.4 | 88.9 | 203.4 | 8.7 | ||
| √ | 92.3 | 63.4 | 88.5 | 89.0 | 198.3 | 9.1 | ||
| √ | 91.4 | 63.1 | 91.6 | 83.9 | 223.3 | 8.1 | ||
| √ | √ | 93.5 | 65.1 | 90.7 | 89.1 | 194.6 | 9.9 | |
| √ | √ | 92.2 | 64.6 | 87.5 | 89.0 | 205.7 | 8.7 | |
| √ | √ | 92.7 | 65.3 | 88.5 | 87.9 | 203.5 | 8.9 | |
| √ | √ | √ | 94.2 | 69.3 | 90.8 | 92.6 | 201.4 | 9.9 |
When all three modules are combined, mAP@0.5 improves by 3.1%, mAP@0.5:0.95 by 6.5%, recall increases by 3.5%, and precision by 4.2%. The speed decreases slightly but remains practical. Each module contributes positively: SPPRFMA enhances multi-scale feature extraction; MSF-FPN improves cross-layer fusion; Focaler-PIoU boosts recall and precision for hard samples.
6.3 Robustness Test
We evaluated the robustness of YOLO-RMFP against various perturbations: contrast enhancement, Gaussian noise, image rotation (90°), and flipping. The detection accuracy for cracks and broken grids under these conditions is compared with baseline YOLOv8n.
| Defect Type | Disturbance | YOLOv8n | YOLO-RMFP |
|---|---|---|---|
| Crack | Contrast Enhancement | 78 | 92 |
| Noise | 60 | 90 | |
| Flip | 67 | 84 | |
| Rotation 90° | 88 | 90 | |
| Broken Grid | Contrast Enhancement | 75 | 88 |
| Noise | 55 | 85 | |
| Flip | 62 | 80 | |
| Rotation 90° | 70 | 82 |
YOLO-RMFP consistently outperforms YOLOv8n under all disturbances, with improvements of 10–30% in certain scenarios. In particular, the proposed model maintains high accuracy even with severe noise, indicating strong robustness for real-world solar panel inspection.
7. Conclusion
In this work, we presented YOLO-RMFP, an improved detection model specifically designed for solar panel defects. By introducing the RFMA attention mechanism, SPPRFMA module, MSF-FPN, and Focaler-PIoU loss, we significantly enhanced the model’s ability to detect small-scale, multi-variant defects under complex backgrounds. Experimental results demonstrate that YOLO-RMFP achieves a mAP@0.5 of 94.2%, with precision and recall of 92.6% and 90.8%, respectively, surpassing other state-of-the-art detectors. The model also exhibits strong robustness against common image distortions. Although the computational cost increased slightly, the overall balance between accuracy and speed is well-suited for practical applications. Future work will focus on further optimizing inference speed and reducing model size to facilitate deployment on edge devices for real-time solar panel defect monitoring.
