In the manufacturing process of solar panels, various defects such as cracks, broken grids,残缺 (incompleteness), and black spots can occur due to工艺 influences. These defects not only reduce power generation efficiency but also pose fire risks, making defect detection a critical环节. Traditional methods, including manual inspection and machine vision, face challenges such as subjectivity and limited algorithmic ability to extract缺陷 information from vast data. Deep learning has emerged as a viable solution for solar panel surface defect detection, with目标检测 algorithms like YOLO and Faster R-CNN offering direct category probability and location坐标 outputs. However, these methods often struggle with multi-scale and multi-object defect detection, especially for small targets, leading to missed detections and inefficiencies. To address these issues, we propose a novel defect detection network based on a multi-scale attention mechanism, extending the Swin-Transformer framework. Our approach enhances multi-scale information acquisition, improves network efficiency through lightweight design, and incorporates advanced loss functions for better small-target detection. This article details our methodology, experiments, and results, demonstrating significant improvements in accuracy and speed for solar panel defect detection.

The importance of solar panel defect detection cannot be overstated, as defects directly impact energy output and safety. Solar panels, or photovoltaic panels, are widely used in renewable energy systems, and their quality assurance is paramount. Traditional inspection methods rely on human视觉, which is time-consuming and prone to errors, while conventional machine vision algorithms lack the sophistication to handle complex defect patterns in solar panels. With the advent of deep learning, convolutional neural networks (CNNs) and Transformer-based models have shown promise in automating defect detection. However, existing networks like Swin-Transformer, while effective in capturing global relationships through self-attention, suffer from high computational costs and poor performance on small defects in solar panels. Our work aims to overcome these limitations by introducing a multi-scale拓展注意力 mechanism, lightweight convolutions, and a normalized Wasserstein distance loss, tailored for solar panel applications.
In this paper, we first review related technologies, including Swin-Transformer and path aggregation networks, to establish the foundation. Then, we present our proposed MEAN-Transformer network, detailing its architecture, components, and mathematical formulations. We conduct extensive experiments on a solar panel defect dataset, comparing our method with state-of-the-art algorithms. The results show that our approach achieves higher accuracy and faster inference times, making it suitable for real-time solar panel inspection. We also provide ablation studies to validate each改进点, ensuring the robustness of our design. Throughout, we emphasize the practical implications for solar panel manufacturing and maintenance, highlighting how our method can enhance quality control processes.
To begin, let us consider the Swin-Transformer network, which serves as the backbone for many vision tasks. Swin-Transformer employs window-based self-attention to capture long-range dependencies in images, but its fixed window size may miss multi-scale features crucial for solar panel defects. The network consists of Swin-Transformer Blocks, each with a depthwise separable convolution module and a Transformer module. The feature fusion network uses a path aggregation structure (FPN and PAN) to combine semantic and positional features. However, for solar panel defects, which vary in scale from large cracks to tiny black spots, this setup may not suffice. We propose modifications to address these gaps, focusing on expanding the receptive field and reducing computational overhead.
Our proposed MEAN-Transformer network introduces several key innovations. First, we replace the standard Swin-Transformer Block with a MEAN-Transformer Block, which incorporates a multi-scale extension attention mechanism (MEAM). This mechanism groups feature maps and applies sparse attention across different heads, allowing the network to capture context at various scales. Mathematically, for a query matrix $Q$, key matrix $K$, and value matrix $V$, the MEAM operation is defined as:
$$M = \text{MEAM}(Q, K, V, r)$$
where $r \in \mathbb{N}^+$ is the膨胀速率 controlling the sparsity. For a query at position $(i, j)$, the attention is computed over a sliding window of size $w \times w$ with sparse selection of keys and values. The output for each head $r$ is given by:
$$X_i^r = \text{Attention}(q_{ij}, K_r, V_r) = \text{Softmax}\left(\frac{q_{ij} K_r^T}{\sqrt{d_k}}\right) \cdot V_r \quad \text{for } 1 \leq r \leq 3$$
and for the fourth head:
$$X_i^4 = \text{Attention}(q_{ij}, K, V) = \text{Softmax}\left(\frac{q_{ij} K^T}{\sqrt{d_k}}\right) \cdot V_r$$
The heads are cascaded to refine features progressively:
$$X’_{i}^{r} = X_i^r + \Delta X_i^{(r-1)} \quad \text{for } 1 < r \leq 4$$
and the final output is concatenated:
$$X_{i+1} = \text{Concat}[\Delta X_i^r]_{r=1:4}$$
This design enables the MEAN-Transformer Block to integrate local and global information, enhancing multi-scale feature extraction for solar panel defects. Additionally, we incorporate a depthwise separable convolution at the beginning to adapt位置编码 to different resolutions, followed by a multi-layer perceptron (MLP) for non-linear transformations. The overall block structure can be summarized as:
$$M = \text{DwConv}(\hat{M}) + \hat{M}$$
$$Y = \text{MSDA}(\text{Norm}(M)) + M$$
$$Z = \text{MLP}(\text{Norm}(Y)) + Y$$
where MSDA denotes the multi-scale sparse attention mechanism. This block reduces computational complexity compared to standard self-attention, making it efficient for processing high-resolution images of solar panels.
Second, we enhance the feature fusion network by introducing a shallow-scale feature map of size $128 \times 128$. This addition helps capture fine-grained details of small defects in solar panels, which are often lost in deeper layers. We integrate this into the path aggregation network, combining top-down and bottom-up pathways to fuse semantic and positional features. To further lightweight the network, we replace standard convolutions with partial convolutions (PConv). PConv applies filters only to a subset of input channels, reducing redundancy and computation. The computational cost of PConv is approximately one-fourth of regular convolutions, which speeds up inference without significant accuracy loss. The structure of PConv is illustrated in our network diagram, and it is implemented in the feature fusion layers to maintain spatial features while minimizing parameters.
Third, we address the small-target detection problem by modifying the loss function. Traditional IoU-based losses are sensitive to minor positional deviations for tiny defects in solar panels, leading to poor optimization. We adopt the Normalized Gaussian Wasserstein Distance (NWD) as a regression loss. This metric models bounding boxes as 2D Gaussian distributions and measures similarity using the Wasserstein distance. For a predicted box $P = (cx_p, cy_p, w_p, h_p)$ and a ground truth box $G = (cx_g, cy_g, w_g, h_g)$, the Gaussian distributions are parameterized by their means and covariances. The squared Wasserstein distance is:
$$W_2^2(N_p, N_g) = \left\| \left[ cx_p, cy_p, \frac{w_p}{2}, \frac{h_p}{2} \right]^T, \left[ cx_g, cy_g, \frac{w_g}{2}, \frac{h_g}{2} \right]^T \right\|_2^2$$
The NWD is then computed as:
$$\text{NWD}(N_p, N_g) = \exp\left(-\frac{W_2^2(N_p, N_g)}{C}\right)$$
where $C$ is a dataset-dependent constant. The loss function becomes:
$$L_{\text{NWD}} = 1 – \text{NWD}(N_p, N_g)$$
This loss is more robust to small目标位置偏差, improving detection accuracy for minor defects like black spots and fine cracks in solar panels.
To evaluate our proposed MEAN-Transformer network, we conducted experiments on a solar panel defect dataset comprising approximately 3000 images. The defects are categorized into five classes: fine lines, black spots, scratches, broken grids, and incompleteness. We split the dataset into training, validation, and test sets in a 6:2:2 ratio. Our experimental setup uses a Windows 10 system with an NVIDIA 3060Ti GPU, PyTorch 1.6 framework, and Python programming. Training parameters include a batch size of 32, 50 epochs, an initial learning rate of 0.01 adjusted to 0.001 after 20 epochs, and weight decay of 0.0002. We assess performance using mean average precision (mAP), frames per second (FPS), and parameter count (Params).
The ablation studies demonstrate the impact of each改进点. We start with the baseline Swin-Transformer and incrementally add components: MEAM, enhanced feature fusion, PConv, and NWD loss. The results are summarized in Table 1 below.
| Group | MEAM | PANnet | PConv | NWD | mAP (%) | Params (MB) | FPS |
|---|---|---|---|---|---|---|---|
| Swin-Transformer | 84.6 | 133.6 | 39.5 | ||||
| A | ✓ | 84.9 | 135.5 | 38.7 | |||
| B | ✓ | ✓ | 85.2 | 133.4 | 39.9 | ||
| C | ✓ | ✓ | ✓ | 84.8 | 124.7 | 42.1 | |
| D (Our full model) | ✓ | ✓ | ✓ | ✓ | 85.7 | 124.7 | 42.1 |
Table 1 shows that adding MEAM (Group A) improves mAP by 0.3% but increases parameters slightly and reduces FPS. Incorporating the enhanced feature fusion (Group B) boosts mAP further to 85.2% while reducing parameters, indicating better feature extraction for solar panel defects. Using PConv (Group C) significantly reduces parameters to 124.7 MB and increases FPS to 42.1, albeit with a minor mAP drop. Finally, introducing the NWD loss (Group D) restores and enhances mAP to 85.7%, maintaining the lightweight benefits. This confirms that our combined approach balances accuracy and efficiency for solar panel defect detection.
We also compare our MEAN-Transformer network with other state-of-the-art methods, including Faster R-CNN, Swin-Transformer, and YOLOv5, on the same solar panel dataset. The results are presented in Table 2.
| Methods | mAP (%) | Params (MB) | FPS |
|---|---|---|---|
| Faster R-CNN | 79.7 | 180.4 | 16.4 |
| Swin-Transformer | 84.6 | 133.6 | 39.5 |
| YOLOv5 | 84.5 | 107.7 | 42.7 | Our MEAN-Transformer | 85.7 | 124.7 | 42.5 |
Our method achieves the highest mAP of 85.7%, outperforming all others. While YOLOv5 has slightly lower parameters and higher FPS, its mAP is lower, making our approach more accurate for solar panel inspection. Faster R-CNN lags in both accuracy and speed due to its two-stage design. Swin-Transformer is competitive but less efficient. Our network thus offers a superior balance, suitable for real-time applications in solar panel manufacturing lines.
To provide deeper insights, we analyze the detection performance across different defect types in solar panels. The five classes—fine lines, black spots, scratches, broken grids, and incompleteness—pose varying challenges. Small defects like fine lines and black spots require high-resolution features, which our multi-scale attention mechanism captures effectively. Larger defects such as scratches and broken grids benefit from the global context provided by the Transformer blocks. We calculate per-class average precision (AP) to illustrate this, as shown in Table 3.
| Defect Class | AP (%) | Improvement over Baseline |
|---|---|---|
| Fine Lines | 86.2 | +1.8% |
| Black Spots | 87.5 | +2.3% |
| Scratches | 84.9 | +1.5% |
| Broken Grids | 85.0 | +1.2% |
| Incompleteness | 85.1 | +1.1% |
The improvements are consistent across all classes, with the most significant gains for black spots and fine lines, which are often small and challenging. This underscores the effectiveness of our multi-scale approach and NWD loss for solar panel defects.
Furthermore, we explore the computational complexity of our network. The MEAN-Transformer Block reduces the number of operations compared to standard self-attention. For an input feature map of size $H \times W \times C$, the computational cost of MEAM can be approximated as:
$$\text{Complexity} = O\left( \sum_{r=1}^{4} N_r \cdot d_k \right)$$
where $N_r$ is the number of sparse key-value pairs for head $r$, and $d_k$ is the key dimension. This is lower than the $O(HW \cdot C^2)$ of full self-attention, making it scalable for high-resolution solar panel images. The use of PConv further reduces the cost in the feature fusion network. We estimate the total浮点运算次数 (FLOPs) for our network and compare it with others in Table 4.
| Network | FLOPs (G) | Parameters (M) | mAP (%) |
|---|---|---|---|
| Faster R-CNN | 180.2 | 180.4 | 79.7 |
| Swin-Transformer | 95.7 | 133.6 | 84.6 |
| YOLOv5 | 75.3 | 107.7 | 84.5 |
| Our MEAN-Transformer | 88.4 | 124.7 | 85.7 |
Our FLOPs are moderate, indicating a good trade-off between computation and accuracy. This efficiency is crucial for deploying the model in resource-constrained environments, such as embedded systems for solar panel inspection drones or production lines.
In addition to quantitative results, we provide qualitative analysis through detection examples. Our network successfully identifies multiple defects in solar panels, including overlapping and small targets, whereas baseline methods often miss them. For instance, in images with both black spots and scratches, our method generates precise bounding boxes, while others produce false positives or omissions. This visual assessment confirms the practical utility of our approach for real-world solar panel quality control.
The success of our method can be attributed to several factors. The multi-scale attention mechanism expands the receptive field without excessive computation, allowing the network to capture defects at various sizes in solar panels. The lightweight design with PConv maintains speed without sacrificing accuracy. The NWD loss function mitigates the issues with small目标检测, which is common in solar panel defects like micro-cracks. Together, these innovations address the core challenges in automated solar panel inspection.
Looking ahead, there are opportunities for further improvement. For example, integrating domain adaptation techniques could enhance the model’s robustness to different solar panel types or environmental conditions. Additionally, exploring more advanced attention mechanisms, such as dynamic稀疏注意力, might reduce computation further. We also plan to extend our work to video-based defect detection for continuous monitoring of solar panel installations. The potential applications in solar energy maintenance are vast, and our method provides a strong foundation.
In conclusion, we have presented a novel defect detection network for solar panels based on a multi-scale attention mechanism. Our MEAN-Transformer network improves upon Swin-Transformer by incorporating MEAM blocks, lightweight convolutions, and an NWD loss function. Experimental results on a solar panel defect dataset show that our method achieves superior accuracy (85.7% mAP) and real-time speed (42.5 FPS), with reduced parameters compared to baseline. The ablation studies validate the contribution of each component, and comparisons with other methods highlight our advantages. This work demonstrates the effectiveness of deep learning for solar panel inspection and paves the way for more efficient and reliable quality assurance in the solar energy industry. We believe that our approach can significantly impact the manufacturing and maintenance of solar panels, contributing to the adoption of renewable energy sources worldwide.
To reiterate, the key takeaways are: (1) Multi-scale attention is essential for capturing diverse defects in solar panels; (2) Lightweight designs like PConv can enhance efficiency without compromising performance; (3) Advanced loss functions like NWD are crucial for small-target detection in solar panels. We hope that this research inspires further innovations in solar panel defect detection and related fields.
Finally, we note that our code and dataset will be made available to facilitate reproducibility and future research. We encourage the community to build upon our work to advance the state of solar panel inspection technology. The integration of AI into renewable energy systems holds great promise, and we are excited to contribute to this journey.
