Deep learning gained great popularity in the task of object detection. This paper proposes a printed circuit board (PCB) defect detection algorithm based on deep learning, which can improve product quality and avoid potential failures and accidents in the electronics manufacturing industry. In this paper, the YOLOv7 model is selected as the original model for PCB defect detection. Firstly, the K-means++ clustering algorithm is used to calculate the target anchor parameters which can enhance the dataset. Secondly, the receptive field enhancement (RFE) module is added to the head layer of the network to take full advantage of the receptive field in the feature map. Thirdly, the loss function CIoU of the YOLOv7 model is changed to WIoUv2. Fourthly, add the Triplet attention mechanism to the CBS and SPPCSPC modules. Finally, the detection accuracy of the improved YOLOv7 model is compared with that of Faster R-CNN, SSD, YOLOv3-tiny, YOLOv5s, and YOLOv7 models. The experimental results show that the detection accuracy and detection speed of the improved YOLOv7 model are enhanced compared with the original YOLOv7 model.