In order to solve the problems of missed detection, poor accuracy and insufficient lightweight model of the existing safety helmet wearing detection algorithm for underground personnel, an improved safety helmet wearing detection algorithm for underground personnel based on YOLOv8n was proposed. In view of the situation that the downhole helmet is small target, the P2 detection layer and the detection head are added, the CBAM attention mechanism is introduced to extract the key features of the image, the Wise-IoU is further introduced to replace the CIoU loss function to improve the training effect of the model, and finally the detection head is replaced by LSCD to make the model lightweight. The experimental results on the mine helmet in the open-source dataset DsLMF+ show that the final recognition rate of the method increases by 1.8 percentage points to 94.8%, the number of parameters is reduced by 23.8%, the amount of computation (GFLOPs) is reduced by 10.4%, and the model size is reduced by 17.2%, which can realize real-time and accurate detection of personnel wearing safety helmets underground.