In terms of the existing PCB defect detection algorithm in complicated model structure with huge numbers of parameters slow speed, low detection accuracy and other problems, an improved PCB defect detection algorithm which is based upon yolov5s is proposed. Taking the yolov5s model as the main framework, the Omni-Dimensional Dynamic Convolution (OdConv) structure is used to replace the backbone of the original model, and the Convolutional Block Attention Module (CBAM) attention mechanism is introduced after the Conv layer of the Neck network. CBAM attention mechanism is brought in after the Conv layer of the Neck network (Neck), and the Focal-EIoU Loss function is modified by the Complete Intersection and Merger Ratio Loss (CIoU Loss) function, and different weights are assigned to high-quality samples and low-quality samples respectively, which solves sample imbalance existing in the target detection problem, and the results show that this algorithm is comparable to the original model. Experiments are conducted and the results show that this paper’s algorithm improves the mAP by 1.9%, speeds up by 47.75Fps, decrease the model size by 13.26 M, and reduces the computation volume by 12.3 G compared to yolov5s at IoU = 0.5.