Aiming at the problems of low detection accuracy and slow speed in PCB defect detection, an enhanced context information Yolov4_ tiny algorithm for PCB defect detection is proposed. Firstly, the deep feature redundancy of feature extraction network is optimized by Transformer coding unit to enhance the ability of network to capture local feature information at different scales. Then, the shallow features are used to enhance the small target context information of PCB defects and improve the representation ability of FPN network for small target defects. Finally, attention mechanism is introduced to weight the effective feature layer of feature extraction network output to strengthen the ability of target feature representation. The experimental results show that the mean average precision (mAP) of the algorithm for overall defects is 98.70%, which is higher than Yolov4_ tiny increased by 3.12%, realized accurate positioning and identification of PCB defects, and met the actual needs of industrial testing.