Infrared target detection is a commonly used means to UAV countermeasure technology. Aimed at the problems that infrared small target image is not obvious in feature and is often submerged in noise under conditions of complex environments, an improved YOLOv8 target detection algorithm is proposed. Firstly, the introduction of an attention mechanism into research is utilized for adaptively adjusting the size of the receptive field. Secondly, a small target detection layer is constructed to pay more attention to the shallow information of the network, enhancing the ability of finegrained feature extraction. Finally, the detection head improved by depth separable convolution is used to improve the detection accuracy and to simultaneously become even more lightweight. The experimental results show that the precision rate, recall rate, mAP50 and mAP50-95 are improved by 5.3%, 8.1%, 9.1% and 21.1% respectively in comparison with the original YOLOv8 algorithm. The result comes off well in the detection of small targets by UAV.