Traffic sign recognition is of great significance for driverless and intelligent driving. If you want the intelligent driving technology to be fully applied to reality, it is necessary to carry out in-depth research on traffic sign recognition. Aiming at the problems of slow speed, low accuracy and poor universality of traffic sign recognition algorithms in dark and backlit environments, this paper proposes an improved traffic sign recognition algorithm for yolov5. Firstly, the parameter-free attention mechanism PfAAM is introduced to provide a more fine-grained feature extraction capability for the network model; secondly, the loss function is optimised to reduce the degrees of freedom during edge regression to accelerate the network convergence; finally, experimental validation is carried out on the CCTSDB traffic sign dataset. The results show that the algorithm has a recognition accuracy of 83.3% and a speed of 43.3% in backlit and dark light environments, and is capable of real-time detection.