The detection of masks is of great significance to the prevention of occupational diseases such as infectious diseases and dust diseases. For the problems of small target size, large number of targets, and mutual occlusion in mask-wearing detection, a mask-wearing detection algorithm based on improved YOLOv5s is proposed in present work. First, the ultra-lightweight attention mechanism module ECA was introduced in the Neck layer to improve the accuracy of the model. Second, the influence of different loss functions (GIoU, CIoU, and DIoU) on the improved model was explored, and CIoU was determined as the loss function of the improved model. Besides, the improved model adopted the label smoothing method at the data processing stage, which effectively improved the generalization ability of the model and reduced the risk of overfitting. Finally, the influence of data augmentation methods (Mosaic and Mixup) on model performance was discussed, and the optimal weight of data augmentation was determined. The proposed model was tested on the verification set and the mean precision (mAP), precision, and recall are 92.1%, 90.3%, and 87.4%, respectively. The mAP of the improved algorithm is 4.4% higher than that of the original algorithm.