Complex environments, such as dense personnel and background interference, affect the detection accuracy of whether personnel wear helmets. To solve this problem, a new detection algorithm for helmets based on YOLOv5 is studied in this paper. Firstly, RepVGGblock is used to replace the common convolution in the network to effectively utilize the computing power of GPU. Secondly, the efficient channel attention mechanism is incorporated into the C3 module of the backbone network to enhance the feature identification ability of the backbone network for the hard hat. Then, the boundary box regression function is changed to SIoU to redefine the distance loss and improve the regression accuracy. Finally, the detection performance of multi-scale targets is improved by adding detection layers. The test results on the self-made safety helmet data set show that the average accuracy of the improved YOLOv5 model reaches 94.6%, which is 4.1% higher than that of the original model, and can meet the requirements of target detection.