AbstractThe camera module surface may introduce defects in the focusing process, and manual detection of these defects is inefficient and costly. To address this problem, a method to automatically expand the dataset for deep learning models with fewer original images is developed. A defect detection method is also presented, YOLOv7‐EAS, that enhances YOLOv7 for camera module images with complex backgrounds and small target defects. This method introduces NewEIOU Loss, a bounding box regression loss function that extends EIOU Loss with a nonlinear compensation term. This function improves the model's convergence rate to quadratic order. Moreover, the detection head based on ASFF is redesigned to adapt the layer features and spatially filter out irrelevant information to improve the detection rate of small targets. Finally, a 3D attention mechanism is applied to increase the model's ability to extract fine‐grained features without increasing the network parameters. Experimental results show that the improved YOLOv7 algorithm achieves 90.5% mAP for the camera module image dataset, which is 10.7% higher than the original algorithm, at 136 FPS. This method can perform the camera module surface defect detection task more accurately and meet the real‐time requirements of the production line.