Improved Dn‑YOLOv7 Algorithm for Small Target Defect Detection on Solar Panels

In the rapidly expanding field of photovoltaic power generation, the reliability and efficiency of solar panels are critical. Defects such as cracks, broken grid lines, and stains on the surface of solar panels can significantly reduce energy output. Detecting these defects early, especially from aerial images, is essential but challenging due to two major factors: image noise and the tiny size of the defects. Traditional object detection algorithms often suffer from degraded performance when noise is present, and small targets are easily overlooked. To address these issues, I propose an improved de‑noising YOLOv7 (Dn‑YOLOv7) algorithm specifically designed for detecting small defects on solar panels under noisy conditions.

The proposed algorithm integrates a de‑noising block (DnBlock) inspired by the DnCNN architecture, which employs a residual learning strategy to remove noise while preserving fine details. Additionally, the coordinate convolution (CoordConv) is introduced to better capture spatial information in noisy features. To improve the detection of extremely small defects, the traditional IoU‑based loss is replaced by the normalized Gaussian Wasserstein distance (NWD) loss, which is more robust to scale variations. The experiments demonstrate that the improved model achieves a mean average precision (mAP) of 96.6% on clean images and maintains high performance under strong Gaussian and impulse noise, reaching 91.4% and 85.4% respectively, with a detection speed of 78.0 frames per second.

Introduction

With global energy demands rising and environmental concerns intensifying, solar energy has become one of the fastest‑growing renewable sources. As of early 2024, China’s installed solar photovoltaic capacity reached 6.1 × 10⁸ kW, accounting for 20.9% of total power generation capacity. However, defects on solar panels — such as cracks, broken busbars, and stains — can severely affect the efficiency and lifespan of photovoltaic systems. Therefore, developing reliable and automatic defect detection methods for solar panels is of great practical importance.

Aerial images captured by drones are a common data source for inspecting large‑scale photovoltaic farms. Nevertheless, these images often suffer from various types of noise, including Gaussian noise and impulse noise, introduced during transmission, compression, or by environmental factors. Moreover, defects such as micro‑cracks or small stains are often only a few pixels in size (e.g., 25 × 25 pixels in a 640 × 640 image), making them extremely difficult to detect. Standard deep‑learning‑based detectors, while powerful, tend to confuse noise with target features, leading to high false‑positive and false‑negative rates.

To tackle these problems, I develop an improved YOLOv7 model, which I call Dn‑YOLOv7, incorporating three key innovations:

  • DnBlock: A dedicated denoising module that learns a residual noise mapping and then subtracts it from the noisy features, effectively cleaning the feature maps before further processing. Instead of the conventional mean squared error (MSE) loss, I adopt a mean absolute error (MAE) loss within the module, which is proven to be symmetric and thus more tolerant to label noise.
  • Normalized Gaussian Wasserstein Distance (NWD) Loss: Replaces the complete IoU (CIoU) loss in the bounding box regression branch. NWD loss is mathematically derived from the Wasserstein distance between two Gaussian distributions modeling the bounding boxes, and it is much more sensitive to small positional shifts, thereby improving small‑target detection.
  • CoordConv: Replaces standard convolutions in key parts of the network (the head and inside DnBlock). CoordConv adds two extra channels encoding the x and y coordinates, helping the network to learn position‑dependent transformations and better handle non‑uniform noise after denoising.

Extensive ablation and comparison experiments show that the proposed Dn‑YOLOv7 achieves state‑of‑the‑art performance on the solar panel defect dataset, especially under noisy conditions, while maintaining a real‑time detection speed suitable for deployment on drones or edge devices.




Proposed Method: Dn‑YOLOv7

Overall Architecture

The backbone of Dn‑YOLOv7 consists of convolutional (Conv) layers, batch normalization (BN), SiLU activation (CBS), ELAN (efficient long‑range aggregation network), MPConv (max‑pooling convolution), and the newly proposed DnBlock. The neck uses SPPCSPC (spatial pyramid pooling cross‑stage partial channel) and up‑sampling modules. The head is redesigned with re‑parameterization (REP) and an auxiliary head for better training. The key modifications are:

DnBlock: Denoising Module

DnBlock adopts a residual learning framework. Given a noisy input feature map, the module predicts the noise map and subtracts it to obtain a clean representation. The structure is illustrated conceptually: an input image first passes through a CBS layer to produce 64‑channel features, then further convolutions to 128 channels. A skip‑splicing operation is used: part of the features are directly concatenated with the final output, while the other part goes through multiple CBS layers to extract noise residuals. After removing noise via residual subtraction, the two parts are fused to form a 256‑channel denoised feature map.

During training, the classification risk under label noise can be analyzed. Let \( f(x) \) be the prediction function, and define the risk under uniform noise with noise rate \( \eta \) as:

$$
R^{\eta}_L(f) = E_{x,\tilde{y}} L(f(x),\tilde{y}) = (1-\eta) R_L(f) + \eta (C – R_L(f)/(k-1)),
$$

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) = [1 – k\eta/(k-1)] [R_L(f^*) – R_L(f)].
$$

When \( \eta \le (k-1)/k \), the global optimum remains unchanged — that is, the loss function is noise‑tolerant. I prove that MAE is symmetric: for a network output \( u = [u_1,\dots,u_n] \) with \( \sum u_i = A \) and the correct label \( e_j = 1 \), the total MAE risk and MSE risk 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.
$$

Since MAE depends only on the number of classes and the activation range, it is symmetric and therefore robust to uniform label noise. In DnBlock, I replace MSE with MAE to improve denoising robustness.

NWD Loss for Small Targets

The original YOLOv7 uses CIoU loss, which is sensitive to large bounding‑box shifts but insensitive to minute displacements typical of tiny defects. For example, in my dataset, many defects are only 25×25 pixels in a 640×640 image. To address this, I adopt the normalized Gaussian Wasserstein distance (NWD) loss.

Each bounding box is modeled as a 2D Gaussian distribution using its inscribed ellipse. The distance between two Gaussians \( N_p \) and \( N_t \) (predicted and true) is given by the Wasserstein distance, which is then normalized via an exponential function:

$$
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 \( (cX,cY) \), \( W \), \( H \) denote center coordinates, width, and height. The constant \( c \) is set to 500 based on the average target size in the training set. The NWD loss is then \( 1 – S_{\text{NWD}} \). This loss function is scale‑invariant and provides smooth gradients even for tiny boxes, significantly improving small‑target detection accuracy on solar panels.

CoordConv Integration

Standard convolution is translation‑invariant, which limits its ability to differentiate noise patterns that are spatially varying. After DnBlock, uniform noise becomes non‑uniform, and ordinary convolutions may lose critical features. CoordConv addresses this by adding two extra channels containing the x and y coordinate information of each pixel, concatenated with the input feature map before convolution. This allows the network to learn position‑aware filters. In my model, I apply CoordConv in both the head and within DnBlock to preserve spatial context and reduce feature loss during denoising and down‑sampling.

Experiments and Results

Dataset and Implementation Details

The experiments are conducted on a publicly available solar panel defect dataset from AIstudio, containing 2,700 images with three defect types: cracks, broken grid lines, and stains. The dataset is split into 1,920 training images, 480 test images, and 300 validation images. All images are resized to 640×640. The model is trained for 200 epochs with a batch size of 64. The initial learning rate is 0.01 with a warm‑up strategy, weight decay is 0.005, and the optimizer is Adam with momentum 0.9. Hardware includes an NVIDIA RTX 3070 (16 GB), Intel i5‑11400 CPU, and Windows 10 with CUDA 11.7. The evaluation metric is mean average precision (mAP). I also define a precision drift metric \( \mathrm{R} \) to quantify sensitivity to noise:

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

where \( P_i \) is the mAP under the i‑th noise level and \( P_1 \) is the mAP on clean images. Smaller R indicates better noise robustness.

Denoising Performance of DnBlock

I first verify the effectiveness of DnBlock by comparing feature maps with and without the module under different configurations. The most significant noise suppression is observed when using MAE loss and 15 CBS layers inside DnBlock. The denoised feature maps show fewer black‑and‑white speckles (noise artifacts), confirming that DnBlock can effectively reduce noise while preserving defect‑related features.

Ablation Study

Ablation experiments are performed on the YOLOv7s baseline. Eight configurations are tested, as summarized in the following table (Table 1). A checkmark (√) indicates that the corresponding module is used.

Table 1: Ablation experiment configurations
Experiment ID 1 2 3 4 5 6 7 8
YOLOv7s
DnBlock
NWD
CoordConv

Training convergence curves (Figure 5 in the original paper) show that the improved model (Experiments 5‑8) has less fluctuation and higher final mAP on noisy datasets. The full results are given in Table 2.

Table 2: Ablation experiment results
Exp. ID Clean Gaussian (σ=0.12) Gaussian (σ=0.24) Impulse 15% Impulse 30% FPS R
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

The best results are achieved in Experiment 8 (full model): mAP of 96.6% on clean data, 91.4% under strong Gaussian noise, and 85.4% under 30% impulse noise. Compared to the baseline (Exp. 1), the improvement under strong Gaussian noise is +10.8% and under strong impulse noise is +8.7%. The precision drift R is reduced from 8.40 to 5.88, indicating better noise robustness. The detection speed decreases from 88.0 FPS to 78.0 FPS, which is still acceptable for real‑time applications.

Comparison with State‑of‑the‑Art Detectors

I compare my Dn‑YOLOv7 with five popular detectors: Fast R‑CNN, SSD, YOLOv5, YOLOv6, and YOLOv8. The results are shown in Table 3.

Table 3: Comparison with existing detectors
Model Clean Gaussian (σ=0.12) Gaussian (σ=0.24) Impulse 15% Impulse 30% FPS R
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
Dn‑YOLOv7 (Ours) 96.6 94.9 91.4 91.2 85.4 78.0 5.9

My model achieves the highest mAP under all noise conditions. While YOLOv8 has slightly better mAP on clean data (96.7% vs. 96.6%) and much higher FPS (118 vs. 78), its performance degrades more under noise (R=7.0 vs. 5.9). My Dn‑YOLOv7 offers a better balance between accuracy and speed, making it more suitable for noisy aerial inspections of solar panels.

Qualitative visual comparisons (as illustrated in the original paper) show that my model produces fewer false positives and false negatives (missed detections) under noisy conditions, especially for tiny defects. For instance, small cracks that are invisible to other detectors are correctly localized by Dn‑YOLOv7.

Conclusion

I have presented an improved Dn‑YOLOv7 algorithm specifically designed for detecting small defects on solar panels from noisy aerial images. The key contributions include:

  • A dedicated denoising block (DnBlock) with MAE loss that effectively removes noise without sacrificing fine details.
  • Adoption of the normalized Gaussian Wasserstein distance (NWD) loss to replace CIoU, significantly improving detection of tiny defects on solar panels.
  • Integration of CoordConv to preserve spatial information and further enhance noise robustness.

Extensive experiments demonstrate that the proposed model achieves 96.6% mAP on clean images and maintains high accuracy under strong Gaussian and impulse noise (91.4% and 85.4% respectively), with a detection speed of 78 FPS. The model strikes an excellent trade‑off between precision and speed, making it well‑suited for real‑time defect detection on solar panels deployed in solar farms.

Future work will focus on optimizing inference speed to match lighter models like YOLOv8 without sacrificing noise robustness. I also plan to extend the approach to handle mixed‑noise scenarios and to test on other photovoltaic infrastructure components.

Scroll to Top