A lightweight infrared target detection model, G-YOLO, based on an unmanned aerial vehicle (UAV) is proposed to address the issues of low accuracy in target detection of UAV aerial images in complex ground scenarios and large network models that are difficult to apply to mobile or embedded platforms. Firstly, the YOLOv8 backbone feature extraction network is improved and designed based on the lightweight network, GhostBottleneckV2, and the remaining part of the backbone network adopts the depth-separable convolution, DWConv, to replace part of the standard convolution, which effectively retains the detection effect of the model while greatly reducing the number of model parameters and calculations. Secondly, the neck structure is improved by the ODConv module, which adopts an adaptive convolutional structure to adaptively adjust the convolutional kernel size and step size, which allows for more effective feature extraction and detection based on targets at different scales. At the same time, the neck structure is further optimized using the attention mechanism, SEAttention, to improve the model’s ability to learn global information of input feature maps, which is then applied to each channel of each feature map to enhance the useful information in a specific channel and improve the model’s detection performance. Finally, the introduction of the SlideLoss loss function enables the model to calculate the differences between predicted and actual truth bounding boxes during the training process, and adjust the model parameters based on these differences to improve the accuracy and efficiency of object detection. The experimental results show that compared with YOLOv8n, the G-YOLO reduces the missed and false detection rates of infrared small target detection in complex backgrounds. The number of model parameters is reduced by 74.2%, the number of computational floats is reduced by 54.3%, the FPS is improved by 71, which improves the detection efficiency of the model, and the average accuracy (mAP) reaches 91.4%, which verifies the validity of the model for UAV-based infrared small target detection. Furthermore, the FPS of the model reaches 556, and it will be suitable for wider and more complex detection task such as small targets, long-distance targets, and other complex scenes.