.Compared with the image captured in the natural scene, the image obtained by unmanned aerial vehicle (UAV) aerial photography has a more complex background and many dense small targets, which puts forward higher requirements for the detection accuracy of the target detection algorithm. However, because the UAV is a kind of small mobile device, how to ensure its real-time detection effect has been a problem. Aiming at these problems, the lightweight YOLOv7 algorithm, namely LRT-YOLOv7, is designed. First, the enhance feature fusion module and the transformer efficient layer aggregation networks module are proposed to improve the performance of feature extraction and fusion to enhance the efficiency of small target detection. Second, aiming at the problems of small target size and complex background in the UAV images, the detection head structure is redesigned in the YOLOv7-tiny algorithm to enhance the multi-scale feature fusion ability of the algorithm and thereby improve the algorithm’s detection accuracy for small targets. Finally, ablation, comparison, and visualization validation experiments were conducted using precision, recall, mean average precision, and frames per second (FPS) as evaluation indicators. The results show that the detection speed of the LRT-YOLOv7 algorithm on the self-made traffic target dataset is 133.8 FPS, and the precision indicator is 84.58%. Therefore, the LRT-YOLOv7 algorithm has high accuracy and real-time performance in traffic target detection tasks for UAV aerial imagery.