It is of profound significance to detect whether cyclists wear helmets to protect their personal safety and maintain road traffic safety. Due to the limitations of space, distance and cyclist movement, it is challenging to detect helmet-wearing accurately and quickly. In view of this, a novel You Only Look Once (YOLOv8) algorithm for helmet-wearing detection is suggested in this paper. Firstly, YOLOv8n with the best performance test results is selected as the baseline model from several advanced object detection algorithms. Secondly, improvement measures are taken for YOLOv8n. The squeeze-and-excitation networks (SENet) is integrated at the C2f of the neck to improve the network representation ability. Part of conv modules in the backbone is replaced with the lightweight convolution (LConv) to improve the computational efficiency and the generalization ability of the model. The loss function is changed with the Wise-IoU (WIoU), to enhance the overall performance of the model. Additionally, the reasoning method is replaced by the slicing aided hyper inference (SAHI), which aims to lower the rate of missed detections for smaller objects and strengthen the accuracy of their detection. Through the above improvement methods, a new helmet-wearing detection algorithm is formed, called helmet net. Furthermore, in comparison to the YOLOv8n, the proposed algorism demonstrated an increase in precision, recall, and mean average precision (mAP) by 5, 7.3, and 6.4%, respectively, for helmet-wearing detection. At the same time, the speed reaches 111.1 fps, which can contribute to the real-time detection of helmet-wearing. After adding SAHI, the detection results show that the model can detect more small objects, which further enhances the competence of model for helmet-wearing detection.