To address the challenges of low small-object detection rates and slow detection speeds in current aerial inspection of photovoltaic panels,an improved defect detection method based on the Detection Transformer(DETR)is proposed.First,to mitigate the issue of relatively small defects in aerial images,relative position encoding is introduced to enhance the model's sensitivity to element positions,thereby improving its ability to detect small targets.Second,a Dynamic Sparse Attention(DSA)module is incorporated to reduce the computational complexity of the DETR self-attention mechanism,which accelerates detection speed.Finally,to improve classification performance on difficult-to-classify samples,Focal Loss is applied to adjust the loss function,increasing the weight of hard-to-classify samples and enhancing detection accuracy for these challenging cases.Experimental results demonstrate that the proposed method achieves an average precision(AP)of 94.7%for defect detection in aerial images of photovoltaic panels,a 5.1%improvement over the original DETR algorithm.The proposed method also outperforms several mainstream detection algorithms,highlighting its effectiveness in practical applications.