A face mask detection method based on YOLOv8 to resist occlusion and counterfeit attacks

By improving the custom structure and dataset annotation of the YOLOv8 algorithm, the anti-occlusion and forgery ability of the face mask detection model is enhanced, the robustness and computational efficiency issues in the existing technology are solved, and high-precision and real-time detection effects are achieved.

CN119600670BActive Publication Date: 2025-10-03SOUTHEAST UNIV +1
View PDF 9 Cites 0 Cited by

Patent Information

Application Number
CN202411811112.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-10
Publication Date
2025-10-03
Estimated Expiration
2044-12-10

AI Technical Summary

Technical Problem

Existing facial mask detection technology has poor robustness under occlusion and counterfeit attacks and high computational complexity, making it difficult to achieve high-precision and high-real-time detection on embedded devices with limited computing resources.

Method used

Based on the YOLOv8 algorithm, the detection model is improved through a customized residual convolution structure, decoupling head, and attention mechanism. Combined with a high-sample-capacity fine-grained annotated dataset, channel feature fusion and positioning loss function are introduced to enhance the model's anti-occlusion and forgery capabilities and computational efficiency.

Benefits of technology

It achieves high-precision and high-robustness detection in occlusion and counterfeit attack scenarios, reduces the computational complexity of the model, and is suitable for real-time application on embedded devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119600670B_ABST
    Figure CN119600670B_ABST
Patent Text Reader

Abstract

The present invention relates to a face mask detection method based on YOLOv8 that resists occlusion and counterfeiting attacks, and belongs to the field of artificial intelligence security applications. The present invention improves the accuracy and generalization of the detection model by constructing a high-sample capacity, high-resolution face mask detection image dataset. The original YOLOv8 target detection model is improved by adopting a custom convolution module, thereby improving the convolution efficiency of the detection model, enhancing the model's feature extraction capability, and reducing computational complexity. The original YOLOv8 human pose estimation model is improved by adopting a custom module and loss function, enhancing the model's feature fusion capability and target positioning capability. A self-designed face mask detection method based on YOLOv8 that resists occlusion and counterfeiting attacks is used to achieve high-precision, high-robustness, and high-real-time face mask detection in images to be detected. The present invention can achieve real-time face mask detection and defend against occlusion and counterfeiting attacks in real detection scenarios. The custom dataset and model network structure are designed, resulting in the present invention having good detection accuracy and real-time detection performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of artificial intelligence security applications and relates to a face mask detection method based on YOLOv8 anti-occlusion counterfeit attack. Background Art

[0002] With public health and safety receiving increasing attention, deep learning-based facial mask detection has become a crucial research topic. This technology not only helps monitor and remind the public to wear masks correctly, but also reduces the harm of harmful particulate matter to the human body in specific production environments such as factories, improving overall hygiene and life safety.

[0003] Traditional facial mask detection methods rely on manual supervision, which is time-consuming and poses safety risks. Therefore, automated facial mask monitoring systems are urgently needed. With the advancement of deep learning technology, particularly with the power of GPU computing and big data, deep learning-based facial mask detection technologies are gradually maturing. These technologies, through end-to-end training of deep learning vision models, can automatically and accurately process large amounts of image data, achieving efficient and accurate mask detection.

[0004] Thanks to the rapid development of deep learning, a large number of deep learning-based detection models have emerged in academia. Most classic object detection algorithms rely on convolutional networks for feature extraction. Excellent foundational networks such as VGGNet, GoogLeNet, and ResNet have demonstrated exceptional performance in feature extraction. Currently, mainstream facial mask detection technologies fall into two categories: two-stage detection algorithms based on candidate regions and one-stage detection algorithms based on regression. While accurate, two-stage detection algorithms are slow and unsuitable for real-time detection scenarios. In contrast, one-stage detection algorithms, such as the YOLO family of algorithms, are widely used due to their speed and accuracy. YOLO algorithms perform object classification and location prediction through a single feature extraction process, making them particularly suitable for real-time scenarios. However, existing mask detection technologies, while pursuing high accuracy, fail to strike a good balance between computational complexity and speed, resulting in poor detection speed and real-time performance. Furthermore, existing facial mask detection technologies often produce incorrect predictions when the subject actively occludes their face, failing to effectively defend against occlusion-based spoofing attacks, resulting in poor robustness.

[0005] Patent application CN202410220928.45 discloses a mask detection method, system, device, medium, and program product. The method constructs and trains an initial fabric segmentation network to perform image segmentation on the face image to be detected, and uses the segmentation results to determine the mask wearing condition of the target face. The method uses the pixel ratio in the segmentation result to determine the proportion of the mouth and nose on the target face and then determines whether the target face is wearing a mask correctly. However, this detection method uses a more classic segmentation model, and the input size of the image is small, making it difficult to achieve high-resolution image segmentation. Therefore, the granularity of the detection is poor, and it is impossible to correctly determine whether the person to be detected is not wearing a mask properly. In addition, the method does not take into account the occlusion counterfeit attacks that are prone to occur in real detection scenarios, so it has poor robustness.

[0006] Patent application CN202311000170.5 describes a deep learning-based mask recognition method. This method builds a mask target detection model based on YOLOv5, uses the SPPCSPCF structure in the backbone network, and divides the feature map fed into the SPPCSPCF structure into two parts, one of which undergoes conventional convolution processing and the other undergoes SPP processing. Finally, the two parts are combined using a Concat operation. In the SPPCSPCF structure, three MaxPool2ds are set as a serial structure, reducing the number of channels in the feature map input pyramid pooling structure, thereby improving the running speed. This method uses YOLOv5s as the basis for constructing a target detection model, resulting in a large amount of computation for the model. This makes it difficult to ensure good real-time performance when computing equipment is limited. Furthermore, this method does not take into account occlusion and counterfeit attacks that are prone to occur in real-world detection scenarios, resulting in poor robustness.

[0007] Patent application CN202211664167.9 is a method and system for face mask recognition based on the improved YOLOv5. The method uses the network pruning method to compress the YOLOv5 algorithm model, optimizes the network space to reduce parameter calculation to avoid overfitting, and adds the CBAM convolution attention module after the CSP module to enhance the expression ability of dense small-scale target features; secondly, the hidden layer pruning method and the convolution kernel pruning method are used to adjust the YOLOv5 network size to reduce redundant structure, select the CIoU target loss function, and improve the model perception and reduce the prediction error by improving the YOLOv5 model bounding box loss function BBoxLoss; finally, the improved YOLOv5 is trained on the data set to obtain the corresponding algorithm model and organically combined with the face recognition system interaction interface to build a real-time face mask recognition system. In the process of data set division, this method only has two types of data samples: wearing masks correctly and not wearing masks. The granularity of data division is coarse, and it is difficult to ensure the accuracy of detection of people who wear masks improperly during the actual detection process. At the same time, this method does not take into account the occlusion and counterfeit attacks that are prone to occur in real detection scenarios, and its robustness is poor.

[0008] Patent application CN202310860746.9 is a face mask recognition method based on a convolutional neural network using HI-DisCLBP. This method is based on a convolutional neural network using HI-DisCLBP. The face is located using a three-point alignment method, and the located face image is converted from RGB color space to HI color space, and then the DisCLBP feature extraction is integrated to form a HI-DisCLBP multi-feature fusion image. The data set based on the SqueezeNet convolutional neural network deep learning model is trained until the model training results achieve the expected effect. The test is performed by cropping, enhancing, and removing noise from the face image processed by HI-DisCLBP, and the SqueezeNet convolutional neural network is integrated to extract high-level features of the image for recognition, and output the face mask wearing status. As an early deep learning classification network, the SqueezeNet convolutional neural network deep learning model can only accept low-resolution 32×32×3 images, which is incompatible with current mainstream image acquisition devices. Moreover, the model can only output classification results for a single image, making it difficult to cope with scenarios where multiple targets must be detected simultaneously in an image. In addition, this method cannot defend against occlusion and counterfeit attacks that are common in real-world detection scenarios. When the subject intentionally obscures their face, the model often gives incorrect predictions.

[0009] Patent application CN202310732956.X discloses a mask wearing recognition method based on an improved SSD algorithm. This method, based on an SSD convolutional neural network, adds Gaussian noise to the dataset, increases the brightness of some low-brightness images, and expands the sample size to obtain a training dataset with improved generalization. This method replaces the original SSD model's VGG-16 backbone with the MobieNet-V model and uses depthwise separable convolution to construct a lightweight deep neural network. The model also incorporates an ECAnet module based on the ECA attention mechanism, using a one-dimensional convolutional network module to facilitate cross-channel information exchange. During model training, this method introduces a focal loss function to reduce the impact of the loss of easily separable samples on the overall loss. As a classic two-stage CNN object detection network, SSD suffers from low detection accuracy. Furthermore, due to the large number of conventional convolutional kernel residual modules within the model, the model's computational complexity is high, resulting in poor real-time performance. Furthermore, this method cannot defend against occlusion spoofing attacks, which are common in real-world detection scenarios, and exhibits poor robustness.

[0010] Patent application CN202110740788.X describes a mask recognition method based on a depth camera. This method uses a depth camera to obtain a depth map containing a human face. The obtained depth map is then cropped to contain only the lower half of the face, and the contour of the lower half of the face is extracted. Spatial and frequency features are calculated to identify whether the face is wearing a mask and the type of mask worn. This method requires an expensive depth camera to capture images of the subject, and has strict requirements on the shooting angle. It may not be able to correctly identify the profile of the subject. Furthermore, this method cannot defend against occlusion and counterfeiting attacks that are common in real-world detection scenarios, and its robustness is poor.

[0011] Patent application CN202111181138.2 is a face mask detection system and method based on an improved FCOS. This method is based on the target detection method of FCOS (Fully Convolutional One-stage Object Detector). A PAN module is added to the neck of the model's network, and a feature pyramid network and PAN module are used for feature fusion. The image feature map is fused from the bottom up, and the underlying feature information such as texture and edge is enhanced to the feature map of each layer, thereby improving the positioning ability of the network. Finally, a fully convolutional structure is used for pixel-by-pixel prediction. This method uses Mosaic for data enhancement during training, further enhancing the detection generalization of the model. However, while enhancing the detection accuracy of the model, this method ignores the computational complexity of the model. Since the PAN module is introduced on the basis of the FCOS network, the computational complexity of the model is further increased, resulting in a slow prediction speed and poor real-time performance. In addition, the model does not consider the occlusion counterfeiting attacks that are prone to occur in the detection scene, so its robustness is poor.

[0012] Patent application CN202110105379.2 discloses a facial mask detection system and method based on the Retinaface algorithm. This method uses the Retinaface algorithm model to extract facial images of the subject and uses an additional mask detection model to perform facial mask detection. The feature extraction network of the Retinaface model uses a lightweight MobileNet V1 structure, the feature fusion layer uses an FPN structure, and the mask recognition model includes 3 convolutional layers, 3 pooling layers, and two fully connected layers. This method first obtains the facial image of the subject through an improved Retinaface model and then proceeds with facial mask detection. This is inefficient and the structure of the mask recognition model is relatively simple, making it difficult to guarantee the accuracy of the detection results. In addition, the model does not take into account occlusion and counterfeit attacks that are prone to occur in the detection scene, so it has poor robustness.

[0013] The journal "Internet of Things Technology" published an article titled "Face Detection Algorithm Based on Multi-Scale Feature Fusion" in its 7th issue in 2024. The algorithm uses the MobileNet lightweight network framework, introduces a feature pyramid fusion module and an SSH (SingleStage Headless) module, and uses two loss functions, face classification and face detection regression box, to improve the model's prediction positioning and occlusion detection capabilities. The network architecture requires only a small number of parameters while ensuring high-precision extraction of key features, and can be ported to mobile devices without GPUs for real-time operation. However, the model structure proposed in the paper only supports 224×224 low-resolution image input, which is significantly different from the resolution of current image acquisition devices. In addition, the experimental part of the paper only gives the model's performance in classifying people, and does not provide data on prediction box regression. In addition, the compared models are relatively classic models, and no experimental data for cutting-edge models is provided. It is impossible to reflect the advantages or disadvantages of the detection method proposed in the paper compared with current advanced methods.

[0014] The journal Computer Engineering and Design, issue 9 of 2023, published a paper titled "Facial Mask Detection Based on Improved YOLOv5." This paper describes a facial mask detection method based on an improved YOLOv5. It introduces an improved DenseNet (densely connected convolutional network) to improve network feature utilization and anti-interference capabilities. It also increases detection head parameters, connects features at different scales across levels, enhances multi-scale information exchange, and improves the network's detection performance for small-scale targets. It also replaces the original GIoU loss function with CIoU to address the issue of slow model convergence. However, this paper does not consider model lightweighting. The introduction of DenseNet and an additional detection head significantly increases the computational complexity of the model, significantly reducing detection speed and real-time performance. The paper also fails to consider occlusion and forgery attacks, which are common in real-world detection scenarios, resulting in poor robustness.

[0015] The journal "Electronic Design Engineering" published a paper titled "Research on Mask Wearing Detection Based on Improved YOLOv5 Algorithm" in issue 22 of 2022. This paper is based on the improved YOLOv5s target detection model. For small-target face mask detection, it introduces an additional detection head network to improve the model's detection capability for small-sized targets in dense scenes. In order to improve the model's missed detection of smaller targets, the paper adds a set of additional Anchor values ​​during the model training phase. However, the paper did not carry out any work related to the lightweighting of the model. Since the author chose to make improvements based on the larger YOLOv5s model and introduced an additional detection head network, the detection speed and real-time performance of the model decreased significantly. In addition, the method proposed in the paper cannot defend against occlusion and counterfeit attacks in real detection scenarios.

[0016] The journal "Journal of Southwest Jiaotong University" published an article in Issue 5 of 2021 titled "Faster R-CNN Mask Face Detection Model with Multi-Scale Attention Learning". For mask tasks, the MSAF R-CNN mask face detection model was proposed. The paper first introduced the Res2Net module into the original Faster R-CNN model to extract fine-grained multi-scale features of the target; then, the SCA-Res2Net module was constructed by combining the channel and spatial attention mechanisms to adaptively locate global and local useful multi-scale features; finally, the WSPP-Net sub-module was embedded at the top of the network to expand the amount of sub-class feature information from coarse-grained to fine-grained. The face mask detection scheme in this paper divides the samples into only two categories: wearing a mask and wearing a mask. When the person being tested does not wear a mask properly, the model may give an incorrect prediction result; and the model cannot defend against occlusion and counterfeit attacks that are prone to occur in real detection scenarios, and its robustness is poor. Summary of the Invention

[0017] In response to the above-mentioned problems that the face mask detection method based on deep learning has high model computational complexity, poor feasibility, is not suitable for deployment in embedded devices with limited computing resources, is prone to misjudgment when the person being detected occludes the face, and has poor robustness, the present invention designs a face mask recognition method based on YOLOv8 anti-occlusion and forgery. This method is based on the YOLOv8 artificial intelligence vision algorithm and, by designing an anti-occlusion and forgery face mask detection method, has good robustness while ensuring high-precision and high-real-time face mask detection.

[0018] In order to achieve the above objectives, the present invention provides the following technical solutions:

[0019] The present invention provides a face mask recognition method based on YOLOv8 anti-occlusion and counterfeiting, comprising a face mask data set construction module, a face mask detection model construction module based on YOLOv8, a human posture estimation model construction module based on YOLOv8, a model training module, a face mask detection module based on YOLOv8 anti-occlusion and counterfeiting attack, and a universal image acquisition module. The universal image acquisition module is not within the scope of protection and is characterized by:

[0020] The face mask dataset construction module is based on a public face mask detection dataset. It first filters low-resolution image data by calculating the image resolution, then uses annotation software to annotate the image data, and finally divides the dataset into a training set and a validation set according to the ratio. Finally, the dataset is transferred to the model training module.

[0021] The YOLOv8-based face mask detection model building module first uses a custom residual convolution structure to improve the neck network of the initial YOLOv8 object detection model network, and then uses a custom decoupling head structure to improve the detection head of the model; finally, a custom attention-based convolution structure is used to improve the backbone network of the model, and the face mask detection model to be trained is obtained and transmitted to the model training module;

[0022] The YOLOv8-based human posture estimation model building module first uses a customized feature fusion structure to improve the neck network of the original YOLOv8 human posture estimation model network, and finally uses a customized positioning loss function to improve the positioning loss function of the model, obtains the human posture estimation model to be trained and transmits it to the model training module;

[0023] The model training module first uses the training set data in the face mask dataset construction module and the target detection model in the face mask detection model construction module based on YOLOv8 to perform data training to obtain a face mask detection model; then uses the open source COCO-Pose dataset and the human pose estimation model in the human pose estimation model construction module based on YOLOv8 to perform data training to obtain a human pose estimation model;

[0024] The YOLOv8-based anti-occlusion and counterfeit attack face mask detection module is responsible for performing anti-occlusion and counterfeit attack face mask detection on the image to be detected obtained from the image acquisition module. The image will be subjected to face mask detection and occlusion and counterfeit attack detection in sequence. After the detection is completed, the detection result is returned to the user's image acquisition module;

[0025] As a further improvement of the present invention, the face mask dataset construction module first performs resolution screening on the open source face mask dataset (SF-MASK, Mask Wearing). When the pixels of the picture with a length of w and a height of h are: w×h>=160000px, the picture is retained; then, these pictures are manually labeled using labelme software, and the targets in the pictures who are not wearing masks are marked as "no mask", the targets who are not wearing masks properly are marked as "mistake mask", and the targets who are wearing masks correctly are marked as "mask"; then, the picture set is divided into two parts, three quarters as a training set, and the remaining quarter as a validation set. Finally, the data set is transferred to the face mask detection model training module based on YOLOv8.

[0026] As a further improvement of the present invention, the YOLOv8-based face mask detection model building module includes a convolution optimization module; a detection head network acceleration module; a feature extraction enhancement module, which is responsible for improving and building the YOLOv8-based face mask detection model and transferring the model to the model training module;

[0027] The convolution optimization module uses a custom residual convolution structure to improve the C2f module in the original YOLOv8 neck network for the original YOLOv8 target detection model. The custom residual convolution structure is: when the input feature map is F in First, a 1×1 convolution is performed, and then two branches are obtained by average segmentation of the channels. Then to F P1 forward The continuous channels are convolved, and then the SILU activation function and the subsequent two 1×1 convolutions are obtained. F FN1 Then passed before The continuous channels are convolved, the SILU activation function and the subsequent two 1×1 convolutions are used to obtain F FN2 , put F P1 ,F P2 ,F FN1 ,F FN2 The four features are spliced ​​together in the channel dimension to obtain Finally, a 1×1 convolution is used to obtain the output The improved convolution module FC2f is obtained. Finally, the module and the model parameters of the convolution module, splicing module, upsampling module, and loss function in the original YOLOv8 target detection model are transferred to the detection head network acceleration module.

[0028] The detection head network acceleration module (2-2) uses a custom decoupling head module to improve the detection head network of the model. The custom decoupling head module is: when the input feature map is F in First pass before The continuous channel convolution operation, SILU activation function, two 1×1 convolutions and a regular convolution module are obtained Then F FN After two parallel 1×1 convolution branches, it is used to generate the classification prediction information Pred of the original image. Cls =Conv Cls (F FN ) and bounding box prediction information Pred Bbox =Conv Bbox (F FN), where Conv Cls It is a 1×1 convolution operation that maps deep features to the target category space and obtains confidence scores for each category. Bbox It is a 1×1 convolution operation corresponding to the bounding box position information of each pixel in the feature map, thereby obtaining an improved detection head network acceleration module FHead; finally, this module and the model parameters received from the convolution optimization module are transmitted to the feature extraction enhancement module;

[0029] The feature extraction enhancement module replaces the C2f module in the original YOLOv8 backbone network with a custom convolutional structure based on the attention mechanism. The attention mechanism consists of two branches: channel branch and spatial branch. Given an input feature map The output of this custom attention mechanism in is the channel branch output, is the spatial branch output; in the channel branch, the channel branch output ⊙ ch It is a multiplication operation of the channel dimension, and the channel branch attention A ch (X in )=F SG [W z (σ1(W v (X in ))×F SM (σ2(W q (X in ))))], where W q ,W v , and W z is a 1×1 convolution operation, σ1 and σ2 are data shape modification operations, F SM (·) is the Softmax operation, “×” is the matrix multiplication operation, F SG (·) is the Sigmoid operation; in the spatial branch, the spatial branch output Spatial attention branch Where W q and W v is a 1×1 convolution operation, σ l ,σ2, and σ3 are data shape modification operations,F GP is a global pooling operation,⊙ sp It is an operation of performing element-by-element multiplication on the data in the spatial dimension, thereby obtaining an improved feature extraction module PFC2f module; finally, the module and the model parameters received from the detection head network acceleration module (2-2) are transmitted to the face mask detection model training module based on YOLOv8 (4-1);

[0030] As a further improvement of the present invention, the human posture estimation model building module based on YOLOv8 includes a channel feature fusion enhancement module and a loss function improvement module, which is responsible for improving and building the human posture estimation model based on YOLOv8 and transferring the model to the model training module;

[0031] The channel feature fusion enhancement module is based on the original YOLOv8 human posture estimation model. It uses a custom feature fusion module to improve all Concat modules in the neck network of the original YOLOv8 human posture estimation network. The custom feature fusion module is: when the input feature maps are F1 and F2, it first initializes two learnable weights W1 and W2, and then quickly normalizes the two weights to calculate ∈ is a small constant, set to 0.0001, and the output of the custom feature fusion module is Concat((W n1 ×F1), (W n2 ×F2)), where Concat is a channel-dimensional concatenation operation, resulting in an improved channel feature fusion module FConcat. Finally, the module and the model parameters of the original YOLOv8 human pose estimation model, including the convolution module, concatenation module, upsampling module, and detection head module, are transferred to the loss function improvement module.

[0032] The loss function improvement module receives the model transmitted by the channel feature fusion enhancement module and uses a custom positioning loss function to improve the positioning loss function of the model. The custom positioning loss function is calculated as: L = L IoU +L dis +L asp , where the intersection loss L IoU =1-IOU; distance loss and edge length loss IOU is the intersection-over-union ratio between the predicted box and the true box, w and h represent the width and height of the predicted bounding box respectively. gt and h gt Represents the width and height of the ground-truth bounding box, w c and h c is the width and length of the minimum rectangle covering the prediction box and the label box, ρ is the Euclidean distance of the center point variable, and the improved loss function is obtained; finally, the loss function and the model parameters received from the channel feature fusion enhancement module are transmitted to the human posture estimation model training module based on YOLOv8.

[0033] As a further improvement of the present invention, the model training module includes a face mask detection model training module based on YOLOv8 and a human posture estimation model training module based on YOLOv8, which is responsible for training and evaluating the face mask detection model and the human posture estimation model, and transmitting the trained model to the face mask detection module based on YOLOv8 anti-occlusion counterfeiting attack;

[0034] The YOLOv8-based face mask detection model training module performs data training on the target detection model obtained from the YOLOv8 face mask detection model building module based on the training set data in the face mask data set building module to obtain a face mask detection model. In a distributed system with n available GPUs, the system sets the number of samples processed at one time to 16×n, the size of the input image is 640×640, and the total number of training rounds is 300. During the training process, the model obtained from each round of training is evaluated using a validation set for model performance. After the training is completed, the model is transferred to the face mask detection module.

[0035] The YOLOv8-based human pose estimation model training module is based on the open source COCO-Pose dataset, and performs data training on the human pose estimation model obtained from the YOLOv8 human pose estimation model building module to obtain a human pose estimation model; in a distributed system with n available GPUs, the system sets the number of samples processed at one time to 16×n, the input image size to 640×640, and the total number of training rounds to 500; after training, the model is transmitted to the occlusion and forgery attack detection module.

[0036] As a further improvement of the present invention, the face mask detection module based on YOLOv8 anti-occlusion and counterfeit attack includes a face mask detection module and an occlusion and counterfeit attack detection module, which is responsible for detecting the image to be detected obtained from the general image acquisition module and returning the detection result to the image acquisition module;

[0037] The face mask detection module first receives the face mask detection model transmitted by the face mask detection model training module based on YOLOv8, then sets the detection confidence threshold to 0.75, sets the face mask detection results to: 0-not wearing a mask, 1-not wearing a mask properly, 2-wearing a mask correctly, 3-no obvious face target detected, and at the same time obtains the image to be detected from the general image acquisition module, adjusts the image to a resolution of 640×640 by scaling and grayscale filling, and then passes the image to the face mask detection model for prediction. The model prediction results include the bounding box coordinates of the face of the person being detected, the target classification and confidence Conf mask ∈(0,1), where the bounding box coordinates include the upper left corner coordinates and the lower right corner coordinates When Conf mask >0.75 and Get the test result 0, when Conf mask >0.75 and When the test result is 1, when Conf mask >0.75 and When , the detection result 2 is obtained, and the detection result 3 is obtained in other cases. Finally, the image to be detected and the detection result are passed to the occlusion and forgery attack detection module;

[0038] The anti-occlusion counterfeit attack detection module first receives the human posture estimation model transmitted by the human posture estimation model training module based on YOLOv8 and the detection results of the face mask detection module, then sets the confidence of the key points of the detected person to 0.75, and sets the anti-occlusion counterfeit attack detection results to: a-occlusion counterfeit attack exists, b-no occlusion counterfeit attack exists, and then passes the image to be detected to the human posture estimation model for prediction. The prediction result of the model is the position information and confidence information of the key points of the hands of the detected person, where the position information of the key points of the left hand is The confidence level is The position information of the right hand key point is The confidence level is when and or and When the detection result is a, the detection result is b. Finally, the detection result (a or b) and the detection result of the face mask detection module (0 or 1 or 2 or 3) are returned to the image acquisition module to display the final output result.

[0039] An electronic device includes a memory, a processor, and a computer program stored in the memory and runnable on the processor. When the processor executes the program, the method for detecting facial masks based on YOLOv8 to resist occlusion and counterfeit attacks is implemented.

[0040] A computer-readable storage medium stores computer instructions, which, when executed by a processor, implement the YOLOv8-based anti-occlusion and counterfeit attack face mask detection method.

[0041] Beneficial effects

[0042] Compared with the prior art, the beneficial effects of the present invention are as follows: the present invention provides a face mask detection method based on YOLOv8 anti-occlusion and counterfeiting; the present invention constructs a face mask detection data set with high sample capacity and fine-grained annotation, thereby enhancing the generalization and detection accuracy of the model; a convolution optimization module, a detection head network acceleration module and a feature extraction enhancement module are introduced on the basis of the original YOLOv8 target detection model network, thereby effectively improving the accuracy of the face mask detection model while significantly reducing the computational complexity of the model, thereby ensuring high accuracy and high real-time performance of the model output; a channel feature fusion enhancement module and a loss function improvement module are introduced on the basis of the original YOLOv8 human posture estimation model network, thereby effectively improving the detection accuracy of the human posture estimation model; the present method is based on the YOLOv8 deep learning visual algorithm, and by sequentially performing face mask detection and occlusion and counterfeiting detection algorithms on images to be detected, effectively defends against occlusion and counterfeiting attacks that may occur in real detection scenarios, thereby achieving high-precision and high-robust face mask detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] Figure 1 It is a system diagram of the present invention.

[0044] Figure 2 It is an overall block diagram of the present invention as a whole,

[0045] Figure 3 is a flowchart of the face mask dataset construction module of the present invention,

[0046] Figure 4 is the model training flow chart of the present invention,

[0047] Figure 5 This is a flow chart of the anti-occlusion counterfeit face mask detection method of the present invention. DETAILED DESCRIPTION

[0048] In order to deepen the understanding of the present invention, this embodiment is described in detail below with reference to the accompanying drawings.

[0049] Embodiment 1: A face mask detection method based on YOLOv8 against occlusion and counterfeit attacks, the detection system used includes a face mask dataset construction module 1, a face mask detection model construction module based on YOLOv8 2, a human posture estimation model construction module based on YOLOv8 3, a model training module 4, a face mask detection module based on YOLOv8 against occlusion and counterfeit attacks 5, and a general image acquisition module.

[0050] The face mask data set construction module (1) first uses resolution calculation to filter based on the open source mask detection image data set (SF-MASK, Mask Wearing), and then manually labels based on labelme software. Finally, these image data are divided into two parts: training set and verification set, and transmitted to the face mask detection model training module 4; the face mask detection model construction module (2) based on YOLOv8, for the initial YOLOv8 target detection model, first improves the neck network of the YOLOv8 target detection model network through a customized residual convolution structure, and then improves the detection head network of the original YOLOv8 target detection model network through a customized decoupling head structure, and finally improves the detection head network of the original YOLOv8 target detection model network through a customized decoupling head structure. The convolution structure based on the attention mechanism is defined, the backbone network of the YOLOv8 target detection model network is improved, the face mask detection model to be trained is obtained, and the model and parameters are transferred to the face mask detection model training module 4; the human posture estimation model building module 3 based on YOLOv8, for the initial YOLOv8 human posture estimation model, firstly improves the neck network of the YOLOv8 human posture estimation model network through a custom feature fusion structure, and finally improves the original YOLOv8 human posture estimation model network positioning loss function through a custom positioning loss function, and obtains the human posture estimation model to be trained. The human body posture estimation model is constructed, and the model and parameters are transmitted to the face mask detection model training module 4; the model training module 4 first receives the training set data in the face mask data set construction module 1, and uses the target detection model network in the face mask detection model construction module 2 based on YOLOv8 to perform data training to obtain the face mask detection model; then, the open source COCO-Pose data set is used, and the human body posture estimation model network in the human body posture estimation model construction module 3 based on YOLOv8 is used for data training, and the trained face mask detection model and human body posture estimation model are trained. Transmitted to the YOLOv8-based anti-occlusion and counterfeit attack face mask detection module 5; the YOLOv8-based anti-occlusion and counterfeit attack face mask detection module 5 first receives the face mask detection model and the human body posture estimation model from the model training module 4. After the detection starts, the picture to be detected is obtained from the general image acquisition module, and then the picture is subjected to anti-occlusion and counterfeit attack face mask detection. The detection process is divided into two steps. The first step is face mask detection based on the face mask detection model, and the second step is anti-occlusion and counterfeit detection based on the human body posture estimation model. After the detection is completed, the detection result is returned to the general image acquisition module.

[0051] The face mask dataset construction module (1) first performs resolution screening on the open source face mask dataset (SF-MASK, Mask Wearing), and retains the image if the pixel of the image with a length of w and a height of h is: w×h>=160000px; then, manually annotates these images using labelme software, and marks the target without wearing a mask in the image as "no mask", the target without wearing a mask in a standard way as "mistake mask", and the target with wearing a mask correctly as "mask"; then, divides the image set into two parts, with three quarters as a training set and the remaining quarter as a validation set, and finally transmits the data set to the face mask detection model training module 4-1 based on YOLOv8. The face mask detection model building module 2 based on YOLOv8 improves and constructs the face mask detection model based on YOLOv8, including a convolution optimization module 2-1, a detection head network acceleration module 2-2 and a feature extraction enhancement module 2-3; the convolution optimization module 2-1 uses a custom residual convolution structure to improve the C2f module in the original YOLOv8 neck network for the original YOLOv8 target detection model. The custom residual convolution structure is: when the input feature map is F in First, a 1×1 convolution is performed, and then two branches are obtained by average channel splitting. Then to F P1 forward The continuous channels are convolved, and then the SILU activation function and the subsequent two 1×1 convolutions are obtained. F FN1 Then passed before The continuous channels are convolved, the SILU activation function and the subsequent two 1×1 convolutions are used to obtain F FN2 , put F P1 ,F P2 ,F FN1 ,F FN2 The four features are spliced ​​together in the channel dimension to obtain Finally, a 1×1 convolution is used to obtain the output The improved convolution module FC2f is obtained. Finally, the module and the model parameters of the convolution module, splicing module, upsampling module, and loss function in the original YOLOv8 target detection model are transmitted to the detection head network acceleration module 2-2.

[0052] The detection head network acceleration module 2-2 uses a custom decoupling head module to improve the detection head network of the model. The custom decoupling head module is: when the input feature map is F in First pass before The continuous channel convolution operation, SILU activation function, two 1×1 convolutions and a regular convolution module are obtained Then F FN After two parallel 1×1 convolution branches, it is used to generate the classification prediction Pred of the original image Cls =Conv Cls (F FN ) and bounding box prediction information Pred Bbox =Conv Bbox (F FN ), where Conv Cls It is a 1×1 convolution operation that maps deep features to the target category space and obtains confidence scores for each category. Bbox It is a 1×1 convolution operation corresponding to the bounding box position information of each pixel in the feature map, thereby obtaining an improved detection head network acceleration module FHead; finally, this module and the model parameters received from the convolution optimization module 2-1 are transmitted to the feature extraction enhancement module 2-3;

[0053] The feature extraction enhancement module 2-3 uses a custom convolutional structure based on the attention mechanism to improve the C2f module in the YOLOv8 backbone network. The custom convolutional structure based on the attention mechanism includes two branches: channel branch and spatial branch. Given an input feature map The custom attention mechanism output in is the channel branch output, is the spatial branch output; in the channel branch, the channel branch output ⊙ ch It is a multiplication operation of the channel dimension, and the channel branch attention A ch (X in )=F SG [W z (σ1(W v (X in ))×F SM (σ2(W q (X in ))))], where W q ,W v , and W z is a 1×1 convolution operation, σ1 and σ2 are data shape modification operations, F SM (·) is the Softmax operation, “×” is the matrix multiplication operation, F SG (·) is the Sigmoid operation; in the spatial branch, the spatial branch output Spatial attention branch Where Wq and W v is a 1×1 convolution operation, σ l ,σ2, and σ3 are data shape modification operations,F GP is a global pooling operation,⊙ sp This is an element-by-element multiplication operation on the data in the spatial dimension, thereby obtaining an improved feature extraction module PFC2f. Finally, this module and the model parameters received from the detection head network acceleration module 2-2 are transmitted to the YOLOv8-based face mask detection model training module 4-1. The YOLOv8-based human pose estimation model construction module 3 improves and constructs the YOLOv8-based human pose estimation model, including the channel feature fusion enhancement module 3-1 and the loss function improvement module 3-2.

[0054] The channel feature fusion enhancement module 3-1 uses a custom feature fusion module to improve all Concat modules in the neck network of the original YOLOv8 human posture estimation network for the original YOLOv8 human posture estimation model. The custom feature fusion module is: when the input feature maps are F1 and F2, first initialize two learnable weights W1 and W2, then quickly normalize the two weights and calculate ∈ is a small constant, set to 0.0001, and the output of the custom feature fusion module is Concat((W n1 ×F1),(W n2 ×F2)), where Concat is a channel-dimensional splicing operation, thereby obtaining an improved channel feature fusion module FConcat module. Finally, the module and the model parameters of the original YOLOv8 human pose estimation model, such as the convolution module, splicing module, upsampling module, and detection head module, are transferred to the loss function improvement module (3-2);

[0055] The loss function improvement module (3-2) uses a custom positioning loss function to improve the positioning loss function of the model. The custom positioning loss function is calculated as: L = L IoU +L dis +L asp , where the intersection loss L IoU =1-IOU; distance loss and edge length loss IOU is the intersection-over-union ratio between the predicted box and the true box, w and h represent the width and height of the predicted bounding box respectively. gt and h gt Represents the width and height of the ground-truth bounding box, w c and h cis the width and length of the minimum rectangle covering the prediction box and the label box, and ρ is the Euclidean distance of the center point variable, thereby obtaining an improved loss function; finally, the loss function and the model parameters received from the channel feature fusion enhancement module 3-1 are transmitted to the human pose estimation model training module 4-2 based on YOLOv8. The model training module 4 is responsible for training the face mask and human pose estimation model, including the face mask detection model training module 4-1 based on YOLOv8 and the human pose estimation model training module 4-2 based on YOLOv8;

[0056] The YOLOv8-based face mask detection model training module 4-1 performs data training on the target detection model obtained from the YOLOv8 face mask detection model building module 2 based on the training set data in the face mask data set construction module 1 to obtain a face mask detection model. In a distributed system consisting of n available GPUs, the system sets the number of samples processed at one time to 16×n, the initial learning rate to 0.001, the size of the input image to 640×640, and the total number of training rounds to 300. After the training is completed, the trained face mask detection model parameters are transmitted to the face mask detection module 5-1;

[0057] The YOLOv8-based human pose estimation model training module 4-2 is based on the open source COCO-Pose dataset, and performs data training on the human pose estimation model obtained from the YOLOv8-based human pose estimation model building module 3 to obtain a human pose estimation model; in a distributed system consisting of n available GPUs, the system sets the number of samples processed at one time to 16×n, the initial learning rate to 0.001, the input image size to 640×640, and the total number of training rounds to 500; after the training is completed, the trained human pose estimation model parameters are transmitted to the occlusion counterfeit attack detection module 5-2.

[0058] 7. A YOLOv8-based anti-occlusion counterfeit attack face mask detection method according to claim 1, characterized in that the YOLOv8-based anti-occlusion counterfeit attack face mask detection module 5 is responsible for detecting the image to be detected obtained from the general image acquisition module and returning the detection result to the image acquisition module, including a face mask detection module 5-1 and an occlusion counterfeit attack detection module 5-2;

[0059] The face mask detection module 5-1 first receives the face mask detection model transmitted by the face mask detection model training module (4-1) based on YOLOv8, then sets the detection confidence threshold to 0.75, and sets the face mask detection results to: 0-not wearing a mask, 1-not wearing a mask properly, 2-wearing a mask correctly, 3-no obvious face target detected, and at the same time obtains the image to be detected from the general image acquisition module, adjusts the image to a resolution of 640×640 by scaling and grayscale filling, and then passes the image to the face mask detection model for prediction. The model prediction results include the bounding box coordinates of the face of the person being detected, the target classification and confidence Conf mask ∈(0,1), where the bounding box coordinates include the upper left corner coordinates and the lower right corner coordinates When Conf mask >0.75 and When the test result is 0, when Conf mask >0.75 and When the test result is 1, when Conf mask >0.75 and , the detection result 2 is obtained, and the detection result 3 is obtained in other cases. Finally, the image to be detected and the detection result are passed to the occlusion counterfeit attack detection module 5-2; the anti-occlusion counterfeit attack detection module 5-2 first receives the human posture estimation model transmitted by the human posture estimation model training module 4-2 based on YOLOv8 and the detection result of the face mask detection module 5-1, and then sets the confidence of the key points of the hand of the person being detected to 0.75, and sets the anti-occlusion counterfeit attack detection result to: a-there is an occlusion counterfeit attack, b-there is no occlusion counterfeit attack, and then passes the image to be detected to the human posture estimation model for prediction. The prediction result of the model is the position information and confidence information of the key points of both hands of the person to be detected, where the position information of the key points of the left hand is The confidence level is The position information of the right hand key point is The confidence level is when and or and When the detection result is a, the detection result is b. Finally, the detection result (a or b) and the detection result (0 or 1 or 2 or 3) of the face mask detection module 5-1 are returned to the image acquisition module to display the final output result.

[0060] The details are as follows:

[0061] like Figure 1This is a system diagram of the present invention, which is applicable to most facial mask detection scenarios. The cloud-based distributed training server cluster of the present invention is used to train facial mask detection models and human posture estimation models, and sends the trained models to the cloud-based distributed detection server cluster; the detection end of the present invention is a picture shooting and acquisition device responsible for collecting photos of the person to be detected for facial mask detection, and sending the collected photos to the cloud-based distributed detection server cluster via the network; the cloud-based distributed detection server cluster of the present invention receives the pictures to be detected transmitted by the detection end, and through a distributed load balancing algorithm, the currently available server performs anti-occlusion and counterfeiting facial mask detection on the collected photos, and returns the detection results to the detection end device.

[0062] like Figure 2This is the overall block diagram of the present invention. The proposed method for detecting facial masks based on YOLOv8 to resist occlusion and counterfeiting includes: a facial mask dataset construction module 1, a facial mask detection model construction module 2 based on YOLOv8, a human posture estimation model construction module 3 based on YOLOv8, a model training module 4, and a facial mask detection module 5 based on YOLOv8 to resist occlusion and counterfeiting attacks. Among them, the facial mask dataset construction module 1 is responsible for constructing a facial mask detection dataset for training the facial mask detection model. The YOLOv8-based face mask detection model construction module 2 is responsible for the preliminary definition and construction of the YOLOv8-based face mask detection model network, including three sub-modules, namely the convolution optimization module 2-1, the detection head network acceleration module 2-2 and the feature extraction enhancement module 2-3. The convolution optimization module 2-1 is responsible for introducing a custom residual convolution structure into the backbone network of the original YOLOv8 model network; the detection head network acceleration module 2-2 is responsible for receiving the model of 2-1 and introducing a custom decoupling head into the model network; the feature extraction enhancement module 2-3 is responsible for receiving the model of 2-2 and introducing a custom attention convolution structure into the backbone network of the model. The YOLOv8-based human pose estimation model building module 3 is responsible for building the YOLOv8-based human pose estimation model network, which includes two sub-modules, namely the channel feature fusion enhancement module 3-1 and the loss function improvement module 3-2. The channel feature fusion enhancement module 3-1 is responsible for introducing a custom channel feature fusion module into the initial YOLOv8 human pose estimation model network, and the loss function improvement module 3-2 is responsible for receiving the model of 3-1 and using a custom bounding box loss function to improve the bounding box loss function. The model training module 4 is responsible for model training, which consists of two modules, namely the face mask detection model training module 4-1 based on YOLOv8 and the human posture estimation model training module 4-2 based on YOLOv8. The face mask detection model training module 4-1 based on YOLOv8 adopts the training set data in the face mask dataset construction module 1, and uses the target detection model network in the face mask detection model construction module 2 based on YOLOv8 to perform data training to obtain the face mask detection model, and transmit it to the face mask detection module 5-1. The human posture estimation model training module 4-2 based on YOLOv8 adopts the open source COCO-Pose dataset, and uses the human posture estimation model network in the human posture estimation model construction module 3 based on YOLOv8 to perform data training to obtain the human posture estimation model, and transmit it to the occlusion and counterfeiting attack detection module 5-2.The face mask detection module 5 based on YOLOv8 anti-occlusion and counterfeit attack is responsible for performing face mask detection against occlusion and counterfeit attacks on the image to be detected. It includes two modules, namely the face mask detection module 5-1 and the occlusion and counterfeit attack detection module 5-2. The face mask detection module 5-1 is responsible for performing preliminary face mask detection on the image to be detected and judging whether the person being detected is wearing the mask correctly. The occlusion and counterfeit attack detection module 5-1 is responsible for performing occlusion and counterfeit attack detection on the image to be detected and judging whether the person being detected has occlusion and counterfeit attack behavior. After the detection is completed, the detection result is returned to the image acquisition module.

[0063] like Figure 3 This is a flowchart of the face mask dataset construction module of the present invention. The face mask dataset construction module first collects and organizes a public image dataset related to face mask detection (SF-MASK, Mask Wearing); then, the image data is filtered by calculating the image resolution. When the pixel of the image with a length of w and a height of h is: w×h>=160000px, the image is retained; then, these images are manually labeled using Labelme software. The objects in the image wearing a mask properly are labeled as "mask", the objects wearing a mask improperly are labeled as "mistake mask", and the objects not wearing a mask are labeled as "no mask"; finally, the image set is divided into two parts, with three-quarters used as a training set and the remaining quarter as a validation set.

[0064] like Figure 4 This is a flowchart of the model training module of the present invention. The module first preprocesses the training data, resizing the image to a 640×640 resolution through scaling and grayscale padding. After training begins, the training loss for the current iteration is calculated based on the loss function. Backpropagation and model parameter updates are then performed. After the parameter updates, the model performance is evaluated using a validation set. After the iterations are complete, the model with the highest accuracy is selected.

[0065] like Figure 5 This is the flow chart of face mask detection in the present invention. The image to be detected is first adjusted to a resolution of 640×640 by scaling and grayscale filling, and then the image is passed to the face mask detection model for prediction; the model's prediction results include the bounding box coordinates of the face of the person being detected, the target classification and confidence Conf mask ∈(0,1), where the bounding box coordinates include the upper left corner coordinates and the lower right corner coordinates When Conf mask >0.75 and When the face mask detection result is 0 (the value to be detected is not wearing a mask), when Conf mask >0.75 and When the face mask detection result is 1 (not wearing a mask properly), when Conf mask >0.75 and , the test result 2 (correctly wearing a mask) is obtained, and the test result 3 (no obvious face target is detected) is obtained in other cases; then the image to be tested is passed to the human posture estimation model for prediction. The prediction result of the model is the position information and confidence information of the key points of the hands of the person to be tested, where the position information of the key point of the left hand is The confidence level is The position information of the right hand key point is The confidence level is when and or and When the anti-occlusion counterfeit attack detection result a is obtained (occlusion counterfeit attack exists), otherwise, the anti-occlusion counterfeit attack detection result b is obtained (occlusion counterfeit attack does not exist); finally, the detection result (a or b) and the face mask detection result (0 or 1 or 2 or 3) are returned to the image acquisition module together, and the final result is displayed and output.

[0066] It should be noted that the above embodiments are not intended to limit the scope of protection of the present invention, and equivalent changes or substitutions made on the basis of the above technical solutions fall within the scope of protection of the claims of the present invention.

Claims

1. A face mask detection method based on YOLOv8 to resist occlusion and counterfeit attacks, characterized by: The detection system used includes a face mask dataset construction module (1), a face mask detection model construction module based on YOLOv8 (2), a human posture estimation model construction module based on YOLOv8 (3), a model training module (4), a face mask detection module based on YOLOv8 to resist occlusion and counterfeiting attacks (5), and a general image acquisition module. The face mask dataset construction module (1) first uses resolution calculation to filter the open source mask detection image dataset, then manually labels it based on the Labelme software, and finally divides the image data into a training set and a validation set, and transmits them to the face mask detection model training module (4); The YOLOv8-based face mask detection model building module (2) first improves the neck network of the YOLOv8 target detection model network through a customized residual convolution structure for the initial YOLOv8 target detection model, then improves the detection head network of the original YOLOv8 target detection model network through a customized decoupling head structure, and finally improves the backbone network of the YOLOv8 target detection model network through a customized attention mechanism-based convolution structure to obtain a face mask detection model to be trained, and transmits the model and parameters to the face mask detection model training module (4); The YOLOv8-based human posture estimation model building module (3) first improves the neck network of the YOLOv8 human posture estimation model network by using a custom feature fusion structure for the initial YOLOv8 human posture estimation model, and finally improves the original YOLOv8 human posture estimation model network positioning loss function by using a custom positioning loss function to obtain a human posture estimation model to be trained, and transmits the model and parameters to the face mask detection model training module (4); The model training module (4) first receives the training set data in the face mask data set construction module (1), uses the target detection model network in the face mask detection model construction module (2) based on YOLOv8 to perform data training, and obtains the face mask detection model; then uses the open source COCO-Pose data set, uses the human posture estimation model network in the human posture estimation model construction module (3) based on YOLOv8 to perform data training, and transmits the trained face mask detection model and human posture estimation model to the face mask detection module (5) based on YOLOv8 for anti-occlusion and counterfeiting attacks; The YOLOv8-based anti-occlusion counterfeit attack face mask detection module (5) first receives the face mask detection model and the human body posture estimation model from the model training module (4). After the detection starts, the image to be detected is obtained from the general image acquisition module, and then the image is subjected to anti-occlusion counterfeit attack face mask detection. The detection process is divided into two steps: the first step is face mask detection based on the face mask detection model, and the second step is anti-occlusion counterfeit detection based on the human body posture estimation model. After the detection is completed, the detection result is returned to the general image acquisition module. A face mask detection model building module based on YOLOv8 (2) improves and builds a face mask detection model based on YOLOv8, including a convolution optimization module (2-1), a detection head network acceleration module (2-2) and a feature extraction enhancement module (2-3); The convolution optimization module (2-1) uses a custom residual convolution structure to improve the C2f module in the original YOLOv8 neck network for the original YOLOv8 target detection model. The custom residual convolution structure is: when the input feature map is F in ∈ F in First, a 1×1 convolution is performed, and then two branches are obtained by average channel splitting. Then to F P1 forward The continuous channels are convolved, and then the SILU activation function and the subsequent two 1×1 convolutions are obtained. F FN1 Then passed before The continuous channels are convolved, the SILU activation function and the subsequent two 1×1 convolutions are used to obtain F FN2 , put F P1 ,F P2 ,F FN1 ,F FN2 The four features are spliced ​​together in the channel dimension to obtain Finally, a 1×1 convolution is used to obtain the output The improved convolution module FC2f is obtained. Finally, the module and the model parameters of the convolution module, splicing module, upsampling module, and loss function in the original YOLOv8 target detection model are transmitted to the detection head network acceleration module (2-2). The detection head network acceleration module (2-2) uses a custom decoupling head module to improve the detection head network of the model. The custom decoupling head module is: when the input feature map is F in First pass before The continuous channel convolution operation, SILU activation function, two 1×1 convolutions and a regular convolution module are obtained Then F FN After two parallel 1×1 convolution branches, it is used to generate the classification prediction Pred of the original image Cls =Conv Cls (F FN ) and bounding box prediction information Pred Bbox =Conv Bbox (F FN ), where Conv Cls It is a 1×1 convolution operation that maps deep features to the target category space and obtains confidence scores for each category. Bbox It is a 1×1 convolution operation corresponding to the bounding box position information of each pixel in the feature map, thereby obtaining an improved detection head network acceleration module FHead; finally, this module and the model parameters received from the convolution optimization module (2-1) are transmitted to the feature extraction enhancement module (2-3); Feature extraction enhancement module (2-3), using a custom convolutional structure based on the attention mechanism to improve the C2f module in the YOLOv8 backbone network. The custom convolutional structure based on the attention mechanism includes two branches: channel branch and spatial branch. Given an input feature map The custom attention mechanism output in is the channel branch output, Output for the spatial branch; In the channel branch, the channel branch output ⊙ ch It is a multiplication operation of the channel dimension, and the channel branch attention A ch (X in )=F SG [W z (σ1(W v (X in ))×F SM (σ2(W q (X in ))))], where W q ,W v , and W z is a 1×1 convolution operation, σ1 and σ2 are data shape modification operations, F SM (·) is the Softmax operation, "×" is the matrix multiplication operation, F SG (·) is the Sigmoid operation; in the spatial branch, the spatial branch output Spatial attention branch Where W q and W v is a 1×1 convolution operation, σ l ,σ2, and σ3 are data shape modification operations,F GP is a global pooling operation, sp It is an operation of performing element-by-element multiplication on the data in the spatial dimension, thereby obtaining an improved feature extraction module PFC2f module; finally, the module and the model parameters received from the detection head network acceleration module (2-2) are transmitted to the face mask detection model training module based on YOLOv8 (4-1); YOLOv8-based human pose estimation model building module (3) improves and builds a YOLOv8-based human pose estimation model, including a channel feature fusion enhancement module (3-1) and a loss function improvement module (3-2); Channel feature fusion enhancement module (3-1) uses a custom feature fusion module to improve all Concat modules in the neck network of the original YOLOv8 human posture estimation network for the original YOLOv8 human posture estimation model. The custom feature fusion module is: when the input feature map is F1 and F2, first initialize two learnable weights W1 and W2, then quickly normalize the two weights and calculate ∈ is a small constant, set to 0.0001, and the output of the custom feature fusion module is Concat((W n1 ×F1),(W n2 ×F2)), where Concat is a channel-dimensional splicing operation, thereby obtaining an improved channel feature fusion module FConcat module. Finally, the module and the model parameters of the original YOLOv8 human pose estimation model, such as the convolution module, splicing module, upsampling module, and detection head module, are transferred to the loss function improvement module (3-2); The loss function improvement module (3-2) uses a custom positioning loss function to improve the positioning loss function of the model. The custom positioning loss function is calculated as: L = L IoU +L dis +L asp , where the intersection loss L IoU =1-IOU; distance loss and edge length loss IOU is the intersection-over-union ratio between the predicted box and the true box, w and h represent the width and height of the predicted bounding box respectively. gt and h gt Represents the width and height of the ground-truth bounding box, w c and h c is the width and length of the minimum rectangle covering the prediction box and the label box, ρ is the Euclidean distance of the center point variable, and the improved loss function is obtained; finally, the loss function and the model parameters received from the channel feature fusion enhancement module (3-1) are transmitted to the human posture estimation model training module based on YOLOv8 (4-2).

2. A face mask detection method based on YOLOv8 anti-occlusion counterfeit attack according to claim 1, characterized in that: The face mask dataset construction module (1) first performs resolution screening on the open source face mask dataset, and retains the image if the pixel of the image with a length of w and a height of h is: w×h>=160000px; then, manually annotates these images using labelme software, and marks the target without wearing a mask in the image as "no mask", the target wearing a mask incorrectly as "mistake mask", and the target wearing a mask correctly as "mask"; then, divides the image set into two parts, with three quarters as a training set and the remaining quarter as a validation set, and finally transmits the dataset to the face mask detection model training module (4-1) based on YOLOv8.

3. A face mask detection method based on YOLOv8 anti-occlusion counterfeit attack according to claim 1, characterized in that: The model training module (4) is responsible for training the face mask and human body posture estimation models, including a face mask detection model training module (4-1) based on YOLOv8 and a human body posture estimation model training module (4-2) based on YOLOv8; The face mask detection model training module (4-1) based on YOLOv8 is based on the training set data in the face mask data set construction module (1), and the target detection model obtained from the face mask detection model construction module (2) of YOLOv8 is trained with data to obtain a face mask detection model. In a distributed system with n available GPUs, the system sets the number of samples processed at one time to 16×n, the initial learning rate to 0.001, the size of the input image to 640×640, and the total number of training rounds to 300. After the training is completed, the trained face mask detection model parameters are transmitted to the face mask detection module (5-1); The YOLOv8-based human pose estimation model training module (4-2) is based on the open source COCO-Pose data set, and performs data training on the human pose estimation model obtained from the YOLOv8-based human pose estimation model building module (3) to obtain a human pose estimation model; in a distributed system with n available GPUs, the system sets the number of samples processed at one time to 16×n, the initial learning rate to 0.001, the size of the input image to 640×640, and the total number of training rounds to 500; After the training is completed, the trained human posture estimation model parameters are transmitted to the occlusion and counterfeit attack detection module (5-2).

4. A face mask detection method based on YOLOv8 anti-occlusion counterfeit attack according to claim 1, characterized in that: The YOLOv8-based anti-occlusion and counterfeit attack face mask detection module (5) is responsible for detecting the image to be detected obtained from the general image acquisition module and returning the detection result to the image acquisition module, including the face mask detection module (5-1) and the occlusion and counterfeit attack detection module (5-2); The face mask detection module (5-1) first receives the face mask detection model transmitted by the face mask detection model training module (4-1) based on YOLOv8, then sets the detection confidence threshold to 0.75, sets the face mask detection results to: 0-not wearing a mask, 1-not wearing a mask properly, 2-wearing a mask correctly, 3-no obvious face target detected, and at the same time obtains the image to be detected from the general image acquisition module, adjusts the image to a resolution of 640×640 by scaling and grayscale filling, and then passes the image to the face mask detection model for prediction. The model prediction results include the bounding box coordinates of the face of the person being detected, the target classification and confidence Conf mask ∈(0,1), where the bounding box coordinates include the upper left corner coordinates and the lower right corner coordinates When Conf mask >0.75 and When the test result is 0, when Conf mask >0.75 and When the test result is 1, when Conf mask >0.75 and When , the detection result 2 is obtained, and the detection result 3 is obtained in other cases. Finally, the image to be detected and the detection result are passed to the occlusion and forgery attack detection module (5-2); The anti-occlusion counterfeit attack detection module (5-2) first receives the human posture estimation model transmitted by the human posture estimation model training module (4-2) based on YOLOv8 and the detection results of the face mask detection module (5-1), then sets the confidence of the key points of the hand of the person being detected to 0.75, and sets the anti-occlusion counterfeit attack detection results to: a-occlusion counterfeit attack exists, b-occlusion counterfeit attack does not exist, and then passes the image to be detected to the human posture estimation model for prediction. The prediction result of the model is the position information and confidence information of the key points of the hands of the person to be detected, wherein the position information of the key point of the left hand is The confidence level is The position information of the right hand key point is The confidence level is when and or and When the detection result is a, the detection result is obtained; otherwise, the detection result is obtained b. Finally, the detection result (a or b) and the detection result (0 or 1 or 2 or 3) of the face mask detection module (5-1) are returned to the image acquisition module to display the output of the final result.

5. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the face mask detection method based on YOLOv8 anti-occlusion and counterfeiting attacks as described in any one of claims 1 to 4 above is implemented.

6. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the computer instruction is executed by the processor, the face mask detection method based on YOLOv8 anti-occlusion counterfeiting attack according to any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Human face mask detection system and method based on Retinaface algorithm

    CN112686214A

  • A mask recognition method based on depth camera

    CN113435361B

  • Face mask detection system and method based on improved FCOS

    CN113887455A

  • Improved YOLOv5-based face mask recognition method and system

    CN116311417A

  • HI-DisCLBP-based convolutional neural network face mask recognition method

    CN117037239A