In the manufacturing process of solar panels, various surface defects such as cracks, broken fingers, incomplete parts, and black spots can occur due to production techniques. These defects significantly reduce power generation efficiency and even pose fire risks. Therefore, detecting such defects accurately and in real time is a critical production requirement. Traditional methods, including manual inspection and machine vision, suffer from subjectivity or insufficient ability to extract limited defect information from massive data. With the rise of deep learning, defect detection for solar panels has become a viable solution. In this work, I propose a novel detection network based on a multi-scale attention mechanism built on Swin-Transformer. The network aims to address the challenges of multi-scale and multi-object defect detection for solar panels, achieving improved accuracy and speed while maintaining lightweight characteristics.
The core of my approach is to replace the original Swin-Transformer blocks with MEAN-Transformer blocks (Multi-scale Extension of Attention Mechanism). This modification expands the receptive field and captures richer multi-scale features of solar panel defects. In the feature fusion network, I integrate a 128×128 shallow scale feature map and adopt partial convolution (PConv) instead of depthwise separable convolution to reduce computational cost. Furthermore, I introduce the Normalized Gaussian Wasserstein Distance (NWD) as the regression loss function to enhance the detection capability for tiny defects. Extensive experiments demonstrate that my method achieves 85.7% mAP with 124.7 MB parameters and 42.1 FPS, satisfying real-time requirements and improving multi-scale multi-category recognition accuracy.
1. Introduction
Solar panels are widely used in renewable energy systems. During their production, defects like cracks, finger breaks, black spots, and incomplete edges often appear. These defects not only lower the efficiency of power conversion but also create safety hazards. Manual inspection is subjective and inefficient, while conventional machine vision lacks the algorithmic power to extract defect features from massive samples. Deep learning, especially convolutional neural networks (CNNs) and transformers, offers a promising alternative for automated defect detection on solar panels.
Object detection algorithms are typically categorized into one-stage detectors (e.g., YOLO series) and two-stage detectors (e.g., Faster R-CNN). One-stage detectors directly map input images to output bounding boxes and class probabilities, while two-stage detectors first generate region proposals and then classify and refine each proposal. Recently, transformer-based architectures, such as Swin-Transformer, have demonstrated strong performance in visual tasks by leveraging self-attention to capture global context. However, applying Swin-Transformer to solar panel defect detection still faces challenges: large computational overhead and insufficient detection of small defects. In this paper, I propose a multi-scale attention mechanism to overcome these limitations, specifically tailored for detecting various defect types on solar panels at different scales.
The contributions of my work are summarized as follows:
- I replace the standard Swin-Transformer blocks with MEAN-Transformer blocks that incorporate multi-scale expansion of attention to better capture both local and global features of solar panel defects.
- I redesign the feature fusion network by adding a 128×128 shallow feature layer and using partial convolution (PConv) to reduce computational cost while preserving accuracy.
- I adopt the Normalized Gaussian Wasserstein Distance (NWD) as the regression loss function, which is more robust for tiny defect detection on solar panels.
- Extensive ablation and comparison experiments confirm that my method outperforms existing detectors in terms of mAP, parameter count, and speed.
2. Related Work
2.1 Swin-Transformer
Swin-Transformer is a hierarchical transformer backbone that uses shifted windows to compute self-attention efficiently. The backbone consists of several Swin-Transformer blocks, each containing a window-based multi-head self-attention (W-MSA) module and a multi-layer perceptron (MLP). The window shifting strategy enables cross-window connections, allowing the model to capture long-range dependencies. However, for solar panel defect detection, the fixed window size limits the ability to handle defects of varying sizes, especially very small ones. Moreover, the computational cost remains high when processing high-resolution images of solar panels.
2.2 Path Aggregation Network (PAN)
Path Aggregation Network (PAN) is a feature fusion architecture that integrates features from different levels of the backbone. It includes a top-down path (FPN) to propagate strong semantic features and a bottom-up path to propagate strong localization features. By combining these paths, PAN produces a multi-scale feature pyramid that is beneficial for detecting objects of various sizes. In my work, I extend PAN by adding an extra shallow layer (128×128 resolution) and replacing standard convolutions with partial convolutions to further enhance multi-scale defect detection on solar panels.
3. Proposed Method
3.1 Overall Architecture

The proposed network, named MEAN-Transformer, is built upon Swin-Transformer but with three major improvements. First, the Swin-Transformer blocks are replaced by MEAN-Transformer blocks, which employ multi-scale expanded attention. Second, the feature fusion network is modified: I add a 128×128 shallow feature map and use PConv to reduce computations. Third, the loss function is changed from IoU-based to NWD-based to better handle small defects. The complete architecture is illustrated conceptually above (the figure shows a solar panel with potential defects).
3.2 MEAN-Transformer Block
The MEAN-Transformer block is the core component for feature extraction. It combines depthwise convolution with a multi-scale expanded attention mechanism (MEAM). In MEAM, the feature map is divided into groups, and within each head, a sliding window centered at each query patch selects keys and values with a dilation rate r. This sparse attention mechanism captures contextual dependencies at multiple scales. The operation is defined as:
$$ M = MEAM(Q, K, V, r) $$
where Q, K, V are the query, key, and value matrices. For a query at position (i, j), MEAM selects keys and values from a window of size w×w with dilation rate r. The attention for each head is computed as:
$$ X_{ir} = \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 1 \le i \le W, 1 \le j \le H, 1 \le r \le 3 $$
$$ X_{i4} = \text{Attention}(q_{ij}, K, V) = \text{Softmax}\left(\frac{q_{ij} K^T}{\sqrt{d_k}}\right) \cdot V, \quad 1 \le i \le W, 1 \le j \le H $$
The selected keys and values are taken from coordinates (i’, j’) satisfying:
$$ \{(i’, j’) \mid i’ = i + p \cdot r, \; j’ = j + q \cdot r\}, \quad -\frac{w}{2} \le p, q \le \frac{w}{2} $$
To refine features progressively, the output of each head is added to the next head’s input:
$$ X’_{ir} = X_{ir} + X_{i(r-1)}, \quad 1 < r \le 4 $$
Finally, all head outputs are concatenated and passed through a linear layer:
$$ X_{i+1} = \text{Concat}\left([X’_{ir}]_{r=1:4}\right) $$
The MEAN-Transformer block also includes a 3×3 depthwise convolution for local feature extraction and a standard MLP with GELU activation. The overall block operation is:
$$ \hat{M} = \text{DwConv}(\hat{M}) + \hat{M} $$
$$ Y = \text{MSDA}(\text{Norm}(M)) + M $$
$$ Z = \text{MLP}(\text{Norm}(Y)) + Y $$
Here, MSDA stands for Multi-Scale Dilated Attention (i.e., MEAM). This design allows the model to capture both short-range and long-range dependencies, which is crucial for detecting defects of varying sizes on solar panels.
3.3 Feature Fusion Network with PConv
The feature fusion network is based on PAN but enhanced to better handle multi-scale defects. I introduce an additional shallow feature map of size 128×128. This increases the number of prediction heads from three to four, enabling the network to detect smaller defects on solar panels. To keep the model lightweight, I replace all standard convolutions in the fusion paths with partial convolution (PConv). PConv applies spatial filters to only a fraction of the input channels, leaving the rest unchanged. This reduces the computational cost to approximately 1/4 of regular convolution. The structure of PConv is simple: given an input feature map with C channels, a subset of channels (e.g., C/4) undergoes 3×3 convolution, and the rest are bypassed. After PConv, a pointwise convolution merges the channels. This significantly reduces the number of parameters and FLOPs without sacrificing accuracy. In my experiments, replacing Conv with PConv in the PAN reduces parameters by about 8.7 MB while maintaining competitive mAP.
3.4 NWD Loss Function
Small defects on solar panels, such as thin cracks or tiny black spots, may occupy only a few pixels. Traditional IoU-based loss functions (e.g., IoU, GIoU, DIoU, CIoU) are sensitive to slight location deviations, often leading to no overlap between predicted and ground-truth boxes for tiny objects. To address this, I adopt the Normalized Gaussian Wasserstein Distance (NWD) as the regression loss. The bounding box is modeled as a 2D Gaussian distribution: given a box with center (cx, cy), width w, and height h, its Gaussian representation is defined as:
$$ \mathcal{N} \sim (\mu, \Sigma), \quad \mu = \begin{pmatrix} c_x \\ c_y \end{pmatrix}, \quad \Sigma = \begin{pmatrix} \frac{w^2}{4} & 0 \\ 0 & \frac{h^2}{4} \end{pmatrix} $$
The Wasserstein distance between two Gaussians (predicted Np and ground truth Ng) is computed as:
$$ W_2^2(N_p, N_g) = \left\| \begin{pmatrix} c_{xp}, c_{yp}, \frac{w_p}{2}, \frac{h_p}{2} \end{pmatrix}^T – \begin{pmatrix} c_{xg}, c_{yg}, \frac{w_g}{2}, \frac{h_g}{2} \end{pmatrix}^T \right\|_2^2 $$
Then, the Normalized Gaussian Wasserstein Distance (NWD) is defined as an exponential form:
$$ \text{NWD}(N_p, N_g) = \exp\left(-\frac{W_2^2(N_p, N_g)}{C}\right) $$
where C is a constant related to the dataset (in my case, C is set to 12.8 based on statistics of the solar panel defect dataset). The loss function becomes:
$$ L_{\text{NWD}} = 1 – \text{NWD}(N_p, N_g) $$
This loss is more robust to small spatial shifts and effectively improves recall for tiny defects on solar panels.
4. Experiments
4.1 Dataset and Setup
I collected a dataset of approximately 3000 images of solar panels with five defect categories: thin cracks, black spots, scratches, broken fingers, and incomplete edges. Each category contains about 500 images. The dataset is split into training, validation, and test sets with a ratio of 6:2:2. All images are resized to 640×640 pixels. Experiments are conducted on an NVIDIA 3060Ti GPU using PyTorch 1.6. The batch size is 32, and training runs for 50 epochs. The initial learning rate is 0.01, reduced to 0.001 after 20 epochs. Weight decay is set to 0.0002.
4.2 Evaluation Metrics
I use three metrics: mean Average Precision (mAP@0.5), model parameters (Params in MB), and inference speed (FPS). mAP is the average of AP over all categories, where AP is the area under the precision-recall curve at IoU threshold 0.5.
$$ mAP = \frac{1}{C} \sum_{i=1}^{C} AP_i $$
FPS is computed as the number of frames processed per second on the test set.
4.3 Ablation Study
To evaluate each improvement, I conduct five ablation experiments starting from the baseline Swin-Transformer. The results are summarized in the table 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 (Ours) | ✓ | ✓ | ✓ | ✓ | 85.7 | 124.7 | 42.1 |
From the table, we can observe:
- Group A: Adding MEAM improves mAP by 0.3% but increases parameters slightly (1.9 MB) and reduces FPS by 0.8.
- Group B: Further integrating the improved PAN (with 128×128 layer) increases mAP by another 0.3% and slightly reduces parameters, while FPS improves to 39.9.
- Group C: Replacing convolutions with PConv reduces parameters by 8.7 MB and significantly boosts FPS to 42.1, but mAP drops by 0.4% (from 85.2 to 84.8). This trade-off is acceptable for real-time applications on solar panels.
- Group D: Adding NWD loss recovers the mAP to 85.7%, surpassing the baseline, with no additional parameters or speed loss. The final model achieves the best balance.
This ablation study validates the effectiveness of each module for solar panel defect detection.
4.4 Comparison with Other Detection Networks
I compare my method with three popular detectors: Faster R-CNN (two-stage), Swin-Transformer (baseline), and YOLOv5 (one-stage). All models are trained under the same conditions. Results are shown in the table below.
| Method | 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 |
| Ours | 85.7 | 124.7 | 42.1 |
My method achieves the highest mAP (85.7%) among all compared methods. Faster R-CNN has the lowest mAP and speed due to the two-stage architecture. Swin-Transformer and YOLOv5 perform similarly, but my method surpasses them by 1.1% and 1.2% respectively. In terms of parameters, my model has 124.7 MB, which is between Swin-Transformer (133.6 MB) and YOLOv5 (107.7 MB). The inference speed of 42.1 FPS is comparable to YOLOv5 (42.7 FPS) and higher than Swin-Transformer (39.5 FPS). This demonstrates that my method provides a good trade-off between accuracy and efficiency for solar panel defect detection.
Furthermore, qualitative results on test images reveal that my method reduces false negatives for small defects (e.g., thin cracks and black spots) compared to other methods. The network successfully detects multi-scale defects in various scenarios, confirming the effectiveness of the multi-scale attention and NWD loss.
5. Discussion
The proposed MEAN-Transformer network is specifically designed for detecting defects on solar panels. The multi-scale expanded attention mechanism (MEAM) enlarges the receptive field and captures both local and global features, which is crucial for solar panel defects that vary in size from tiny spots to large cracks. The addition of a 128×128 shallow feature map in the fusion network further improves the detection of small defects. The use of partial convolution (PConv) reduces computational cost, making the model suitable for real-time inspection lines. Finally, the NWD loss function addresses the sensitivity of IoU to small object displacements, leading to better localization for tiny defects on solar panels.
Although my method achieves superior performance, there is still room for improvement. For instance, the model could be extended to detect more defect categories or be optimized for deployment on edge devices. Future work may include knowledge distillation or quantization to further reduce model size while maintaining accuracy.
6. Conclusion
In this paper, I presented a novel defect detection network for solar panels based on a multi-scale attention mechanism called MEAN-Transformer. By replacing the Swin-Transformer blocks with MEAN-Transformer blocks, enhancing the feature fusion network with PConv and an additional shallow layer, and adopting NWD loss, my method effectively addresses the challenges of multi-scale and tiny defect detection on solar panels. Experimental results on a dataset of 3000 solar panel images show that my method achieves 85.7% mAP, 124.7 MB parameters, and 42.1 FPS, outperforming existing methods like Swin-Transformer and YOLOv5. The work provides a practical solution for automated quality inspection of solar panels, contributing to the reliability and safety of photovoltaic systems.
