UAV aerial images have more complex backgrounds and a large number of dense small targets compared with natural scene images, which impose higher requirements on the detection network. On the premise of ensuring real-time object detection, a YOLOv5-based UAV real-time dense small object detection algorithm is proposed for the problem of low accuracy of dense small object detection in UAV view. First, combining Spatial Attention Module (SAM) with Channel Attention Module (CAM), the fully connected layer after feature compression in CAM is improved to reduce the computational effort. In addition, the connection structure of CAM and SAM is changed to improve the spatial dimensional feature capture capability. In summary, a Spatial-Channel Attention Module (SCAM) is proposed to improve the model's attention to the aggregated regions of small targets in the feature map; secondly, an SCAM- based Attentional Feature Fusion module (SC-AFF) is proposed to enhance the feature fusion efficiency of small targets by adaptively assigning attentional weights according to feature maps of different scales; finally, a backbone network is introduced in the Transformer in the backbone network, and use the SC-AFF to improve the feature fusion at the original residual connections to better capture global information and rich contextual information, and improve the feature extraction capability of dense small targets in complex backgrounds. Experiments are conducted on the VisDrone2021 dataset. The effects of different network scale parameters and different input resolutions on the detection accuracy and speed of YOLOv5 are first investigated. The analysis concludes that YOLOv5s is more suitable to be used as a benchmark model for UAV real-time object detection. Under the benchmark of YOLOv5s, the improved model improves mAP50 by 6.4% and mAP75 by 5.8%, and the FPS for high-resolution images can reach 46. The mAP50 of the model trained at an input resolution of 1504×1504 can reach 54.5%, which is 11.5% better than that of YOLOv4. The accuracy is improved while the detection speed FPS remains at 46, which is more suitable for real-time UAV object detection in dense small target scenarios.