Ship detection is crucial in inland waterway shipping management, and it is not easy to balance accuracy and real-time performance in complex water conditions. This paper proposes a real-time ship detection method based on improved YOLOv7 to address the problem. Firstly, GhostNet is introduced into the backbone network for feature extraction, and then distribution shifting convolution is introduced into the feature fusion network to achieve a lightweight model. Secondly, an attention mechanism is introduced into the feature fusion network to compensate for the accuracy loss caused by the lightweight model. Finally, the loss function is improved to make the detection model more applicable to the ship dataset. Compared with the traditional YOLOv7 detection model, the experimental results of the HPRship dataset show that the computation volume is reduced by 3.88 × 10 10 , the model parameter volume is reduced by 5.7 × 10 6 , and the detection accuracy mAP0.5 is increased by 0.7% to 98.80%. YOLOv7-GDAW model achieves a good balance between lightweight and detection accuracy, allowing it to accurately and timely complete ship detection tasks. It is suitable for deployment on small devices with limited storage and computing capacity.