The circuit boards in the fields of optical sensors and optical devices require extremely high levels of precision and performance. For instance, applications such as fiber optic communication, optical computing, biomedical devices, and high-performance computing devices all necessitate meticulous optical components. Any minute defect on the circuit boards of these components has the potential to adversely impact the performance of the entire device. Traditional circuit defect detection methods require manual inspection, which is very labor-intensive and time-consuming. The defect detection method based on deep learning can automatically learn features and more accurately find defects in printed circuit boards, improve detection efficiency, and reduce the workload, bringing better economic and social benefits. Based on the popular YOLOv8 model, this paper uses the open-source circuit defect dataset, introduces Wise IoU, proposes the W–YOLOv8 model, and uses the gradient gain allocation strategy of a dynamic non-monotonic focusing mechanism to make the model focus on ordinary-quality anchor boxes, which improves the performance of the original model. Experimental data show that the mAP50 of W–YOLOv8 is 97.3%, which is 1.35% higher than that of YOLOv8, and the mAP50-95 is 55.4%, which is 3.94% higher than that of YOLOv8.