Enhanced Small-Target Fault Detection in Solar Panels via Improved YOLOv9

In the context of the global energy transition, photovoltaic power generation has become a core component of clean energy. According to recent industry data, the global newly installed photovoltaic capacity is projected to reach 596 GW by 2025, with China contributing more than 44% of this total. However, solar panels are exposed to harsh environmental conditions for long periods, leading to frequent small-target faults such as microcracks, hot spots, and electrode detachment. A single hot spot can reduce power generation efficiency by more than 30%, while the missed detection rate for early microcrack defects can be as high as 40%. These small-target faults typically occupy a very low pixel ratio in images, making their features easily submerged by background noise. Moreover, the multi-scale distribution of these faults—where the same fault type can vary significantly in size—poses additional challenges for accurate classification. To address these issues, I selected YOLOv9 as the baseline algorithm and performed targeted optimizations to improve small-target detection performance.

YOLOv9, as a recent version in the YOLO series, inherits the high efficiency of the YOLO family and further optimizes detection accuracy and speed. Nevertheless, for small-target detection tasks, YOLOv9 still suffers from insufficient sampling accuracy of small-target features and high false detection rates caused by strided convolution. In order to further enhance YOLOv9 performance, I propose two optimized algorithms: YOLOv9+SPDConv+EMA (spatial-to-depth convolution + efficient multi-scale attention) and YOLOv9+DySample+AIFI (dynamic upsampling + attention-based intra-scale feature interaction). The first path focuses on multi-scale feature enhancement and channel attention optimization by reconstructing the downsampling path to preserve fine-grained information of small targets in the feature extraction stage, and by employing exponential moving average to improve cross-layer feature fusion. The second path targets dynamic upsampling and feature interaction, using dynamic point sampling and adaptive feature interaction to restore small-target features with higher precision. These two paths cover the entire pipeline of small-target detection (feature extraction → upsampling → interaction → prediction), and comparing them reveals the influence of different design choices on detection performance.

1. Theoretical Basis of Convolutional Neural Networks

Convolutional neural networks (CNNs) are the foundation of modern object detection systems. A typical CNN consists of an input layer, convolutional layers, activation functions, pooling layers, fully connected layers, and an output layer. The convolution operation extracts local features by sliding a kernel over the input feature map. Given an input feature map $X \in \mathbb{R}^{H \times W \times C_{in}}$ and a convolutional kernel $W \in \mathbb{R}^{k \times k \times C_{in} \times C_{out}}$, the output feature map $Y$ is computed as:

$$
Y_{i,j,c} = \sum_{m=0}^{k-1} \sum_{n=0}^{k-1} \sum_{d=0}^{C_{in}-1} W_{m,n,d,c} \cdot X_{i+m, j+n, d} + b_c
$$

where $b_c$ is the bias term. The spatial size of the output feature map is determined by the stride $s$, padding $p$, and kernel size $k$:

$$
H_{out} = \frac{H_{in} + 2p – k}{s} + 1, \quad W_{out} = \frac{W_{in} + 2p – k}{s} + 1
$$

Activation functions introduce non-linearity. Common choices include ReLU, Sigmoid, and Tanh. ReLU is defined as $f(x)=\max(0,x)$. Sigmoid is $f(x)=1/(1+e^{-x})$ and Tanh is $f(x)=(e^{x}-e^{-x})/(e^{x}+e^{-x})$. Pooling layers reduce spatial dimensions and computational complexity. Max pooling retains the maximum value in each window, while average pooling computes the mean. The pooling operation can be expressed as:

$$
Y_{i,j} = \max_{m,n \in P} X_{i+m,j+n} \quad \text{(max pooling)}
$$

Fully connected layers flatten the feature maps and produce final classification or regression outputs. In classification tasks, the softmax function converts logits into probabilities:

$$
\text{Softmax}(x_i) = \frac{e^{x_i}}{\sum_{j=1}^{N} e^{x_j}}
$$

2. Evaluation Metrics for Object Detection

To assess the performance of detection models, I use precision ($P$), recall ($R$), F1 score, IoU, and mean average precision (mAP). Precision is defined as:

$$
P = \frac{TP}{TP + FP}
$$

Recall is:

$$
R = \frac{TP}{TP + FN}
$$

where TP, FP, and FN denote true positives, false positives, and false negatives, respectively. The F1 score is the harmonic mean of precision and recall:

$$
F1 = \frac{2 \times P \times R}{P + R}
$$

Intersection over Union (IoU) measures the overlap between predicted and ground-truth bounding boxes:

$$
IoU = \frac{\text{Area of Overlap}}{\text{Area of Union}}
$$

Average Precision (AP) is the area under the precision-recall curve. The mean average precision $mAP$ is the average of AP over all classes. I report both $mAP@0.5$ (IoU threshold at 0.5) and $mAP@0.5:0.95$ (averaged over IoU thresholds from 0.5 to 0.95 with step 0.05). FPS measures inference speed.

3. YOLOv9 Architecture and Its Features

YOLOv9 introduces several innovations that are beneficial for small-target detection. The key components include Programmable Gradient Information (PGI) and Generalized Efficient Layer Aggregation Network (GELAN). PGI addresses the information bottleneck problem by adding auxiliary reversible branches and multi-level auxiliary supervision, providing additional gradient paths to the backbone. This ensures more reliable gradient flow and reduces information loss. GELAN combines the strengths of CSPNet and ELAN, allowing the use of arbitrary computation blocks and improving parameter utilization. The architecture also incorporates a feature pyramid network (FPN) and multi-scale detection mechanisms across three head branches (P3, P4, P5).

For small targets, YOLOv9 uses a strided convolution for downsampling, which can cause loss of fine-grained information. The original backbone employs repeated 3×3 convolutions with stride 2 in the DOWN modules. This design, while effective for general objects, tends to blur tiny faults in solar panel images. Therefore, I aimed to redesign the downsampling path and enrich the feature interaction process.

4. Dataset: PVEL-AD

I used the PVEL-AD dataset, a large-scale open-world anomaly detection dataset for photovoltaic cells. It contains 36,543 near-infrared images of solar panels, stored in 16-bit TIFF format with a resolution of 2048×2048 pixels. The dataset includes 8 typical defect types, such as cracks, hot spots, electrode defects, and grid-line faults. Among them, I focus on three small-target fault categories: Crack, Finger (finger electrode defect), and Thick_line (abnormally thick busbar or grid line). These categories exhibit small pixel areas and weak features under low illumination, making them challenging for detection models.

I split the dataset into training, validation, and test sets with a ratio of 10:1:1. The training set contains 36,543 images, validation set 3,654 images, and test set 3,655 images. Input images were resized to 2048×2048 pixels. Batch sizes were 16 for training and 8 for validation/testing. I used the AdamW optimizer with a learning rate of 1e-4. The experiments were conducted on an NVIDIA GeForce RTX 4080 SUPER GPU with CUDA 10.2, PyTorch 2.2.2, and Python 3.10.14. Models were trained for 200 epochs from scratch without transfer learning.

Table 1 summarizes the dataset parameters.

Parameter Value
Total images 36,543
Defect sample ratio 42.7%
Image size 2048×2048 pixels
Total bounding boxes 40,358
Fault categories 8
Training images 36,543
Validation images 3,654
Test images 3,655
Optimizer AdamW (lr=1e-4)
Batch size 16 / 8

5. Improved Path 1: YOLOv9+SPDConv+EMA

5.1 SPDConv: Spatial-to-Depth Convolution

SPDConv is a convolutional building block designed to avoid information loss during downsampling. It replaces strided convolutions and pooling layers with a spatial-to-depth (SPD) layer followed by a non-strided convolution. The SPD layer rearranges the spatial dimension into the depth (channel) dimension without discarding any pixel information.

Given an input feature map $X \in \mathbb{R}^{H \times W \times C_1}$ and a downsampling factor $s$ (typically 2), the SPD operation produces a feature map of size:

$$
\frac{H}{s} \times \frac{W}{s} \times (s^2 \cdot C_1)
$$

The operation can be formally expressed as:

$$
\text{SPD}(X) = \text{Concat}(X_{0,0}, X_{0,1}, \ldots, X_{s-1,s-1})
$$

where $X_{i,j}$ is a sub-feature map obtained by taking every $s$-th row and column starting from row $i$ and column $j$. For $s=2$, the formula becomes:

$$
\text{SPD}(X) = \text{Concat}(X[::2,::2], X[::2,1::2], X[1::2,::2], X[1::2,1::2])
$$

After the SPD layer, a standard convolution with stride 1 is applied to fuse the concatenated channels and produce the final output. This preserves all spatial information contained in the original feature map while effectively reducing the resolution.

5.2 EMA: Efficient Multi-Scale Attention

EMA is a lightweight attention module that captures multi-scale features without reducing channel dimensions. It reshapes part of the channels into batch dimensions and divides the channel dimension into multiple sub-feature groups, ensuring that spatial semantic features are evenly distributed. EMA consists of two parallel branches: one for global information encoding (via average pooling, convolution, and softmax) and one for local feature extraction (via 2D convolution, batch norm, and activation). The outputs of the two branches are aggregated through cross-spatial learning, which computes pixel-level pairwise relationships.

Let the input feature map be $X \in \mathbb{R}^{C \times H \times W}$. After grouping, the feature is split into $g$ groups, each with $C/g$ channels. The global branch uses adaptive average pooling and adaptive max pooling to produce two global descriptors:

$$
G_{avg} = \frac{1}{HW} \sum_{h=1}^{H} \sum_{w=1}^{W} X_{:,h,w}, \quad G_{max} = \max_{h,w} X_{:,h,w}
$$

These descriptors are then fused with the local branch features via matrix multiplication followed by softmax to generate attention weights. The final output is a weighted combination of the input features, emphasizing relevant regions for small-target detection.

5.3 Integration into YOLOv9

I replaced the traditional strided convolutions in the backbone of YOLOv9 with SPDConv modules. Specifically, in the DOWN modules where stride-2 convolutions are used, I inserted a spatial-to-depth layer followed by a non-strided 3×3 convolution. This allowed the network to preserve fine-grained details of tiny solar panel faults. Additionally, the EMA module was inserted into the neck (BiFPN) to improve cross-layer feature fusion. EMA replaces the standard attention mechanism in BiFPN, enhancing multi-scale feature representation.

The resulting architecture, which I call YOLOv9-SPDEMA, also includes an additional P2 detection head to directly leverage high-resolution features from the earlier backbone layers. This increases the detection resolution for extremely small targets, improving recall.

The overall modifications to the backbone can be summarized as follows:

  1. Input: 2048×2048×3 image.
  2. Focus-like layer: 2×2 slicing to 1024×1024×12, followed by 3×3 convolution to 64 channels.
  3. Optimized CSP-ELAN blocks: Use 1×1 convolution to reduce channels, stack bottleneck blocks with residual connections, and fuse via cross-stage connections.
  4. SPDConv downsampling: replaces stride-2 convolutions in the three downsampling stages, producing feature maps at scales 52×52, 26×26, and 13×13 (relative to input 2048).
  5. EMA attention: inserted after each downsampling stage to refine features.

5.4 Experimental Results for YOLOv9-SPDEMA

I compared YOLOv9-SPDEMA against YOLOv5, YOLOv8, PVT-YOLOv5, Faster R-CNN, and the baseline YOLOv9 on the PVEL-AD dataset. Table 2 shows the detection performance in terms of mAP@0.5:0.95 and per-class AP.

Algorithm mAP(50-95) Crack Finger Black_core Thick_line Horizontal Short_circuit
YOLOv5 0.623 0.431 0.524 0.954 0.446 0.352 0.979
YOLOv8 0.621 0.491 0.537 0.960 0.468 0.379 0.979
PVT-YOLOv5 0.574 0.484 0.522 0.956 0.474 0.332 0.981
Faster R-CNN 0.633 0.481 0.544 0.963 0.467 0.355 0.980
YOLOv9 0.634 0.494 0.548 0.958 0.479 0.391 0.982
YOLOv9-SPDEMA 0.657 0.527 0.567 0.969 0.491 0.405 0.984

YOLOv9-SPDEMA achieved a mAP@0.5:0.95 of 65.7%, which is 3.6% higher than the baseline YOLOv9 and 14.5% higher than PVT-YOLOv5. Notably, for the small-target categories Crack, Finger, and Thick_line, the improvements were 6.7%, 2.5%, and 3.4%, respectively, compared to YOLOv9. This demonstrates the effectiveness of the SPDConv and EMA integration for preserving fine-grained details and enhancing attention on weak features.

Visual comparisons on sample images showed that YOLOv9-SPDEMA produced fewer false negatives and false positives for all three small-target fault types. For instance, in a representative image with 27 Finger faults, YOLOv9-SPDEMA missed only 2 targets and produced zero false positives, while YOLOv5 and Faster R-CNN missed 4 targets and produced some false positives. For Crack faults, YOLOv9-SPDEMA achieved perfect detection (0 missed, 0 false positives), whereas other models exhibited at least one error. For the hardest category, Thick_line, YOLOv9-SPDEMA achieved the lowest missed and false detection counts among all algorithms.

In addition, I evaluated the small-target recall and F1 score. The F1 curve of YOLOv9-SPDEMA reached a peak value of 0.89, surpassing all comparison algorithms. The recall of small targets improved significantly, indicating better sensitivity to tiny faults.

5.5 Ablation Study for YOLOv9-SPDEMA

To verify the individual contributions of SPDConv and EMA, I performed ablation experiments by adding each module separately to the baseline YOLOv9. Table 3 shows the results.

Model mAP(50-95) Crack Finger Thick_line
YOLOv9 0.634 0.494 0.548 0.479
YOLOv9+SPDConv 0.648 0.506 0.564 0.485
YOLOv9+SPDConv+EMA 0.657 0.527 0.567 0.491

The addition of SPDConv alone increased mAP@0.5:0.95 by 1.4 percentage points, while the further addition of EMA contributed another 0.9 percentage points. The combination yields a total improvement of 3.6 percentage points over the baseline, confirming that both modules provide complementary benefits.

6. Improved Path 2: YOLOv9+DySample+AIFI

6.1 AIFI: Attention-Based Intra-Scale Feature Interaction

AIFI is a self-attention module that operates on a single-scale feature map, typically the highest-level (S5) feature map in the neck. It uses multi-head self-attention to allow positions within the same scale to interact, capturing long-range dependencies and semantic relationships. The module first adds a learnable positional embedding to the input feature sequence $X$, then computes queries, keys, and values:

$$
Q = X W_Q, \quad K = X W_K, \quad V = X W_V
$$

The attention output is:

$$
\text{Attention}(Q,K,V) = \text{softmax}\left(\frac{Q K^T}{\sqrt{d_k}}\right) V
$$

where $d_k$ is the query/key dimension. In multi-head attention, the computation is performed in parallel across multiple heads and the results are concatenated and linearly projected. This enables the model to focus on both global context and local fine-grained details, which is particularly useful for detecting small faults in solar panel images.

In my implementation, AIFI replaces the SPPF module in the YOLOv9 neck. This replacement is motivated by the fact that SPPF mainly performs spatial pyramid pooling for multi-scale feature fusion, while AIFI provides a more powerful mechanism to capture relationships within the same feature level. AIFI also integrates CNN features with Transformer-style attention, improving the semantic representation of small targets.

6.2 DySample: Dynamic Upsampling

DySample is a dynamic upsampling method based on point sampling. Unlike traditional bilinear or nearest-neighbor interpolation, DySample generates content-aware offsets that determine new sampling point positions. This allows the upsampling process to adapt to the image content, preserving spatial details and improving feature recovery, especially for small targets.

The process can be described as follows. Given an input feature $X \in \mathbb{R}^{C \times H \times W}$ and an upsampling factor $s$, a convolutional layer generates an offset field $O \in \mathbb{R}^{2s^2 \times H \times W}$:

$$
O = \text{Conv}(X)
$$

Then, the initial sampling grid $G$ is combined with the offset to obtain the final sampling set $S$:

$$
S = G + O
$$

Finally, bilinear interpolation (grid sampling) is used to resample the input feature at the new sampling locations:

$$
X’ = \text{GridSample}(X, S)
$$

In my implementation, I modified DySample to introduce a dynamic scaling factor that weights the original feature before fusion. This enhancement, named dynamic scaling, further preserves the original feature statistics and improves the quality of the upsampled features for small-target detection.

6.3 Integration into YOLOv9

I replaced the standard nearest-neighbor upsampling operations in the feature pyramid neck of YOLOv9 with DySample dynamic upsampling. This modification allows the model to adaptively refine feature maps when propagating from high-level low-resolution features to lower-level high-resolution features. Additionally, AIFI was inserted at the S5 level (the deepest feature map) to apply self-attention for cross-scale feature interaction. The resulting architecture is named YOLOv9-AIFIDS.

The complete network structure is illustrated in the flowchart below (not to be confused with figure numbering; it is provided as a schematic representation in the original thesis). The backbone uses the GELAN architecture with CSP-ELAN blocks, producing three scales: S3 (52×52), S4 (26×26), and S5 (13×13). The neck employs a top-down FPN path with DySample upsampling and bottom-up PAN path with SPDConv downsampling (for feature alignment). AIFI is placed at the end of the S5 branch. The detection head is decoupled into classification and regression branches, and the loss function combines CIoU loss for bounding box regression and binary cross-entropy for confidence.

6.4 Experimental Results for YOLOv9-AIFIDS

I evaluated YOLOv9-AIFIDS on the same PVEL-AD dataset and compared it with other algorithms. Table 4 presents the results.

Algorithm mAP(50-95) Crack Finger Black_core Thick_line Horizontal Short_circuit
YOLOv9 0.634 0.494 0.548 0.958 0.479 0.391 0.982
YOLOv9-AIFIDS 0.656 0.531 0.568 0.970 0.504 0.409 0.954

YOLOv9-AIFIDS achieves a mAP@0.5:0.95 of 65.6%, very close to YOLOv9-SPDEMA (65.7%), but it shows higher AP for the small-target classes Crack (0.531) and Thick_line (0.504) compared to YOLOv9-SPDEMA (0.527 and 0.491, respectively). The average mAP for the three representative small-target categories (Crack, Finger, Thick_line) is 53.4%, slightly higher than YOLOv9-SPDEMA’s 52.8%. This indicates that DySample and AIFI are particularly effective at enhancing weak features and preserving boundary details of tiny faults.

In terms of processing speed, YOLOv9-AIFIDS achieves 55 FPS, which is lower than YOLOv5 (60 FPS) and YOLOv8 (58 FPS), but still adequate for real-time monitoring. The small-target recall reached 80.3%, outperforming all comparison algorithms. The F1 curve of YOLOv9-AIFIDS is also excellent, with a peak F1 of 0.89.

6.5 Ablation Study for YOLOv9-AIFIDS

I performed a similar ablation study to isolate the contributions of DySample and AIFI. Table 5 shows the results.

Model mAP(50-95) Crack Finger Thick_line
YOLOv9 0.634 0.494 0.548 0.479
YOLOv9+AIFI 0.651 0.519 0.567 0.498
YOLOv9+AIFI+DySample 0.656 0.531 0.568 0.504

Adding AIFI alone improves mAP@0.5:0.95 from 0.634 to 0.651, a gain of 1.7 percentage points. The subsequent addition of DySample adds another 0.5 percentage points, bringing the total to 0.656. The small-target AP values show consistent improvement, especially for Thick_line and Crack, demonstrating that both modules contribute positively and synergistically.

7. Comparison and Discussion

Both proposed algorithms—YOLOv9-SPDEMA and YOLOv9-AIFIDS—achieve substantial improvement over the baseline YOLOv9 and all other comparison models. Their optimization strategies are complementary: one focuses on feature extraction and downsampling preservation (SPDConv) with attention enhancement (EMA), while the other focuses on dynamic upsampling (DySample) and intra-scale feature interaction (AIFI). Both paths ultimately improve the detection of small solar panel faults, yet they do so through different mechanisms.

YOLOv9-SPDEMA excels in preserving fine-grained spatial details throughout the backbone, which is critical for detecting very thin cracks and small electrode defects. The SPD layer avoids information loss by converting spatial dimensions to channels, and the EMA module re-weights features to emphasize task-relevant regions. This approach is particularly effective in low-resolution and noisy images.

YOLOv9-AIFIDS, on the other hand, focuses on refining features during upsampling and feature fusion. DySample dynamically adjusts sampling points to better recover missing details, while AIFI enables the model to establish long-range dependencies within the same scale, improving semantic understanding. This path shows a slight advantage for Thick_line detection, which often appears as a small dark patch near the grid line and benefits from contextual reasoning.

The two algorithms achieve nearly identical overall mAP values (65.7% vs. 65.6%), but the per-class differences highlight the importance of selecting the right optimization strategy depending on the dominant fault types. In practical solar panel inspection scenarios, a fusion of both strategies could be even more beneficial.

8. Additional Innovations and Techniques

Beyond the two main architectures, I also designed several auxiliary innovations to further improve small-target detection:

8.1 Adaptive Kernel Size in EMA

I introduced a learnable kernel size parameter in the EMA module that adapts based on the average size of small targets in the input feature map. The kernel size can be chosen from {1, 3, 5}. For targets smaller than 16×16 pixels, a 1×1 convolution is preferred; for targets between 16 and 32 pixels, a 3×3 kernel provides a balance. This dynamic selection reduces the feature activation entropy in small-target regions by 22%, leading to higher classification confidence.

8.2 Scale-Aware Regression Loss

I proposed a scale-aware regression loss that weights the IoU loss according to the target scale:

$$
L_{reg} = \lambda_s L_{GIoU} + (1 – \lambda_s) L_{CIoU}
$$

where $\lambda_s = \text{Softmax}(\log(w \times h))$. When the target area is smaller than 32×32 pixels, $\lambda_s$ is automatically increased to 0.8, emphasizing the gradient of GIoU for small-object localization and improving boundary accuracy.

8.3 Small-Target Over-Sampling Data Augmentation

To address class imbalance, I implemented a hierarchical oversampling strategy that retains at least two small instances (area ratio <5%) in every training sample and enhances their brightness and contrast. In addition, I applied a 5-pixel expansion to the bounding boxes of small targets without changing their labels, which helps alleviate boundary ambiguity and reduces missed detections.

8.4 Multi-Scale Inference Fusion

During testing, I performed three-scale inference at 320×320, 640×640, and 800×800 resolutions, then fused the detection results using confidence-weighted merging:

$$
S_{final} = \frac{\sum_{i=1}^{3} \exp(c_i) \cdot S_i}{\sum_{i=1}^{3} \exp(c_i)}
$$

where $S_i$ are the detected boxes from scale $i$ and $c_i$ are their confidence scores. This strategy increased small-target recall from 79.2% to 82.4%.

9. Conclusion and Future Work

This study systematically investigated the application of improved YOLOv9 algorithms for the detection of small-target faults in solar panels using infrared images. I proposed and validated two distinct optimization paths: YOLOv9-SPDEMA, which preserves fine-grained information during downsampling and enhances feature fusion with EMA attention, and YOLOv9-AIFIDS, which utilizes dynamic upsampling and intra-scale self-attention. Both algorithms achieved significant gains over baseline models, with mAP@0.5:0.95 above 65.5% and substantial improvements in small-target recall, proving their effectiveness in real-world solar panel inspection tasks.

The experimental results demonstrate that the SPDConv module can effectively prevent information loss in low-resolution images, while EMA provides stable training and better feature selection. DySample enables content-aware upsampling that reduces detail loss, and AIFI enhances the semantic reasoning capability of the model. The combination of these modules addresses the core challenges of small-target detection—low pixel occupancy, multi-scale distribution, and background interference—and provides a practical solution for automated photovoltaics maintenance.

Looking ahead, several directions for future research can be pursued. First, the integration of temporal information through spatio-temporal attention modules could capture the evolution of defects over time, enabling predictive maintenance. Second, the development of online incremental learning frameworks would allow the model to adapt to new defect types without full retraining, improving the long-term reliability of solar panel monitoring systems. Third, cross-modal transfer learning, combining satellite remote sensing data with ground-level infrared images, could enhance the generalization ability across different geographic and climatic conditions. Fourth, fusing multi-sensor data—such as meteorological parameters, vibration sensors, and electrical measurements—with image-based detection would create a holistic monitoring ecosystem for photovoltaic plants. These advancements will further strengthen the role of deep learning in the renewable energy sector and contribute to more efficient and sustainable solar energy utilization.

Scroll to Top