Ship target detection at sea has important strategic significance in military activities, maritime security, and other aspects. Traditional image processing algorithms struggle to capture the various scales of ship features. In this paper, we propose an algorithm for ship target detection based on CBAM-YOLOv8. Firstly, spatial-to-depth convolution is used in the model's downsampling section instead of cross-stride convolution to improve feature utilization. Secondly, the CBAM (Convolutional Block Attention Module) attention mechanism is added to the deep layers of the model to fuse spatial and channel feature information. Finally, MPDIOU is used to replace the CIOU loss function, enhancing the extraction accuracy of detection boxes. Experimental results on a maritime target dataset show that the detection algorithm achieves a mAP value of 93.16% and a detection speed of approximately 134 FPS, meeting the requirements of real-time ship detection at sea and providing an effective technical reference for various maritime activities and tasks.