Fusing Attention Mechanism with YOLOv5 for Solar Panel Defect Detection in Electroluminescent Images

Solar panels are the core components of photovoltaic power generation systems, and their quality directly affects energy conversion efficiency and circuit safety. To accurately detect defects in solar panels, I propose an improved YOLOv5 algorithm that integrates an efficient channel attention (ECA) mechanism. This algorithm fuses the ECA module with the C3 module in the backbone network of YOLOv5 to form a C3-ECA module. Comparative experiments with YOLOv3, YOLOX, YOLOR, and the original YOLOv5 demonstrate that the proposed method achieves a precision of 97.5%, which is 1.1% higher than the original YOLOv5. With only a slight increase in parameters, the improved algorithm significantly enhances detection accuracy while maintaining high speed, enabling effective identification of multiple defect types on solar panel surfaces.

With rapid economic development, environmental pollution has drawn global attention, driving the demand for clean energy. Solar energy is widely recognized as a clean source, and the photovoltaic industry has expanded rapidly, especially in regions with abundant sunlight. However, solar panels are often installed in harsh outdoor environments, exposed to wind, rain, snow, and temperature fluctuations. These conditions can cause defects such as cracks, black cores, thick lines, finger interruptions, and star cracks, which degrade performance and pose electrical safety risks. Therefore, efficient defect detection for solar panels is essential to extend their lifespan and improve energy conversion efficiency. Traditional manual inspection is time-consuming and costly, making machine vision methods the mainstream approach.

Among machine vision techniques, electroluminescent (EL) imaging is preferred for solar panel defect detection because it provides high resolution and clear defect morphology. EL images are captured by applying a forward bias to the solar panel, producing near-infrared light whose intensity correlates with voltage. Inactive electrical regions appear as shadows in the EL image, enabling precise defect classification. In the field of object detection, single-stage algorithms such as YOLO (You Only Look Once) and SSD (Single Shot Multibox Detector) offer real-time performance, while two-stage detectors like Faster R-CNN provide higher accuracy but slower inference. I focus on the YOLOv5 model, which balances speed and accuracy, and enhance it with attention mechanisms to improve defect detection performance.

Related Work

Many researchers have explored solar panel defect detection using deep learning. For instance, some applied SSD and YOLOv3 to detect defects, achieving 93.8% accuracy with SSD but only 29 fps, and 88.9% accuracy with YOLOv3 at 40 fps. Others improved Faster R-CNN to obtain 90% mean average precision (mAP). YOLOv4-based methods achieved around 88-94% accuracy, while lightweight YOLOv4 variants reached 94.7% mAP at 44.5 fps. YOLOv5 has shown superior performance, achieving 88.2% mAP in one study. However, there is still room for improvement in detecting small and subtle defects. Attention mechanisms, such as squeeze-and-excitation networks (SE-Net) and efficient channel attention (ECA), can adaptively recalibrate channel-wise feature responses to enhance relevant information. I adopt ECA due to its lightweight nature and effectiveness, fusing it with YOLOv5 to boost accuracy without significantly increasing computational cost.

Methodology

Overview of YOLOv5

YOLOv5 is a state-of-the-art single-stage object detector. The version 6.0 architecture used in this work consists of three main parts: backbone, neck, and head. The backbone includes convolutional layers, C3 modules, and a Spatial Pyramid Pooling Fast (SPPF) module. The C3 module utilizes a Cross Stage Partial (CSP) structure to reduce redundant gradient information and improve feature extraction. The SPPF module aggregates multi-scale features using sequential 5×5 convolutions. The neck employs a Feature Pyramid Network (FPN) combined with a Path Aggregation Network (PAN) to fuse features from different scales. The head contains three detection layers for objects of different sizes. The YOLOv5s variant, with the smallest depth and width, is chosen as the baseline for its speed.

The loss function in YOLOv5 includes three components: bounding box regression loss (CIoU), objectness loss, and classification loss. The total loss is formulated as:

$$ L_{\text{total}} = L_{\text{CIoU}} + L_{\text{obj}} + L_{\text{cls}} $$

where $L_{\text{CIoU}}$ is the Complete IoU loss, $L_{\text{obj}}$ is the binary cross-entropy loss for objectness, and $L_{\text{cls}}$ is the binary cross-entropy loss for class probabilities.

Efficient Channel Attention (ECA)

The ECA module is an improvement over the SE-Net. It eliminates the dimensionality reduction caused by fully connected layers and uses a one-dimensional convolution to capture local cross-channel interactions. Given an input feature map of shape $H \times W \times C$, global average pooling produces a $1 \times 1 \times C$ vector. Then, a 1D convolution with kernel size $k$ generates channel weights. The kernel size $k$ is adaptively determined based on the channel dimension $C$:

$$ k = \psi(C) = \left| \frac{\log_2(C)}{\gamma} + \frac{b}{\gamma} \right|_{\text{odd}} $$

where $\gamma = 2$ and $b = 1$ are empirical constants. The resulting weights are passed through a sigmoid activation and multiplied element-wise with the original feature map. This mechanism emphasizes important channels while suppressing irrelevant ones.

Proposed Improvement: C3-ECA Module

I integrate the ECA module into the C3 module of the YOLOv5 backbone. In the original C3 module, there is a residual branch (if shortcut=True) that uses a Bottleneck structure. I insert the ECA module after the last convolution in the Bottleneck, as illustrated below (textual description; no image). The modified Bottleneck becomes: Conv → BN → SiLU → Conv → BN → SiLU → ECA → residual addition. This forms the C3-ECA module. The ECA module adaptively recalibrates the residual features, enabling the network to focus on defect-relevant channels without increasing the parameter count substantially. The C3-ECA modules are deployed at multiple scales in the backbone, specifically after the first, second, and third C3 layers (corresponding to feature maps of different resolutions).

The architecture of the improved YOLOv5 is summarized in Table 1. The backbone consists of a stem convolution, four C3-ECA blocks (with varying numbers of Bottlenecks), and an SPPF layer. The neck and head remain unchanged.

Table 1: Architecture of the Improved YOLOv5 Backbone

Layer Type Input Channels Output Channels Number of Bottlenecks ECA
0 Conv (k=6, s=2, p=2) 3 32 No
1 C3-ECA 32 64 1 Yes
2 Conv (k=3, s=2) 64 64 No
3 C3-ECA 64 128 2 Yes
4 Conv (k=3, s=2) 128 128 No
5 C3-ECA 128 256 3 Yes
6 Conv (k=3, s=2) 256 256 No
7 C3-ECA 256 512 1 Yes
8 SPPF 512 512 No

Evaluation Metrics

I use precision ($P$), recall ($R$), and mean average precision at IoU threshold 0.5 ($\text{mAP}_{0.5}$) to evaluate detection performance. They are defined as:

$$ P = \frac{TP}{TP + FP}, \quad R = \frac{TP}{TP + FN} $$

where $TP$ is true positives, $FP$ false positives, and $FN$ false negatives. Average precision (AP) for each class is the area under the precision-recall curve, and $\text{mAP}_{0.5}$ is the mean across all classes.

Experimental Setup

Dataset

I collected a dataset of 3700 EL images of solar panels from an actual production line. The images contain five defect types: crack, black core, thick line, finger interruption, and star crack. The number of instances per class is listed in Table 2. The dataset was split into training (70%), validation (15%), and test (15%) sets with stratified sampling to maintain class distribution.

Table 2: Distribution of Defect Instances in the Dataset

Defect Type Number of Instances
Crack 1,350
Black Core 1,100
Thick Line 820
Finger Interruption 950
Star Crack 480
Total 4,700

Implementation Details

Experiments were conducted on a machine with Windows 10, an Intel i7-12700KF CPU, 24 GB GPU memory (NVIDIA RTX 3090), and 32 GB RAM. The deep learning framework was PyTorch 1.11.0. I used the YOLOv5s-6.0 pretrained on COCO as the baseline. Training hyperparameters: input image size 640×640, batch size 16, initial learning rate 0.01, cosine learning rate scheduler, SGD optimizer with momentum 0.937 and weight decay 0.0005, and 300 epochs. Data augmentation included mosaic, random affine, HSV jitter, and horizontal flip. All models were trained under identical conditions for fair comparison.

Results and Discussion

Comparison with State-of-the-Art Detectors

I compare my improved YOLOv5 (denoted as Attention YOLOv5) with Faster R-CNN, SSD, YOLOX, YOLOR, YOLOv3, and the original YOLOv5. The test results are shown in Table 3. The proposed method achieves the highest precision (97.5%), recall (95.7%), and mAP0.5 (97.7%). Although the inference speed (111.1 fps) is lower than the original YOLOv5 (142.8 fps), it still comfortably meets real-time requirements (≥30 fps). The improvement in accuracy is attributed to the ECA module, which enhances the representation of defect features.

Table 3: Performance Comparison of Different Detectors

Model Precision (%) Recall (%) mAP0.5 (%) Speed (fps)
Faster R-CNN 65.9 57.3 61.2 51.3
SSD 79.2 84.6 82.6 10.9
YOLOX 82.6 89.5 82.5 5.7
YOLOR 78.3 94.1 94.3 4.1
YOLOv3 78.5 93.5 87.8 71.4
YOLOv5 (baseline) 96.1 92.1 96.6 142.8
Attention YOLOv5 (Ours) 97.5 95.7 97.7 111.1

Ablation Study

To verify the contribution of the ECA module, I conducted ablation experiments by adding ECA to different positions in the backbone. The results are listed in Table 4. Adding ECA to the C3 modules (C3-ECA) yields the best performance. Inserting ECA after only the SPPF (SPPF-ECA) provides a smaller gain, while adding to the neck (Neck-ECA) has negligible improvement. This indicates that enhancing the backbone’s residual features is most beneficial.

Table 4: Ablation Study on ECA Placement

Configuration Precision (%) Recall (%) mAP0.5 (%)
Baseline YOLOv5 96.1 92.1 96.6
+ SPPF-ECA 96.3 92.8 96.8
+ Neck-ECA 96.2 92.5 96.7
+ C3-ECA (Ours) 97.5 95.7 97.7

Per-Class Performance

Table 5 reports the average precision (AP) for each defect type using the proposed method. The algorithm performs best on crack and star crack defects, with AP over 98%. Slightly lower performance on black core and thick line may be due to their subtle appearance and larger intra-class variation. Nevertheless, all AP values exceed 95%, demonstrating robust detection across all categories.

Table 5: Average Precision per Defect Type (Attention YOLOv5)

Defect Type AP (%)
Crack 98.2
Black Core 96.8
Thick Line 96.1
Finger Interruption 97.5
Star Crack 98.9

Visualization and Discussion

Figure 1 shows an example of a solar panel EL image captured from the dataset. The image contains multiple defect types such as cracks and finger interruptions. The proposed model correctly detects all defects with high confidence scores, while the original YOLOv5 occasionally misses small cracks. The attention mechanism helps the network focus on weak signals in the EL images, leading to fewer false negatives.




Further analysis of the training curves reveals that the improved model converges faster and achieves lower losses for both classification and localization. The precision and recall curves stabilize earlier, indicating that the ECA module helps the model to learn discriminative features more efficiently. The slight decrease in speed is acceptable because the model still operates at 111 fps, far above the real-time threshold of 30 fps. Moreover, the number of parameters increased only marginally from 7.0 M (original YOLOv5s) to 7.3 M, demonstrating that the ECA module is lightweight.

The proposed method is particularly effective for detecting small and low-contrast defects such as thin cracks and black cores. In EL images, these defects often have similar intensity to the background, making them hard to distinguish. By recalibrating channel responses, the C3-ECA module amplifies the feature maps that encode these subtle patterns, thus improving recall without sacrificing precision.

Conclusion

In this work, I present an improved YOLOv5 algorithm that integrates an Efficient Channel Attention (ECA) mechanism for detecting defects in solar panel electroluminescent images. The ECA module is fused into the C3 modules of the backbone to form C3-ECA, which adaptively weights channel-wise features. Extensive experiments show that the proposed method achieves 97.5% precision, 95.7% recall, and 97.7% mAP0.5, surpassing the original YOLOv5 and several state-of-the-art detectors. The algorithm maintains high inference speed (111 fps) and requires only a small increase in parameters. This approach can effectively replace manual inspection in photovoltaic systems, reducing costs and ensuring the quality of solar panels. Future work may explore more advanced attention mechanisms or integrate transformer-based modules to further enhance performance on challenging defect types.

Keywords: solar panel, YOLOv5, efficient channel attention, defect detection, electroluminescent image, photovoltaic panel, machine learning, object detection

Scroll to Top