Since the outbreak of coronavirus in 2019, people around the world have started to wear masks to avoid the further spread of the virus. In order to better control the epidemic, it is very necessary to supervise the wearing of masks. In this paper, a deep learning model based on yolov5 is established for mask recognition and detection, and the model is trained and tested through datasets. Finally, mask detection is carried out for people in images and videos using local computer equipment, and the best weight of training and the training accuracy of nearly 95% is obtained. This paper combines the algorithms of binary classification, convolutional neural network, and deep learning object detection to effectively and accurately train and test the model, which has a certain reference value.