Improved Dn-YOLOv7 for Small Defect Detection on Solar Panel Surfaces

In this study, we present an improved de-noising you only look once version 7 (Dn-YOLOv7) algorithm specifically designed to detect tiny defects on solar panel surfaces from aerial images. The presence of noise and the extremely small size of defects (e.g., cracks, broken grids, and spots) pose significant challenges for conventional object detectors. Our approach integrates a denoising block (DnBlock) inspired by the DnCNN architecture, employs a normalized Gaussian Wasserstein distance (NWD) based regression loss to replace the traditional IoU loss, and introduces coordinate convolution (CoordConv) to enhance feature representation under noisy conditions. Extensive experiments on a public solar panel defect dataset demonstrate that the proposed method achieves high detection accuracy (96.6% mAP under no noise) while maintaining robustness against Gaussian and impulse noise, with a detection speed of 78.0 frames per second. The method offers a practical solution for real‑time defect inspection of solar panels in outdoor environments.




1. Introduction

Photovoltaic (PV) power generation has become a cornerstone of renewable energy. As of early 2024, the installed capacity of solar PV in China reached 610 million kW, accounting for 20.9% of the total installed power generation capacity. The reliability of solar panels directly influences the efficiency and stability of solar farms. Therefore, timely and accurate detection of surface defects – such as cracks, broken fingers, and stains – is essential.

Aerial images captured by drones are commonly used for large‑scale inspection of solar panels, but these images inevitably suffer from noise (e.g., Gaussian noise and impulse noise) introduced by long‑duration flights, wireless transmission, and image processing operations. Moreover, most defects are extremely small targets (as small as 25×25 pixels in a 640×640 image), making them easily confused with noise. Conventional object detectors like YOLOv7 exhibit high performance in clean images, but their accuracy degrades significantly when noise is present.

To address these challenges, we propose an improved Dn‑YOLOv7 model that integrates three key innovations:

  • DnBlock: A denoising module built upon the DnCNN framework, using a noise‑tolerant loss function (MAE) and residual learning to suppress noise while preserving fine features.
  • CoordConv: Replaces standard convolution in the backbone and DnBlock to better capture the spatial distribution of noise and reduce feature loss during downsampling.
  • NWD Loss: Replaces the CIoU loss with a normalized Gaussian Wasserstein distance (NWD) to improve sensitivity to small‑scale defects and stabilize training under noisy conditions.

The remainder of this paper describes the methodology, experimental setup, and results, concluding with a discussion of the practical implications for solar panel defect detection.

2. Methodology

2.1 Overall Architecture

The improved Dn‑YOLOv7 architecture consists of three main components: a backbone network, a neck, and a head. The backbone employs CBS (Conv+BN+SiLU) blocks, ELAN (Efficient Long‑Range Aggregation Network) modules, MPConv (Max Pooling Convolution), and the proposed DnBlock. The neck uses SPPCSPC (Spatial Pyramid Pooling Cross‑Stage Partial Channel) and upsampling modules. The head incorporates re‑parameterization (REP) and auxiliary head training. The DnBlock is inserted after the initial convolution layers to remove noise early in the feature extraction pipeline.

2.2 DnBlock – Denoising Block

The DnBlock adopts a residual learning strategy: the input noisy feature map is passed through several CBS layers to estimate the noise component, which is then subtracted from the original feature map to obtain a clean representation. The module uses a skip connection that concatenates part of the input feature directly with the denoised output to preserve information. The structure of DnBlock is outlined in Figure (not shown here, but described textually). The key improvement lies in the loss function used during training. Traditional mean squared error (MSE) loss is sensitive to label noise, whereas mean absolute error (MAE) is a symmetric loss function that is more robust to label corruption.

Consider a classification risk under uniform label noise with a noise rate $\eta$. The risk for a symmetric loss function $L$ satisfies:

$$ R^\eta_L(f) = \frac{C\eta}{k-1} + \left[1 – \frac{k\eta}{k-1}\right] R_L(f) $$

where $k$ is the number of classes and $C$ is a constant. For two different functions $f^*$ and $f$, the difference in risk is:

$$ R^\eta_L(f^*) – R^\eta_L(f) = \left[1 – \frac{k\eta}{k-1}\right] \left[ R_L(f^*) – R_L(f) \right] $$

Under the condition $\eta \le (k-1)/k$, the global optimum remains unchanged, indicating that symmetric losses are unbiased by label noise. We prove that MAE is symmetric by computing its risk. Suppose the network output for a given input is $u = [u_1, u_2, \dots, u_n]$, and the true label is a one‑hot vector $e_j$ with $e_j=1$ and $e_i=0$ for $i \neq j$. The sum of all loss values for MAE and MSE are:

$$ R^{\text{MAE}}_L(f) = \sum_{i=1}^n \| e_i – u_i \|_1 = n + (n-2)A $$
$$ R^{\text{MSE}}_L(f) = \sum_{i=1}^n \| e_i – u_i \|_2^2 = n \|u\|_2^2 + n – 2 $$

where $A = \sum_{i=1}^n u_i$ is a constant under the ReLU activation. The MAE risk is independent of the specific values of $u_i$ (only depends on $n$ and $A$), confirming its symmetry and noise robustness.

In our implementation, the DnBlock uses 15 CBS layers with MAE loss to achieve effective denoising. Comparative experiments showed that the MAE‑based DnBlock yields cleaner feature maps than MSE‑based or no denoising, especially under high noise levels.

2.3 NWD Loss for Small Targets

Conventional IoU‑based losses (e.g., CIoU) are highly sensitive to small positional changes when target sizes are tiny. To mitigate this, we adopt the normalized Gaussian Wasserstein distance (NWD) loss. Each bounding box is modeled as a 2D Gaussian distribution, and the similarity between two boxes is measured by the Wasserstein distance between their distributions. The NWD loss is defined as:

$$ S_{\text{NWD}}(N_p, N_t) = \exp\left( -\frac{\left\| [cX_p, cY_p, W_p, H_p]^T – [cX_t, cY_t, W_t, H_t]^T \right\|_2^2}{c} \right) $$

where $N_p$ and $N_t$ are the Gaussian distributions of the predicted and ground‑truth boxes, $[cX, cY, W, H]^T$ denote the center coordinates, width, and height, and $c$ is a scaling constant (set to 500 based on the average defect size in our dataset).

This loss function provides a smooth gradient even for boxes with negligible overlap, significantly improving training stability and detection accuracy for small solar panel defects.

2.4 CoordConv Integration

Standard convolution is translation‑invariant, which can cause it to overlook the spatial location of noise patterns. After denoising by DnBlock, uniform noise is partially converted into non‑uniform residuals that often exhibit sparse distributions. CoordConv adds two extra channels that encode the $x$ and $y$ spatial coordinates, helping the network learn the spatial layout of noise. We applied CoordConv in both the DnBlock and the detection head. The structure concatenates the standard feature map with two coordinate maps (vertical and horizontal), as illustrated conceptually.

The incorporation of CoordConv reduces information loss during downsampling and enhances the network’s ability to localize small defects amidst residual noise.

3. Experimental Setup

3.1 Dataset

We used a publicly available solar panel defect dataset from the AIStudio platform. The dataset contains 2700 images divided into three defect categories: cracks, broken fingers, and spots. The dataset was split into 1920 training images, 480 validation images, and 300 test images. All images were resized to 640×640 pixels. Defects vary in size, with some as small as 25×25 pixels.

3.2 Training Configuration

Training was performed for 200 epochs with a batch size of 64. We used an initial learning rate of 0.01 with a warm‑up schedule and weight decay of 0.005. The optimizer was Adam (momentum 0.9). Experiments were conducted on an NVIDIA RTX 3070 (16 GB) GPU with CUDA 11.7 and PyTorch framework.

3.3 Evaluation Metrics

Mean average precision (mAP) at IoU=0.5 was the primary metric. Additionally, we defined a precision offset $\mathcal{R}$ to measure robustness to noise:

$$ \mathcal{R} = \frac{\sum_{i=2}^{N} (P_i – P_1)}{N-1} $$

where $P_i$ is the mAP under the $i$‑th noise condition, and $P_1$ is the mAP under no noise. A smaller $\mathcal{R}$ indicates better noise robustness.

4. Results and Discussion

4.1 Effectiveness of DnBlock

We performed ablation experiments to evaluate the impact of DnBlock, NWD, and CoordConv. The baseline model was YOLOv7s. The experiments were labeled as shown in Table 1.

Table 1. Ablation experiment configurations (√ indicates used)
Exp # YOLOv7s DnBlock NWD CoordConv
1
2
3
4
5
6
7
8

The quantitative results are presented in Table 2.

Table 2. Ablation experiment results (mAP % and speed)
Exp # No noise Gaussian σ=0.12 Gaussian σ=0.24 Impulse 15% Impulse 30% Speed (fps) 𝒓
1 93.9 92.3 82.5 88.6 78.6 88.0 8.40
2 94.1 93.6 86.5 88.7 80.7 81.0 6.73
3 95.3 94.2 88.9 89.9 80.8 85.0 6.85
4 95.0 93.3 88.1 88.3 78.9 80.0 7.85
5 96.3 94.2 90.3 90.0 82.8 87.0 6.98
6 95.9 94.4 90.1 89.7 82.5 79.0 6.73
7 96.1 93.6 87.4 90.4 80.2 82.0 8.20
8 96.6 94.9 91.4 91.2 85.4 78.0 5.88

From Table 2, the full‑improvement model (Exp #8) achieves the highest mAP across all noise levels, while only slightly reducing speed (78 fps vs. 88 fps of baseline). Notably, the precision offset $\mathcal{R}$ is reduced from 8.40 (baseline) to 5.88, demonstrating significantly better noise robustness.

4.2 Comparison with State‑of‑the‑Art Detectors

We compared our improved Dn‑YOLOv7 with five popular detectors: Fast R‑CNN, SSD, YOLOv5, YOLOv6, and YOLOv8. Results are summarized in Table 3.

Table 3. Comparison with other detectors (mAP % and speed)
Model No noise Gaussian σ=0.12 Gaussian σ=0.24 Impulse 15% Impulse 30% Speed (fps) 𝒓
Fast R‑CNN 73.9 69.4 62.2 68.6 62.1 30.0 8.3
SSD 71.4 68.2 62.5 65.1 59.2 32.0 7.7
YOLOv5 88.4 84.6 76.3 81.2 68.5 91.0 10.8
YOLOv6 93.4 85.6 75.8 81.3 78.3 98.0 13.2
YOLOv8 96.7 93.6 90.8 90.9 83.4 118.0 7.0
Ours (Dn‑YOLOv7) 96.6 94.9 91.4 91.2 85.4 78.0 5.9

Our method achieves the best mAP under all noisy conditions. YOLOv8 has slightly higher mAP under no noise (96.7% vs 96.6%) and faster speed (118 fps vs 78 fps), but its noise robustness ($\mathcal{R}=7.0$) is worse than our model ($\mathcal{R}=5.9$). Under strong Gaussian noise (σ=0.24), our mAP is 91.4%, which is 0.6% higher than YOLOv8. Under 30% impulse noise, ours is 85.4% vs 83.4% of YOLOv8. Thus, our model offers a better trade‑off between accuracy and noise immunity, which is critical for real‑world solar panel inspection from aerial images.

4.3 Qualitative Analysis

Visual inspection of detection outputs confirms that our improved Dn‑YOLOv7 generates fewer false positives and misses, especially under high noise. Features are cleaner and small defects (e.g., thin cracks) are correctly localized, whereas other models often fail due to noise artifacts.

5. Conclusion

In this work, we presented an improved Dn‑YOLOv7 algorithm for detecting small surface defects on solar panels from noisy aerial images. The key contributions are: (i) a denoising block (DnBlock) with MAE loss that removes noise while preserving defect features; (ii) adoption of NWD loss to improve small‑target detection; and (iii) integration of CoordConv to enhance spatial‑aware feature extraction. Experimental results demonstrate that the model achieves state‑of‑the‑art mAP under various noise conditions, with only a modest reduction in speed. The method is suitable for deployment on drone‑mounted embedded systems for real‑time solar panel inspection. Future work will focus on optimizing inference speed and extending the approach to handle mixed‑noise environments.

Scroll to Top