Mask wearing detection method based on improved YOLOv4-tiny model
By improving the YOLOv4-tiny model, adding the Zero-DCE network and GFLV2 head part, and combining the Mosaic data enhancement and preprocessing network modules, the problems of a small number of algorithms, large light effects, and poor real-time performance in face mask wearing recognition are solved, and the problem is achieved High-precision and fast mask wearing detection and error wearing reminder meet the real-time detection needs on the development board.
Patent Information
- Application Number
- CN202110701707.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-24
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2041-06-24
Smart Images

Figure CN113887270B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing methods, and in particular to a mask wearing detection method based on an improved YOLOv4-tiny model. Background Art
[0002] In recent years, with the rapid development of technology, many target detection models based on deep learning methods have emerged, such as the R-CNN model based on the region proposal method, the Fast R-CNN model, the Faster R-CNN model, the R-FCN model, the SSD model based on the regression method, and the YOLO model, all of which are based on neural networks. The SSD model is a network structure with relatively higher detection accuracy, but it also has certain defects. For example, only the last low-level feature layer is used for target detection, resulting in a large amount of target feature information loss, making the detection effect unsatisfactory.
[0003] The main objective of this work is to develop a deep learning model for detecting people without masks. The proposed model uses the YOLOv4-tiny model by integrating it with surveillance cameras to identify people without masks in public places. Image augmentation techniques are used to increase the diversity of training data to improve the performance of the proposed model.
[0004] The YOLOv4-tiny model integrates various methods that can improve accuracy in recent years in deep learning based on YOLOv3, and applies them to YOLOv3, making YOLOv4-large reach SOTA on the COCO data machine. In traditional target detection, data enhancement is simply to perform multiple random transformations on sample images, while YOLOv4 uses Mosaic data enhancement to stitch four images into one for training, which is equivalent to increasing the mini-batch in disguise. This is an improvement on the basis of CutMix mixing two images: this makes the model more accurate in small target detection, and at the same time, it is more conducive to GPU training when the batch size remains unchanged.
[0005] In order to improve the detection speed, YOLOv4-tiny uses LeakyReLU as the activation function.
[0006] Currently, there are the following problems in correctly detecting face masks:
[0007] (1) There are few deep learning algorithms specifically designed for face mask wearing recognition.
[0008] (2) The model is greatly affected by light factors.
[0009] (3) The relevant algorithms have problems such as poor real-time performance and slow detection speed when migrated to the development board.
[0010] (4) There is no recognition of incorrect wearing and no reminder of incorrect wearing.
[0011] (5) There is almost no device deployment solution for the above algorithm. Summary of the invention
[0012] The purpose of the present invention is to provide a mask wearing detection method based on an improved YOLOv4-tiny model to solve the problems existing in the above-mentioned background technology.
[0013] In order to achieve the above object, the technical solution adopted by the present invention is:
[0014] Based on the improved YOLOv4-tiny model, the mask wearing detection method includes the following steps:
[0015] S1. Obtain mask face image data, and divide the mask face image data into a training set, a validation set, and a test set;
[0016] S2. Generate a YOLOv4-tiny model, add a Zero-DCE network before the YOLOv4-tiny model, and change the Yolov3 in the head part of the YOLOv4-tiny model to GFLV2 to obtain an improved YOLOv4-tiny model;
[0017] S3, importing the training set obtained in step S1 into the improved YOLOv4-tiny model obtained in step S2, and training the improved YOLOv4-tiny model; then verifying the improved YOLOv4-tiny model through the verification set obtained in step S1, and testing the robustness of the improved YOLOv4-tiny model through the test set obtained in step S1, and adjusting the configuration parameters of the improved YOLOv4-tiny model after training to the optimal configuration parameters according to the verification and test results; the improved YOLOv4-tiny model with the optimal configuration parameters obtained after training, verification and testing is used as the detection model;
[0018] S4, inputting the mask face image data to be detected into the detection model, and implementing detection processing on the mask face image data to be detected through the detection model.
[0019] In the step S1, the training set is divided into three categories according to the mask wearing conditions reflected by the corresponding mask face image data: face data of people not wearing a mask, face data of people wearing a mask correctly, and face data of people wearing a mask incorrectly. Thus, the improved YOLOv4-tiny model after training in step S3 outputs three types of prediction targets: no mask wearing, mask wearing correctly, and mask wearing incorrectly.
[0020] In the step S2, first, a Zero-DCE network is added before the YOLOv4-tiny network, the DCE-Net uses a weight file pre-trained on the DARK FACE dataset, and the weight file is obtained by training the DCE-Net on the DARKFACE dataset, and the trained DCE-Net network is added before the YOLOv4-tiny network;
[0021] Then, change the Yolov3 in the head part of the YOLOv4-tiny model to GFLV2; use the pre-trained weight file trained by the YOLOv4-tiny model on the COCO dataset. The pre-trained weight file is pre-trained on the COCO dataset and used as the YOLOv4-tiny model weight.
[0022] In step S3, the data in the training set are rotated, scaled, translated, mirrored, spliced and Mosaic enhanced, and then imported into the improved YOLOv4-tiny model obtained in step S2.
[0023] When the step S3 starts training, the data in the training set is used as input. After the YOLOv4-tiny model is improved to generate a prediction target, the classification error and regression error are calculated with the validation set, and the error results are reflected in the various parameters of the network model, and the network parameters are updated to generate the expected output; the test set is used as input to test the model, test the robustness of the model, and finally use it as the final detection model.
[0024] The step S5 is also included: migrating and deploying the obtained detection model to the single-chip microcomputer, and the detection model in the single-chip microcomputer performs detection and processing on the mask face image data to be detected.
[0025] The process of step S5 is as follows: configure the code running environment of the detection model on the artificial intelligence development board device, install the relevant dependency packages, and complete the environment configuration; then migrate the detection module with the strongest generalization to the artificial intelligence development board device, and test the execution effect of the detection model on the artificial intelligence development board device, complete the model deployment, obtain real-time mask wearing image data from the external camera, pass the image into the model in frames, reduce the resolution of the image to increase the running speed, display the model output results on the external screen, and complete the detection of correct mask wearing.
[0026] The present invention also discloses a computer system for implementing a mask wearing detection method based on an improved YOLOv4-tiny model, comprising a readable storage medium in a computer memory, wherein the readable storage medium stores program instructions, and the computer processor reads and runs the program instructions to execute the mask wearing detection method based on the improved YOLOv4-tiny model.
[0027] The present invention proposes a detection method and device for correctly wearing a mask based on an improved YOLOv4-tiny. The method has the characteristics of small required calculation amount, fast detection speed, high detection accuracy compared with other algorithms, small model amount and simple migration, and can realize the deployment of the model on an artificial intelligence development board.
[0028] Compared with the prior art, the advantages of the present invention are:
[0029] The present invention adds a preprocessing network module, which improves the detection effect in some undesirable lighting environments such as low light and reduces the influence of light problems on the detection effect.
[0030] The present invention adopts a detection method for correctly wearing a mask based on GFLV2-improved YOLOv4-tiny. In combination with a public mask data set, the head part of the original model is replaced by GFLV2 from Yolov3, so that the accuracy is further improved. Compared with other models, such as YOLOv3-tiny, FasterRCNN and other target detection models, which have poor real-time performance due to the performance limitations of the deployment platform, the improved YOLOv4-tiny can improve both accuracy and speed, and can meet the real-time requirements.
[0031] The present invention adds an additional reminder of incorrect mask wearing. The existing mask detection algorithm only detects whether a mask is worn, but lacks detection of incorrect wearing in practice. Our model can detect this situation and warn the user on the external screen in the deployment platform, thereby improving the scientificity and practicality of the model. The present invention adds incorrect wearing detection and reminds users of incorrect mask wearing, thereby improving the practicality and scientificity of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 It is a step diagram of the detection method for correctly wearing a mask based on the improved YOLOv4-tiny of the present invention.
[0033] Figure 2 The present invention discloses a Mosica data enhancement operation process implemented based on the improved YOLOv4-tiny mask correct wearing detection method.
[0034] Figure 3 It is the preprocessing network module of the present invention.
[0035] Figure 4 This is the modified model network structure. DETAILED DESCRIPTION
[0036] Reference Figure 1 The steps implemented by the present invention are as follows: construct a data set; construct an algorithm model based on the improved YOLOv4-tiny, improve the network, and train the model; migrate and deploy, and use an artificial intelligence development board device to run the model.
[0037] Step 1: Obtain mask face image data. The mask face image data can be downloaded from a public mask dataset on the Internet.
[0038] According to the ultimate goal of identifying the wearing status of pedestrians' masks, the mask face image data is annotated into three categories: face data without mask, data of mask wearing correctly, and data of mask wearing incorrectly, corresponding to the three situations of not wearing, wearing correctly, and wearing incorrectly. After annotating each image, it is converted into the form of COCO dataset to meet the subsequent YOLOv4-tiny input
[0039] In addition, the present invention divides the mask face image data into a training set, a verification set and a test set at a ratio of 70%, 20% and 10%.
[0040] Step 2: Generate a YOLOv4-tiny model and add a Zero-DCE network before the YOLOv4-tiny model. The network framework can be found in Figure 1 And change the Yolov3 in the head part of the original YOLOv4-tiny model to GFLV2, and get the improved YOLOv4-tiny model as follows Figure 3 As shown. Specifically:
[0041] In order to enhance the image, the Zero-DCE network is used to estimate the nonlinear second-order curve LE-curve to enhance the image at the pixel level.
[0042] The LE-curve is calculated as follows:
[0043] LE(I(x);α)=I(x)+αI(x)(1-I(x)) (1)
[0044] Where x is the pixel coordinate, I(x) is the value at the corresponding coordinate, and LE(I(x); α) is the enhanced value. When applied, the LE-curve is applied to the value on the RGB channel and an iterative operation is performed to achieve the effect of a high-order curve.
[0045] The n*H*W matrix output obtained by the DEC-Net network, where n is generally 24, that is, 8 iterations are performed on the original image, and the image is input into the LE-curve calculation to obtain the enhanced image. It is used as the input to modify the YOLOv4-tiny model for detection.
[0046] The head part has two branches: the classification-quality branch and the anchor box regression branch Dirac delta function. In this model, the classification-quality branch uses Quality Focal Loss (QFL) to solve the problem of imbalance between positive and negative samples. Quality Focal Loss is improved from Focal Loss. It combines the advantages of Focal Loss and combines the calculation of image quality.
[0047] QFL is defined as follows:
[0048] QFL(σ)=-|y-σ| β ((1-y)log(1-σ)+ylog(σ)) (2)
[0049] Where σ is the output of the sigmoid function, y is the true value of the corresponding label confidence, and β is an adjustable parameter, which is generally 2.
[0050] The anchor box regression branch uses Distribution Focal Loss. The bounding box regression model generally uses the General distribution P(x) without adding other priors. The relative offset from the position to the four sides of the bounding box is used as the regression target. Its integral form is as follows.
[0051]
[0052] Set the area [y0,y n ] is discretized into {y0, y1, …, y i ,y i+1 ,…,y n-1 ,y n}, the regression estimate of label y calculated in this way It can be expressed as:
[0053]
[0054] Where P(y i ) can be obtained by the softmax layer, because the learning of the bounding box can be simply represented by the complete cross entropy, and we convert the continuous domain into a discrete domain, so the true calibration y will fall on y i and i+1 Therefore, the definition of DistributionFocal Loss is as follows:
[0055] DFL(S i ,S i+1 )=-((y i+1 -y)log(S i )+(yy i )log(S i+1 )) (5)
[0056] To simplify the expression, S i Corresponding to the corresponding P(y i ), where the global minimum solution is
[0057] Because the image shape learned from the General distribution plays a huge role in the classification-quality branch, the average of the top-k (k is 1, 2, 3, 4..., generally 3) and the top-k in the General distribution is taken as the vector P w In the anchor frame, there are four positions, top, bottom, left, and right, that need to be regressed. The present invention marks the left border to be regressed as l, the right border as r, the top border as t, and the bottom border as b, and defines the discrete probability of one of the borders as P w =[P w (y0),P w (y1),P w (y2),…,P w (y n )], where w is {l, r, t, b}, and finally the vectors obtained from the four edges are concat to form a new vector F, F = Concat ((Top-k (P w )|w∈{l,r,t,b})). Then it passes through a small network layer (FC layer, ReLU layer, FC layer, Sigmoid layer) and performs multiplication operation with the output of the classification-quality branch.
[0058] The improved network in the head part adds thousands of training parameters. Compared with the training parameters in the model, the computational overhead brought by thousands of parameters is negligible.
[0059] Step 3: Import the training set obtained in step 1 as input into the improved YOLOv4-tiny model.
[0060] In order to increase the number of training samples, data enhancement is performed before importing. The method is to rotate, scale, translate, mirror flip, splice and mosaic enhancement operations on the images in the training set. The mosaic operation process is as follows: Figure 2 shown.
[0061] Import the training set data after the enhancement operation into the improved YOLOv4-tiny model obtained in step 2, and train the improved YOLOv4-tiny model. The network model can generate corresponding outputs according to the input, and learn according to the correct areas marked in the picture. The process is to calculate the classification error and regression error of the input of the model network and the correct area, and then reflect the error results in various parameters of the network model. The error results are adjusted differently according to the different gradients of each parameter, and the error between the model prediction target and the training set is continuously reduced. The performance obtained by the validation set is used to fine-tune the hyperparameters of the model, and finally tested on the test set. According to the validation and test results, the configuration parameters of the improved YOLOv4-tiny model after training are adjusted to the optimal configuration parameters; the improved YOLOv4-tiny model with the optimal configuration parameters obtained after training, validation and testing is used as the detection model.
[0062] Step 4: input the mask face image data to be detected into the detection model, and implement detection processing of the mask face image data to be detected through the detection model.
[0063] Step 5: migrate and deploy the obtained detection model to the single-chip microcomputer, and use the detection model in the single-chip microcomputer to detect and process the mask face image data to be detected.
[0064] Specifically include:
[0065] S3.1, environment configuration, model migration, use manual development board device;
[0066] S3.2. Configure the code running environment on the artificial intelligence development board device and install related dependency packages;
[0067] S3.3. Implement the migration deployment of the model and test the execution effect of the model on the artificial intelligence development board device.
[0068] The present invention provides a computer system, comprising a readable storage medium in a computer memory, wherein a computer processor reads and runs a program instruction to execute a mask wearing detection method based on an improved YOLOv4-tiny model.
[0069] Experimental conditions:
[0070] The experiment of the present invention is carried out under the hardware conditions of two NVIDIA GTX 2080super.
[0071] Results Analysis
[0072] The simulation experiment of the present invention shows the picture test results based on the deployment of the artificial intelligence development board device. Figure 4It can be seen that the model can realize accurate face mask wearing recognition in the artificial intelligence development board device. The embodiments described in the present invention are only descriptions of the preferred implementation methods of the present invention, and do not limit the concept and scope of the present invention. Without departing from the design concept of the present invention, various modifications and improvements made by engineers and technicians in this field to the technical solution of the present invention should fall within the protection scope of the present invention. The technical content of the present invention for protection has been fully recorded in the claims.
Claims
1. A mask wearing detection method based on an improved YOLOv4-tiny model, characterized by: The following steps are involved: S1. Obtain mask face image data, and divide the mask face image data into a training set, a validation set, and a test set; S2. Generate a YOLOv4-tiny model, add a Zero-DCE network before the YOLOv4-tiny model, and change the Yolov3 in the head part of the YOLOv4-tiny model to GFLV2 to obtain an improved YOLOv4-tiny model; S3, importing the training set obtained in step S1 into the improved YOLOv4-tiny model obtained in step S2, and training the improved YOLOv4-tiny model; then verifying the improved YOLOv4-tiny model through the verification set obtained in step S1, and testing the robustness of the improved YOLOv4-tiny model through the test set obtained in step S1, and adjusting the configuration parameters of the improved YOLOv4-tiny model after training to the optimal configuration parameters according to the verification and test results; the improved YOLOv4-tiny model with the optimal configuration parameters obtained after training, verification and testing is used as the detection model; S4, inputting the mask face image data to be detected into the detection model, and implementing detection processing of the mask face image data to be detected through the detection model; In step S2, first, a Zero-DCE network is added in front of the YOLOv4-tiny network, the DCE-Net uses a weight file pre-trained on the DARK FACE dataset, and the weight file is obtained by training DCE-Net on the DARK FACE dataset, and the trained Zero-DCE network is added to the front of the YOLOv4-tiny network; then, the Yolov3 in the head part of the YOLOv4-tiny model is changed to GFLV2; the pre-trained weight file trained by the YOLOv4-tiny model on the COCO dataset is used, and the pre-trained weight file is obtained by pre-training on the COCO dataset, and the weight file is used as the YOLOv4-tiny model weight.
2. The mask wearing detection method based on the improved YOLOv4-tiny model according to claim 1, characterized in that: In the step S1, the training set is divided into three categories according to the mask wearing conditions reflected by the corresponding mask face image data: face data of people not wearing a mask, face data of people wearing a mask correctly, and face data of people wearing a mask incorrectly. Thus, the improved YOLOv4-tiny model after training in step S3 outputs three types of prediction targets: no mask wearing, mask wearing correctly, and mask wearing incorrectly.
3. The mask wearing detection method based on the improved YOLOv4-tiny model according to claim 1, characterized in that: In step S3, the data in the training set are rotated, scaled, translated, mirrored, spliced and Mosaic enhanced, and then imported into the improved YOLOv4-tiny model obtained in step S2.
4. The mask wearing detection method based on the improved YOLOv4-tiny model according to claim 1, characterized in that: When the step S3 starts training, the data in the training set is used as input. After the YOLOv4-tiny model is improved to generate a prediction target, the classification error and regression error are calculated with the validation set, and the error results are reflected in the various parameters of the network model, and the network parameters are updated to generate the expected output; the test set is used as input to test the model, test the robustness of the model, and finally use it as the final detection model.
5. The mask wearing detection method based on the improved YOLOv4-tiny model according to claim 1, characterized in that: The step S5 is also included: migrating and deploying the obtained detection model to the single-chip microcomputer, and the detection model in the single-chip microcomputer performs detection and processing on the mask face image data to be detected.
6. The mask wearing detection method based on the improved YOLOv4-tiny model according to claim 5 is characterized in that: The process of step S5 is as follows: configure the code running environment of the detection model on the artificial intelligence development board device, install the relevant dependency packages, and complete the environment configuration; then migrate the detection module with the strongest generalization to the artificial intelligence development board device, and test the execution effect of the detection model on the artificial intelligence development board device, complete the model deployment, obtain real-time mask wearing image data from the external camera, pass the image into the model in frames, reduce the resolution of the image to increase the running speed, display the model output results on the external screen, and complete the detection of correct mask wearing.
7. A computer system for implementing the mask wearing detection method based on the improved YOLOv4-tiny model as described in any one of claims 1 to 6, comprising a readable storage medium in a computer memory, characterized in that: The readable storage medium stores program instructions, and the processor of the computer reads and runs the program instructions to execute the mask wearing detection method based on the improved YOLOv4-tiny model.
