Abstract High-precision road vehicle detection is a key requirement in the field of autonomous driving. In this paper, an optimization method based on YOLOv8n is proposed to improve the detection accuracy and generalization ability of existing deep learning target detection algorithms. The structure of YOLOv8n is comprehensively improved by upgrading Backbone to VanillaNet structure, optimizing the traditional PANet in the neck to Bi-FPN, and introducing the ASFF module in the head part. The model training is performed using a specially designed dataset based on the pictures collected from the car recorder. Comparative experimental indicates that the optimized model improves 1.75%, 2.76%, 3.6%, and 4.7% in Precision, Recall, mAP0.5, and mAP0.5:0.95. While the accuracy is improved, the number of parameters only increases by 21.81M, the FLOPS only increases by 61.22B, and the computational complexity is still lower than that of the same series of YOLOv8m. In addition, the independent contributions of each improvement module are systematically analyzed through ablation experiments. In the driving test, the inference confidence and frame rate are used as indicators for the detection evaluation of road scenes. The test results show that the frame rate always stays above 38 FPS and reaches up to 56 FPS, and the detection confidence is no less than 0.69 in the face of diversified road targets, which meets the accuracy and real-time demand of the automatic driving detection system. The research in this paper provides a feasible and efficient solution to improve the target detection accuracy.