Face mask detection method for resisting shielding counterfeit attack based on YOLOv8

By improving the convolutional structure, detection head network and feature extraction module of the YOLOv8 model, and introducing channel feature fusion and loss function improvement module, the problems of large calculation volume, poor real-time performance and inability to defend against occlusion of fake attacks in the prior art are solved, and high-precision, high-real-time and high-rootty facial mask detection is achieved.

CN119600670AActive Publication Date: 2025-03-11SOUTHEAST UNIV +1

Patent Information

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

AI Technical Summary

Technical Problem

While pursuing high precision, the existing facial mask detection technology has large calculation volume and poor real-time performance, and is unable to effectively defend against counterfeit attacks, which is poorly robust.

Method used

Based on the YOLOv8 artificial intelligence vision algorithm, a face mask detection method that is resistant to occlusion and forgery is designed. By improving the convolutional structure, detection head network and feature extraction module of the YOLOv8 model, the detection accuracy and real-time performance are improved, and the channel feature fusion and loss function improvement module are introduced into the model to enhance the robustness of the model.

Benefits of technology

It realizes high-precision and real-time facial mask detection, while effectively defending against counterfeit attacks, improving the robustness of the detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119600670A_ABST
    Figure CN119600670A_ABST
Patent Text Reader

Abstract

The invention relates to a face mask detection method based on YOLOv8 shielding and counterfeit attack resistance, and belongs to the field of artificial intelligence security application. According to the method, the precision and generalization of a detection model are improved by constructing a face mask detection picture data set with high sample capacity and high resolution; an original YOLOv8 target detection model is improved by adopting a self-defined convolution module, the convolution efficiency of the detection model is improved, the feature extraction capability of the model is enhanced, and the calculation complexity is reduced; an original YOLOv8 human body posture estimation model is improved by adopting a user-defined module and a loss function, and the feature fusion capability and the target positioning capability of the model are enhanced; by autonomously designing a face mask detection method based on YOLOv8 shielding and counterfeit attack resistance, high-precision, high-robustness and high-real-time face mask detection on a to-be-detected picture is realized. According to the method, real-time face mask detection can be realized, shielding counterfeit attacks in a real detection scene can be defended, and meanwhile, a self-defined data set and a model network structure are designed, so that the method has good detection precision and detection real-time 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] In the current context of increasing attention to public health and safety, face mask detection technology based on deep learning has become an important research topic. This technology can not only help monitor and remind the public to wear masks correctly, but also reduce the harm of harmful particles to the human body in specific production environments such as factories, and improve the overall hygiene level and life safety.

[0003] Traditional face mask detection methods rely on manual supervision, but this method is time-consuming and poses safety risks. Therefore, an automated face mask wearing monitoring system has become an urgent need. With the development of deep learning technology, especially with the help of GPU computing devices and big data, face mask detection technology based on deep learning has gradually matured. These technologies can automatically process large amounts of image data with high precision through end-to-end training of deep learning visual models, achieving efficient and accurate mask detection.

[0004] Thanks to the rapid development of deep learning, many detection models based on deep learning have emerged in academia. Most classic object detection algorithms rely on convolutional networks for feature extraction. Some excellent basic networks such as VGGNet, GoogLeNet and ResNet have shown extraordinary results in feature extraction. At present, the mainstream face mask detection technology is mainly divided into two categories: two-stage detection (Two-stage) algorithm based on candidate regions and one-stage (one-stage) detection algorithm based on regression. Although the two-stage detection algorithm is accurate, it is slow and not suitable for detection scenarios with high real-time requirements. In contrast, one-stage detection algorithms such as the YOLO series of algorithms are widely used due to their fast and accurate characteristics. The YOLO series of algorithms completes object classification and position prediction through one feature extraction, which is particularly suitable for scenarios with high real-time requirements. However, while pursuing high precision, the existing mask detection technology does not have a good balance between the model calculation amount, resulting in poor detection speed and real-time performance. At the same time, the existing face mask detection technology often gives wrong prediction results when the person being detected actively covers his face, and cannot effectively defend against occlusion counterfeiting attacks, so the robustness is poor.

[0005] Patent application CN202410220928.45 A mask detection method, system, device, medium and program product, the method constructs and trains an initial fabric segmentation network, performs image segmentation on the face image to be detected, and judges the mask wearing condition of the target face by the segmentation result. The method judges the proportion of the mouth and nose on the target face by the pixel ratio in the segmentation result, and then judges whether the target face is wearing a mask correctly. However, this detection method uses a more classic segmentation model, the input size of the picture is small, and it is difficult to achieve high-resolution picture segmentation. Therefore, the fine-grainedness of the detection is poor, and it is impossible to correctly judge the situation that the person to be detected does not wear a mask in a standardized manner. In addition, the method does not take into account the occlusion counterfeit attack that is easy to occur in real detection scenarios, so the robustness is poor.

[0006] Patent application CN202311000170.5 is a mask recognition method based on deep learning. In this method, a mask target detection model is constructed based on YOLOv5. The SPPCSPCF structure is used in the backbone network. The feature map fed into the SPPCSPCF structure is divided into two parts, one of which is subjected to conventional convolution processing and the other is subjected to SPP processing. Finally, the two parts are combined by Concat operation. In the SPPCSPCF structure, three MaxPool2d are set as a serial structure and the number of channels of the feature map input pyramid pooling structure is reduced, thereby improving the running speed. This method uses YOLOv5s as the basis for constructing a target detection model, resulting in a large amount of calculation for the model. It is difficult to ensure good real-time performance when the computing equipment is limited. At the same time, this method does not take into account the occlusion counterfeit attacks that are prone to occur in real detection scenarios, and has poor robustness.

[0007] Patent application CN202211664167.9 is a method and system for face mask recognition based on improved YOLOv5. The method uses network pruning to compress the YOLOv5 algorithm model, optimizes the network space to reduce parameter calculation to avoid overfitting, and adds a CBAM convolution attention module after the CSP module to enhance the ability to express dense small-scale target features; secondly, the hidden layer pruning method and 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 with a 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 do not wear masks properly 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 convolutional neural network face mask recognition method based on HI-DisCLBP. This method is based on the convolutional neural network of HI-DisCLBP, locates the face through the three-point alignment method, converts the located face image from RGB color space to HI color space, and then integrates the DisCLBP feature extraction to form a HI-DisCLBP multi-feature fusion image; trains a data set based on the SqueezeNet convolutional neural network deep learning model until the model training results achieve the expected effect, tests the face image processed by HI-DisCLBP, crops, enhances and removes noise from the image, and integrates the SqueezeNet convolutional neural network to extract high-level features of the image for recognition, and outputs the face mask wearing status. As an early deep learning classification network, the SqueezeNet convolutional neural network deep learning model can only accept 32×32×3 lower resolution images, which is inconsistent with the current mainstream image acquisition devices. Moreover, the model can only output the classification results of a single image, which makes it difficult to cope with the scenario of detecting multiple targets in the image at the same time. In addition, this method cannot defend against occlusion and counterfeit attacks that are prone to occur in real detection scenarios. When the person being detected intentionally covers his face, the model often gives wrong predictions.

[0009] Patent application CN202310732956.X is a mask wearing recognition method based on an improved SSD algorithm. The method is based on the SSD convolutional neural network. By adding Gaussian noise to the data set and increasing the brightness of some low-brightness images, and expanding the sample, a training data set with better generalization is obtained; the method replaces the network backbone network VGG-16 of the original SSD model with the MobieNet-V model, and uses deep separable convolution to build a lightweight deep neural network, and introduces the ECAnet module based on the ECA attention mechanism into the model. The one-dimensional convolutional network module is used to complete the cross-channel information interaction. The method introduces the Focal Loss function during model training to reduce the impact of the loss of easily separable samples on the total loss. As a relatively classic two-stage CNN target detection network, SSD has low detection accuracy, and because there are a large number of conventional convolution kernel residual modules inside the model, the model has a high computational complexity and poor real-time performance; at the same time, the method cannot defend against occlusion counterfeit attacks that are easy to appear in real detection scenarios, and has poor robustness.

[0010] Patent application CN202110740788.X A mask recognition method based on a depth camera This method uses a depth camera to obtain a depth map containing a face, then crops the obtained depth image into a depth image containing only the lower half of the face and extracts the contour of the lower half of the face, and identifies whether the face is wearing a mask and the type of mask worn by the face by calculating spatial features and frequency features. This method requires a relatively expensive depth camera to collect images of the person being tested, and has strict shooting angles, and may not be able to correctly identify the side face image of the tester. At the same time, this method cannot defend against occlusion counterfeiting attacks that are prone to occur in real detection scenarios, and has poor robustness.

[0011] Patent application CN202111181138.2 is a face mask detection system and method based on improved FCOS. This method is based on the target detection method of FCOS (Fully Convolutional One-stage Object Detector), adds a PAN module to the neck of the model's network, and uses a feature pyramid network and a PAN module for feature fusion, fuses the image feature map from the bottom up, and enhances the underlying feature information such as texture and edge to the feature map of each layer, improving the positioning ability of the network. Finally, a full convolution 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, this method ignores the computational complexity of the model while enhancing the detection accuracy 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 of the model. In addition, the model does not consider the occlusion counterfeit attack that is prone to occur in the detection scene, so the robustness is poor.

[0012] Patent application CN202110105379.2 is a face mask detection system and method based on the Retinaface algorithm. The method uses the Retinaface algorithm model to extract the face image of the person being detected and uses an additional mask detection model to perform face mask detection. The feature extraction network of the Retinaface model adopts a lightweight MobileNet V1 structure, the feature fusion layer adopts 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 face image of the person being detected through an improved Retinaface model and then continues with face 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 the occlusion counterfeiting attacks that are prone to occur in the detection scene, so it has poor robustness.

[0013] The journal "Internet of Things Technology" issue 7, 2024, published a paper titled "Face Detection Algorithm Based on Multi-Scale Feature Fusion". The algorithm uses the lightweight MobileNet network framework, introduces the feature pyramid fusion module and the SSH (SingleStage Headless) module, and uses two loss functions, face classification and face detection regression box, to improve the model's prediction positioning ability and occlusion detection ability. The network architecture can ensure high-precision extraction of the main features while requiring only a small number of parameters, 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 quite different from the resolution of current image acquisition devices, and the experimental part of the paper only gives the performance of the model in classifying people, and does not give data on prediction box regression. The compared models are relatively classic models, and no experimental data for cutting-edge models are given, which cannot reflect the advantages or gaps of the detection method proposed in the paper compared with the current advanced methods.

[0014] The 9th issue of the journal "Computer Engineering and Design" in 2023 is titled "Face Mask Wearing Detection Based on Improved YOLOv5". This paper is based on the face mask detection method of improved YOLOv5; introduces improved DenseNet (densely connected convolutional network) to improve network feature utilization and network anti-interference ability; increases detection head parameters, cross-level connections for features of different scales, enhances multi-scale information exchange, and improves the network's detection performance for small-scale targets; replaces the original loss function GIoU with CIoU to solve the problem of slow model convergence. However, this paper does not consider the lightweight of the model. Due to the introduction of DenseNet and additional detection heads, the computational complexity of the model is greatly increased, and the detection speed and real-time performance are significantly reduced. This paper does not consider the occlusion counterfeit attacks that are prone to occur in real detection scenarios, so the robustness is poor.

[0015] The journal "Electronic Design Engineering" published an article titled "Research on Mask Wearing Detection Based on Improved YOLOv5 Algorithm" in Issue 22 of 2022. This article 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, this article adds an additional set of Anchor values ​​during the model training phase. However, this article did not carry out any work related to the lightweighting of the model. Since the author chose to make improvements on the larger YOLOv5s model and introduced an additional detection head network, the detection speed and real-time performance of the model were significantly reduced. In addition, the method proposed in this article cannot defend against occlusion counterfeiting attacks in real detection scenarios.

[0016] The journal Journal of Southwest Jiaotong University, Issue 5, 2021, published a paper 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 incorrect prediction results; and the model cannot defend against occlusion counterfeit attacks that are prone to occur in real detection scenarios, and its robustness is poor. Summary of the invention

[0017] In view of 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 blocks the face, and has poor robustness, the present invention designs a face mask recognition method based on YOLOv8 anti-occlusion and counterfeiting. The method is based on the YOLOv8 artificial intelligence vision algorithm, and by designing an anti-occlusion and counterfeiting face mask detection method, it 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 body 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, which is not within the protection scope and is characterized by:

[0020] The face mask data set construction module is based on a public face mask detection data set. First, the low-resolution image data is filtered by calculating the image resolution, and then the image data is annotated using annotation software. Finally, the data set is divided into a training set and a validation set according to the ratio, and finally the data set is transmitted 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 target detection model network, and then uses a custom decoupling head structure to improve the detection head of the model; finally, a custom convolution structure based on the attention mechanism 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 custom feature fusion structure to improve the neck network of the original YOLOv8 human posture estimation model network, and finally uses a custom 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 data set construction module, and uses 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 data set, and uses the human posture estimation model in the human posture estimation model construction module based on YOLOv8 to perform data training to obtain a human posture estimation model;

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

[0025] As a further improvement of the present invention, the face mask data set construction module first performs resolution screening on the open source face mask data set (SF-MASK, Mask Wearing). When the pixel of the picture with a length of w and a height of h is: w×h>=160000px, the picture is retained; then, the labelme software is used to manually annotate these pictures, and the targets in the pictures that are not wearing masks are marked as "no mask", the targets that are not wearing masks in a standardized manner are marked as "mistake mask", and the targets that 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 verification set, and finally the data set is transmitted 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 transmitting 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 channel segmentation. 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 Afterwards, The continuous channels of the convolution operation are convolved, the SILU activation function and the subsequent two 1×1 convolutions are obtained. FN2 , put F P1 ,F P2 ,F FN1 ,F FN2 The four features are concatenated in channel dimension to obtain Finally, use 1×1 convolution to get the output Thus, an 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.

[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 for 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 position information of the bounding box of each pixel in the feature map, thereby obtaining an improved detection head network acceleration module FHead; finally, the 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. 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, and 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 (4-1) based on YOLOv8;

[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 are responsible for improving and building the human posture estimation model based on YOLOv8, and transmitting the model to the model training module;

[0031] The channel feature fusion enhancement module 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. Finally, the output of the custom feature fusion module is Concat((W n1 ×F1), (W n2 ×F2)), where Concat is a concatenation operation in the channel dimension, thereby obtaining an improved channel feature fusion module FConcat module. Finally, the model parameters of this module and the convolution module, concatenation module, upsampling module, and detection head module of the original YOLOv8 human posture estimation model are transmitted 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 Represent the width and height of the real 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 counterfeit 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 consisting of n available GPUs, the system sets the number of samples processed at one time to be 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 in each round of training is evaluated for model performance using a validation set, and the model is transmitted to the face mask detection module after the training is completed.

[0035] The YOLOv8-based human posture estimation model training module is based on the open source COCO-Pose data set, and the human posture estimation model obtained from the YOLOv8 human posture estimation model building module is trained with data to obtain a human posture 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 size of the input image is 640×640, and the total number of training rounds is 500; after the training, the model is transmitted to the occlusion counterfeit attack detection module.

[0036] As a further improvement of the present invention, the face mask detection module based on YOLOv8 anti-occlusion counterfeit attack includes a face mask detection module and an occlusion 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 result to: 0-no mask, 1-not wearing the mask properly, 2-wearing the 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 result includes 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 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 counterfeit 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-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 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 comprises a memory, a processor and a computer program stored in the memory and executable on the processor. When the processor executes the program, the method for detecting human face masks based on YOLOv8 against 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 counterfeit attack face mask detection method.

[0041] Beneficial Effects

[0042] Compared with the prior art, the invention has the following beneficial effects: the invention provides a human face mask detection method based on YOLOv8 anti-occlusion and counterfeiting; the invention constructs a human face mask detection data set with high sample capacity and fine-grained annotation, and enhances 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 an original YOLOv8 target detection model network, and the accuracy of the human face mask detection model is effectively improved while the calculation complexity of the model is significantly reduced, thereby ensuring the 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 an original YOLOv8 human body posture estimation model network, and the detection accuracy of the human body posture estimation model is effectively improved; the method is based on the YOLOv8 deep learning visual algorithm, and by sequentially performing human face mask detection and occlusion and counterfeiting detection algorithms on a to-be-detected picture, the occlusion and counterfeiting attacks that may occur in a real detection scene are effectively defended, and high-precision and high-robust human face mask detection is achieved. BRIEF DESCRIPTION OF THE DRAWINGS

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

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

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

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

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

[0048] In order to deepen the understanding of the present invention, the present 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, wherein the detection system used includes a face mask data set construction module 1, a face mask detection model construction module based on YOLOv8 2, a human body 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 an open source mask detection image data set (SF-MASK, Mask Wearing), then manually labels the image data based on 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 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 custom residual convolution structure, then improves the detection head network of the original YOLOv8 target detection model network through a custom decoupling head structure, and finally improves the detection head network of the original YOLOv8 target detection model network through a self-defined residual convolution structure. The defined convolution structure based on the attention mechanism is used to improve the backbone network of the YOLOv8 target detection model network to obtain the face mask detection model to be trained, and the model and parameters are transmitted to the face mask detection model training module 4; the YOLOv8-based human posture estimation model building module 3, for the initial YOLOv8 human posture estimation model, first 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 to obtain 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 the human body posture estimation model 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 to perform data training, and the trained face mask detection model and the human body posture estimation model are transmitted to the face mask detection model training module 4; Transmitted to the YOLOv8-based anti-occlusion counterfeit attack face mask detection module 5; 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 picture to be detected is obtained from the general image acquisition module, and then the picture 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 model of human body posture estimation. 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 an open source face mask dataset (SF-MASK, Mask Wearing). When the pixel of a picture with a length of w and a height of h is: w×h>=160000px, the picture is retained; then, the pictures are manually labeled using labelme software, and the targets in the pictures that are not wearing masks are marked as "no mask", the targets that are not wearing masks properly are marked as "mistake mask", and the targets that are wearing masks correctly are marked as "mask"; then, the picture set is divided into two parts, three quarters of which are used as a training set and the remaining quarter is used as a validation set, and finally the data set is transmitted to the face mask detection model training module 4-1 based on YOLOv8. The YOLOv8-based face mask detection model building module 2 improves and builds a YOLOv8-based face mask detection model, 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, and 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 segmentation. 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 Afterwards, The continuous channels of the convolution operation are convolved, the SILU activation function and the subsequent two 1×1 convolutions are obtained. FN2 , put F P1 ,F P2 ,F FN1 ,F FN2 The four features are concatenated in channel dimension to obtain Finally, use 1×1 convolution to get the output Thus, an improved convolution module FC2f is obtained, and finally the module and the model parameters such as 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 for 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 position information of the bounding box of each pixel in the feature map, thereby obtaining an improved detection head network acceleration module FHead; finally, the 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 outputs 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, and 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 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 YOLOv8-based face mask detection model training module 4-1. The YOLOv8-based human posture estimation model building module 3 improves and constructs a YOLOv8-based human posture estimation model, including a channel feature fusion enhancement module 3-1 and a 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 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. Finally, the output of the custom feature fusion module is Concat((W n1 ×F1), (W n2 ×F2)), where Concat is the concatenation operation of the channel dimension, thereby obtaining an improved channel feature fusion module FConcat module. Finally, the model parameters of this module and the convolution module, concatenation module, upsampling module, and detection head module of the original YOLOv8 human posture estimation model are transmitted 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 Represent the width and height of the real bounding box, w c and h cis the width and length of the smallest 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 4-2 based on YOLOv8. The model training module 4 is responsible for training the face mask and human posture estimation model, including 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;

[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 building 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 posture estimation model training module 4-2 is based on the open source COCO-Pose data set, and performs data training on the human posture estimation model obtained from the YOLOv8-based human posture estimation model building module 3 to obtain a human posture 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 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 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, sets the face mask detection result to: 0-not wearing a mask, 1-not wearing a mask properly, 2-wearing a mask correctly, 3-no obvious face target is 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 result includes 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 hands 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 a is obtained, otherwise, the detection result b is obtained. 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 result.

[0060] The details are as follows:

[0061] like Figure 1This is a system diagram of the present invention, which is applicable to most face mask detection scenarios. The cloud-based distributed training server cluster of the present invention is used to train face mask detection models and human body posture estimation models, and send 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, which is responsible for collecting photos of the person to be detected for face mask detection, and sending the collected photos to the cloud-based distributed detection server cluster through 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 server currently in an available state performs anti-occlusion and counterfeiting face mask detection on the collected photos, and returns the detection results to the detection end device.

[0062] like Figure 2The overall block diagram of the present invention is as follows. The face mask detection method based on YOLOv8 anti-occlusion counterfeiting proposed by the present invention includes: a face mask data set construction module 1, a face 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 face mask detection module 5 based on YOLOv8 anti-occlusion counterfeiting attack. Among them, the face mask data set construction module 1 is responsible for constructing a face mask detection data set for training a face mask detection model. The face mask detection model building module 2 based on YOLOv8 is responsible for the preliminary definition and construction of the face mask detection model network based on YOLOv8, 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 posture estimation model building module 3 is responsible for building a human posture estimation model network based on YOLOv8, including 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 posture 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 the training of the model, which includes 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 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, 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 data set, 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 counterfeit attack detection module 5-2.The face mask detection module 5 based on YOLOv8 anti-occlusion and counterfeit attack is responsible for face mask detection against occlusion and counterfeit attack on the detected image, and includes two modules, namely, face mask detection module 5-1 and 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 detected image to determine whether the detected person 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 detected image to determine whether the detected person 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 The present invention is a flowchart of the face mask data set construction module. The face mask data set construction module first collects and organizes public image data sets related to face mask detection (SF-MASK, Mask Wearing); then the image data is screened by calculating the image resolution, and 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 the images are manually labeled using labelme software, and the target in the image that wears a mask in a standardized manner is labeled as "mask", the target that does not wear a mask in a standardized manner is labeled as "mistake mask", and the target that does not wear a mask is labeled as "no mask"; finally, the image set is divided into two parts, three quarters as a training set, and the remaining quarter as a validation set.

[0064] like Figure 4 This is a flow chart of the model training module of the present invention. The model training module first preprocesses the training data and adjusts the image to a resolution of 640×640 by scaling and grayscale filling; after the training starts, the training loss value of the current iteration round is first calculated based on the loss function; then back propagation and model parameter update are performed; after the parameters are updated, the performance of the model is evaluated using the validation set; after the iteration is completed, the model with the highest accuracy is selected.

[0065] like Figure 5 The figure is a flowchart 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 prediction results of the model 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 detection result 2 (correctly wearing a mask) is obtained, and the detection result 3 (no obvious face target is detected) is obtained in other cases; then the image to be detected 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 detected, 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 (an occlusion counterfeit attack exists), otherwise, the anti-occlusion counterfeit attack detection result b is obtained (there is no occlusion counterfeit attack); 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 protection scope of the present invention, and equivalent changes or substitutions made on the basis of the above technical solutions all fall within the protection scope 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 data set 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 based on an open source mask detection image dataset (SF-MASK, Mask Wearing), then manually labels the images based on 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 convolution structure based on an attention mechanism, thereby obtaining a face mask detection model to be trained, and transmitting 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 customizing the 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 customizing the positioning loss function to obtain the 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 body posture estimation model network in the human body posture estimation model construction module (3) based on YOLOv8 to perform data training, and transmits the trained face mask detection model and human body posture estimation model to the face mask detection module (5) based on YOLOv8 for anti-occlusion counterfeiting attack; The YOLOv8-based anti-occlusion counterfeit attack face mask detection module (5) first receives a face mask detection model and a human body posture estimation model from a 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.

2. According to claim 1, a YOLOv8-based anti-occlusion counterfeit attack face mask detection method is characterized in that: The face mask dataset construction module (1) first performs resolution screening on an open source face mask dataset (SF-MASK, MaskWearing). When the pixel of a picture with a length of w and a height of h is: w×h>=160000px, the picture is retained; then, the pictures are manually labeled using labelme software, and the targets in the pictures that are not wearing masks are marked as "no mask", the targets that are not wearing masks properly are marked as "mistake mask", and the targets that are wearing masks correctly are marked as "mask"; then, the picture set is divided into two parts, three quarters of which are used as a training set and the remaining quarter is used as a validation set, and finally the data set is transmitted to a face mask detection model training module (4-1) based on YOLOv8.

3. According to claim 1, a YOLOv8-based anti-occlusion counterfeit attack face mask detection method is characterized in that: The YOLOv8-based face mask detection model building module (2) improves and builds a YOLOv8-based face mask detection model, 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 segmentation. 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 Afterwards, The continuous channels of the convolution operation are convolved, the SILU activation function and the subsequent two 1×1 convolutions are obtained. FN2 , put F P1 ,F P2 ,F FN1 ,F FN2 The four features are concatenated in channel dimension to obtain Finally, use 1×1 convolution to get the output Thus, an 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 for 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 position information of the bounding box of each pixel in the feature map, thereby obtaining an improved detection head network acceleration module FHead; finally, the module and the model parameters received from the convolution optimization module (2-1) are transmitted to the feature extraction enhancement module (2-3); The feature extraction enhancement module (2-3) uses a custom attention-based convolutional structure to improve the C2f module in the YOLOv8 backbone network. The custom attention-based convolutional structure includes two branches: a channel branch and a spatial branch. Given an input feature map The custom attention mechanism outputs in is the channel branch output, Output for the spatial branch; In the channel branch, the channel branch output ⊙ ch is a multiplication operation in the channel dimension, and the channel branch attention Where W q ,W v , and W z is a 1×1 convolution operation, σ1 and σ2 are data shape modification operations, and 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 YOLOv8-based face mask detection model training module (4-1).

4. A method for detecting face masks based on YOLOv8 against occlusion and counterfeit attacks according to claim 1, characterized in that: The YOLOv8-based human posture estimation model building module (3) improves and builds a YOLOv8-based human posture estimation model, including a channel feature fusion enhancement module (3-1) and a loss function improvement module (3-2); The channel feature fusion enhancement module (3-1) is aimed at the original YOLOv8 human posture estimation model, and 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 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. Finally, the output of the custom feature fusion module is Concat((W n1 ×F1), (W n2 ×F2)), where Concat is the concatenation operation of the channel dimension, thereby obtaining an improved channel feature fusion module FConcat module. Finally, the model parameters of this module and the convolution module, concatenation module, upsampling module, and detection head module of the original YOLOv8 human posture estimation model are transmitted 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 Represent the width and height of the real 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 an 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).

5. A method for detecting face masks based on YOLOv8 against occlusion and counterfeit attacks 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 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 building module (1) 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 be 16×n, the initial learning rate to be 0.001, the size of the input image to be 640×640, and the total number of training rounds to be 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 posture estimation model training module (4-2) is based on the open source COCO-Pose data set, and performs data training on the human posture estimation model obtained from the YOLOv8-based human posture estimation model building module (3) to obtain a human posture 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 counterfeit attack detection module (5-2).

6. A method for detecting face masks based on YOLOv8 against occlusion and counterfeit attacks 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 a face mask detection module (5-1) and an 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 result to: 0-no mask, 1-not wearing the mask properly, 2-wearing the 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, and the model prediction result includes the bounding box coordinates of the face of the person being detected, the target classification and confidence level 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 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), then sets the confidence of the key points of the hand of the person being detected to 0.75, sets the anti-occlusion counterfeit attack detection result 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 both hands of the person to be detected, wherein 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 a is obtained, otherwise, the detection result b is obtained. 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, and the final result is displayed and output.

7. 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 method for detecting human face masks based on YOLOv8 against occlusion and counterfeit attacks is implemented as described in any one of claims 1 to 6 above.

8. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the computer instruction is executed by the processor, the method for detecting human face masks based on YOLOv8 against occlusion and counterfeit attacks as described in any one of claims 1 to 6 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

Cited By

  • Face part positioning method and device based on multi-region perception, and medium

    CN119851330A

  • A Face Part Localization Method, Device and Medium Based on Multi-Region Perception

    CN119851330B

  • Face recognition system based on face mask detection model

    CN120853235A

  • A face recognition system based on a face mask detection model

    CN120853235B