In the actual inland waterway scene, it is often affected by natural factors and physical conditions, resulting in the problem of inconsistent ship size. To solve the above problems, this paper proposes a ship detection algorithm based on improved yolov5. Firstly, the 3*3 convolution in the residual block of the backbone network CSPDarkNet is changed into deep separable convolution to reduce the network parameters; Secondly, by adding the improved SPP feature pyramid pooling, semantic information of different sizes can be extracted from the feature map, and a multi‐scale fused feature map can be obtained. Finally, the feature layer is strengthened and CBAM attention mechanism is added, so that the network can adaptively focus on the areas that need more attention. The improved detection algorithm based on yolov5 has significantly improved the detection effect of ships of different scales, and compared with the current mainstream SSD, Faster‐Rcnn and so on, it has significantly improved the accuracy and speed.