In recent years, COVID-19 has swept the world, and people in crowded public places are usually large. In order to reduce the risk of virus transmission, stop the spread of the epidemic and reduce cross-infection, wearing masks correctly has become an important measure to prevent the virus. Aiming at the time-consuming and laborious situation of wearing masks manually, this paper proposes a mask wearing detection method based on yolov5. The input layer is mainly used for mosaic data enhancement, that is, adaptive anchor box and adaptive image scaling technology; Yolov5 in backbone mainly adopts focus and CSP (cross stage partial) structure; The neck layer adopts spp (spatial pyramid pooling) module and FPN (feature pyramid networks) + pan (pixel aggregation network) structure; The output mainly adopts ciou for the bounding box loss function_Loss is the average index of NMS (non maximum suppression). This method uses 8000 preprocessed images as the data set and trains 200 epochs to get the final model. The algorithm visually displays the training and test results through tensor board, and inputs the pictures captured by the camera into the model to detect whether the face wears a mask. The accuracy, recall and mean accuracy (map) of the algorithm on the test set are 94.8%, 89.0% and 93.5% respectively, which are higher than the detection results of yolov3 and yolov4 algorithms.