In order to solve the problem of low accuracy of ship detection for small target ships and complex backgrounds in synthetic aperture radar(SAR)images, while making the model more lightweight, a SAR ship detection algorithm with improved YOLOv7 is proposed. The REP-PConv-ELAN module is built in the YOLOv7 backbone network to replace the original ELAN, which reduces the computation and memory consumption of the network, speeds up the inference speed, and enhances the extraction capability of the network for target features; the ConvNeXt Block is incorporated in the feature fusion part to accelerate the network to extract and fuse the feature information of complex targets. Then the global attention mechanism(GAM)is added to the down-sampling stage to build a sampling module for capturing global features(MP-GAM), which performs feature capture and feature fusion in channel dimension and spatial dimension to realize the interaction of multidimensional information and improve the ability of network to capture key features of ships in complex backgrounds. A new metric NWD is introduced at the regression loss function of the detection head to replace IoU to enhance the detection capability of small targets. Experimental comparisons are conducted on the HRSID dataset, and the improved method improves the AP value by 10.04 percentage points, the accuracy by 3.61 percentage points, and the recall by 15.15 percentage points compared to YOLOv7. The accuracy is significantly improved compared with the current mainstream algorithm. The experimental results show that the improved algorithm can effectively improve the false and missed detections of ships. © 2023 Journal of Computer Engineering and Applications Beijing Co., Ltd.; Science Press. All rights reserved.