A method and system for detecting a face mask

CN123016145APending Publication Date: 2026-10-30ZHEJIANG NORMAL UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311748230.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-19
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

[0004]有鉴于此,本发明提供了一种口罩检测方法及系统,解决了原始YOLOv5n算法在口罩检测中小目标检测精度低、边界框回归不稳定和模型训练收敛慢等问题,实现了高效的口罩检测

Benefits of technology

[0028]经由上述的技术方案可知,与现有技术相比,本发明提供了一种口罩检测方法及系统,在特征提取阶段中的卷积模块组采用Softplus激活函数用以提高模型训练的稳定性和收敛速度;在主干特征提取深层网络中添加Coordinate Attention,通过嵌入位置信息到通道注意力,使网络获取更大的物体区域信息和通道目标特征,同时避免较大的内存开销;与此同时在深层网络中添加RFB模块,借助不同的膨胀率来扩大卷积特征采样的感受野,获取到高层网络中丰富的物体语义信息;在多尺度特征融合网络PANet结构的基础上,添加FPN跨阶段多尺度特征融合设计,使得具有不同尺度空间信息和语义信息的目标特征充分融合交互,进一步提升小目标检测精度;采用DIoU作为边界框损失函数,用以解决边界框回归不稳定和目标漏检的问题;最后,采用Soft-NMS的方法通过降低重叠检测框置信度得分的方式,进一步提升检测效率。实验结果表明,改进后的口罩检测算法Mask-YOLO与基准模型YOLOv5n相比在mAP@0.5-0.95综合评价指标性能提升8.58%,

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123016145A_ABST
    Figure CN123016145A_ABST
Patent Text Reader

Abstract

The application discloses a mask detection method and system, and relates to the field of image processing. The method comprises the following steps: acquiring a mask image dataset; establishing an initial mask detection model Mask-YOLO; the model comprises a feature proposal part, a multi-scale fusion part and a classification detection head part; the feature proposal part adopts a Coodinate Attention attention mechanism and an RFB module; the multi-scale fusion part adopts an FPN network structure; the initial mask detection model Mask-YOLO is trained by using the mask image dataset, so that a mask detection model Mask-YOLO is obtained; and a to-be-detected image is input into the mask detection model Mask-YOLO, so that a detection result is obtained. The application solves the problems of low small target detection precision, unstable boundary box regression and slow model training convergence in mask detection, and realizes efficient mask detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image processing, and more specifically to a method and system for detecting face masks. Background Technology

[0002] Harmful and toxic gases, dust, and respiratory viruses in the air can enter the lungs through respiration, causing severe pneumonia symptoms and even damaging the body's immune system. According to relevant research, wearing masks correctly is an important way to effectively reduce the spread of bacteria and viruses in the air. In many crowded public places such as hospitals, supermarkets, stations, squares, and shopping malls, protective personnel are usually assigned to frequently remind people to wear masks. However, this manual approach not only consumes a lot of human resources but also causes protective personnel to become fatigued and inefficient as their working hours increase.

[0003] Mask detection in computer vision has received increasing attention, with researchers conducting extensive work to help raise public awareness of personal protection and significantly reduce the risk of airborne bacteria and viruses. However, mask detection faces numerous challenges in complex scenarios, such as blurred backgrounds, dense crowds, and object occlusion. Therefore, improving the accuracy of mask detection is a crucial area of ​​research for those skilled in the art. Summary of the Invention

[0004] In view of this, the present invention provides a mask detection method and system, which solves the problems of low accuracy of small target detection, unstable bounding box regression and slow model training convergence in the original YOLOv5n algorithm in mask detection, and achieves efficient mask detection.

[0005] To achieve the above objectives, the present invention adopts the following technical solution:

[0006] A method for testing face masks includes the following steps:

[0007] Obtain a dataset of mask images;

[0008] An initial mask detection model, Mask-YOLO, is established, comprising a feature extraction part, a multi-scale fusion part, and a classification and detection head part. The feature extraction part adopts the Coodinate Attention mechanism and the RFB module, and the multi-scale fusion part adopts the FPN network structure.

[0009] The initial mask detection model Mask-YOLO was trained using a mask image dataset to obtain the mask detection model Mask-YOLO;

[0010] The image to be detected is input into the Mask-YOLO mask detection model to obtain the detection results.

[0011] Optionally, the Coodinate Attention mechanism can be configured as follows: The input channel data is first encoded by two average pooling operations. Information is aggregated in both width and height dimensions, and then processed by channel-level concatenation and convolutional smoothing to generate a global receptive field. After batch regularization and non-linear mapping transformation, and with the same number of channels as the input data, the data is finally expanded to serve as the final weights for attention.

[0012] Optionally, the final weights can be expressed as follows:

[0013]

[0014] Among them, y c (i,j) represents the feature of the final output, x c (i,j) represents the original features. This indicates that the feature recovers the original number of channels in the height dimension after aggregation processing. This indicates a feature that restores the original number of channels in the width dimension after aggregation processing.

[0015] Optionally, the RFB module consists of consecutive 1×1 convolutional blocks, 3×3 convolutional blocks, 5×5 convolutional blocks, and short connections.

[0016] Optionally, the FPN network structure adopts a cross-stage connection method based on PANet to fuse feature information from different stages.

[0017] Optionally, the activation function for the Mask-YOLO mask detection model is as follows:

[0018] Softplus(x) = log(1 + e) x );

[0019] Where x represents the input feature, and the whole expression is the Softplus activation function expression.

[0020] Optionally, the loss function for the Mask-YOLO mask detection model is as follows:

[0021]

[0022] Where IoU represents the intersection-union ratio of the ground truth bounding box and the predicted bounding box, b,b gt These represent the center points of the predicted and ground truth boxes, respectively. ρ represents the Euclidean distance between the two center points, and c represents the diagonal distance of the smallest closure region that can simultaneously contain both the predicted and ground truth boxes. The entire expression is the DIoU loss function.

[0023] A mask detection system, comprising:

[0024] Image dataset acquisition module: used to acquire mask image datasets;

[0025] Initial Mask Detection Model Mask-YOLO Establishment Module: Used to establish the initial mask detection model Mask-YOLO, which includes a feature extraction part, a multi-scale fusion part, and a classification and detection head part. The feature extraction part adopts the Coodinate Attention mechanism and the RFB module, and the multi-scale fusion part adopts the FPN network structure.

[0026] The initial mask detection model Mask-YOLO training module is used to train the initial mask detection model Mask-YOLO using a mask image dataset, thus obtaining the mask detection model Mask-YOLO.

[0027] Detection Results Module: This module is used to input the image to be detected into the Mask-YOLO mask detection model to obtain the detection results.

[0028] As can be seen from the above technical solutions, compared with the prior art, this invention provides a mask detection method and system. In the feature extraction stage, the convolutional module group adopts the Softplus activation function to improve the stability and convergence speed of model training. Coordinate Attention is added to the deep network of the backbone feature extraction. By embedding position information into the channel attention, the network can obtain larger object region information and channel target features, while avoiding large memory overhead. At the same time, an RFB module is added to the deep network to expand the receptive field of convolutional feature sampling with different dilation rates, thereby obtaining rich object semantic information in the high-level network. On the basis of the multi-scale feature fusion network PANet structure, FPN cross-stage multi-scale feature fusion design is added to enable target features with different scale spatial information and semantic information to fully fuse and interact, further improving the detection accuracy of small targets. DIoU is used as the bounding box loss function to solve the problems of unstable bounding box regression and missed target detection. Finally, the Soft-NMS method is used to further improve the detection efficiency by reducing the confidence score of overlapping detection boxes. Experimental results show that the improved mask detection algorithm Mask-YOLO improves performance by 8.58% in the comprehensive evaluation index of mAP@0.5-0.95 compared with the benchmark model YOLOv5n. Attached Figure Description

[0029] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0030] Figure 1 This is a diagram of the YOLOv5 network structure.

[0031] Figure 2 This is a diagram of the Mask-YOLO network structure of the present invention;

[0032] Figure 3 This is the activation function diagram of the present invention;

[0033] Figure 4 A classification diagram of attention mechanisms;

[0034] Figure 5(a) is a diagram of the SE module;

[0035] Figure 5(b) shows the CA module diagram;

[0036] Figure 6(a) is a diagram of the Inception structure;

[0037] Figure 6(b) is a diagram of the RFB structure;

[0038] Figure 7(a) shows the feature map structure used by the detector head of the SSD algorithm;

[0039] Figure 7(b) shows the most basic FPN structure;

[0040] Figure 7(c) is the FPN structure diagram;

[0041] Figure 7(d) shows the FPN structure used in the Mask-YOLO algorithm of this invention;

[0042] Figure 8(a) shows the IoU loss function.

[0043] Figure 8(b) shows the DIoU loss function. Detailed Implementation

[0044] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0045] In recent years, the YOLOv5 detection algorithm has been widely used in industrial deployments, demonstrating highly efficient feature extraction and object detection performance. The YOLOv5 series of detection algorithms comprises five versions: YOLOv5n, YOLOv5s, YOLOv5m, YOLOv5l, and YOLOv5x. Their main differences lie in the depth and width of the network model, which affects the overall network size and computational complexity. YOLOv5n has the lowest computational cost and minimum complexity, making it the fastest running algorithm. YOLOv5x, on the other hand, has the largest network model with the highest number of parameters and model complexity, leading in training accuracy but running slower in practice.

[0046] The model structure of YOLOv5 is as follows: Figure 1 As shown, it comprises three main components: the network feature extraction module (BackBone), the multi-scale feature fusion part (Neck), and the object classification and localization part (Head). At the image data input end, YOLOv5 employs Mosaic Data Augmentation to expand the data volume of small datasets and improve detection accuracy. The network feature extraction part (BackBone) consists of a series of CBS, C3, and SPPF modules. CBS is a convolutional feature extraction part composed of convolution, regularization, and SiLU. C3 refers to an iterative module composed of overlapping CSPNet bottleneck network structures (CSPBottleNeck) to enhance feature extraction and network gradient propagation efficiency. CSPBottleNeck not only reduces the overall computational cost but also more efficiently acquires more complex image features. SPPF is a fast pyramid pooling operation to further aggregate feature information to extract deeper semantic information from the network. The second part of the network is the Neck module, which adopts a path aggregation feature pyramid (PANet) structure based on feature pyramid (FPN). It uses repeated top-down, bottom-up, and lateral connection multi-scale feature fusion to fully integrate the spatial structure information extracted from the shallow layers of the network with the semantic information extracted from the deeper layers. The final part is the detector head, which is mainly responsible for object classification and localization. The final output vector data includes object classification probabilities, confidence scores, and visualized bounding boxes.

[0047] YOLOv5 boasts excellent object detection performance, but it also has some significant shortcomings. Firstly, YOLOv5 is geared towards general object detection tasks like the COCO dataset, and is not well-suited for the mask detection task mentioned above, posing a considerable challenge to its performance. Secondly, the PANet network structure is inefficient in fusing feature maps at different scales across stages, and there is room for improvement in the information interaction of some spatial and semantic features. The max-pooling module in SPPF leads to significant information loss, causing a performance penalty for localization tasks. Furthermore, the complex and repetitive gradient propagation process in YOLOv5's multi-scale feature map fusion limits the overall computational efficiency of the network, making the processing of object-related feature information redundant.

[0048] Example 1

[0049] This embodiment discloses a mask testing method, including the following steps:

[0050] S1: Obtain the mask image dataset;

[0051] S2: Establish the initial mask detection model Mask-YOLO: including a feature extraction part, a multi-scale fusion part, and a classification and detection head part. The feature extraction part adopts the Coodinate Attention mechanism and the RFB module, and the multi-scale fusion part adopts the FPN network structure.

[0052] S3: Train the initial mask detection model Mask-YOLO using the mask image dataset to obtain the mask detection model Mask-YOLO;

[0053] S4: Input the image to be detected into the Mask-YOLO mask detection model to obtain the detection results.

[0054] Furthermore, in S2, the Mask-YOLO network architecture proposed in this invention is as follows: Figure 2As shown, it comprises three main parts: the feature extraction part (Backbone), the multi-scale feature fusion part (Neck), and the classification and detection head (Head). The Mask-YOLO mask detection algorithm has undergone several improvements based on YOLOv5n, maintaining a relatively small scale in terms of parameter count and model complexity. The algorithm boasts fast processing speed and high performance metrics such as accuracy and recall. Specifically, in the feature extraction part (Backbone), the original CBS (convolution + regularization + SiLU activation function) has been replaced with CBS (convolution + regularization + Softplus activation function). The smoothness of Softplus makes gradient propagation more stable during training, improving gradient propagation efficiency and avoiding the phenomenon of zero gradients to some extent. In the deep feature extraction module, the Coodinate Attention mechanism is adopted, which can simultaneously consider attention in both channel and spatial dimensions. Through adaptively learned channel weights, the model focuses on more salient object region features. The original SPPF module was replaced with the RFB module, which has multi-scale feature extraction capabilities. This module incorporates dilated convolutions based on Inception, effectively increasing the receptive field to obtain richer semantic details and aiding in small object detection. The multi-scale feature fusion (Neck) section uses a BiFPN network structure. This structure improves the transfer efficiency of features across different scales across stages by using a weighted bidirectional top-down and bottom-up feature pyramid network. Learnable weights are introduced to capture the diversity of different input features, significantly improving the utilization of multi-scale features. In the bounding box regression section, the DIoU loss function is used. This function considers the distance, overlap, and scale between the target and anchor, making the bounding box regression more stable. Finally, in the bounding box processing section, the Soft-NMS method is employed. By reducing the candidate box confidence score, it alleviates the target false negative problem faced by NMS to some extent.

[0055] Activation functions play a crucial role in convolutional networks, introducing non-linear mappings to help the network learn complex graphical patterns in data. Activation functions typically possess differentiability and monotonicity. When the values ​​of the activation function are finite, gradient-based optimization methods are more stable because the feature representation is more significantly affected by finite weights. When the output of the activation function is infinite, model training becomes more efficient. Common activation functions are often piecewise or exponentially non-linear. Figure 3 The calculation formula for the Softplus curve is as follows:

[0056] Softplus(x) = log(1 + e) x ).

[0057] In Mask-YOLO experiments, Softplus achieved the best performance. This function can be seen as a smoothed version of ReLU, effectively improving gradient propagation efficiency during feature extraction in convolutional blocks. When the Sigmoid function backpropagates, gradient vanishing easily occurs; that is, as the Sigmoid approaches saturation, the function transforms too slowly, and the derivative tends to zero, leading to information loss and hindering network training. The ReLU activation function, on the other hand, results in some neurons outputting zero, creating network sparsity and reducing parameter dependencies, thus mitigating overfitting. Softplus addresses some of the shortcomings of Sigmoid while inheriting the advantages of ReLU and LeakyReLU, improving network training efficiency while alleviating overfitting.

[0058] The human visual system can naturally and efficiently discover salient regions of objects in complex scenes. Based on this discovery, attention mechanisms have been introduced into computer vision to mimic human visual characteristics. Attention mechanisms have achieved great success in many downstream computer vision tasks, such as image classification and recognition, object detection, semantic segmentation, video understanding, 3D vision, multimodal tasks, and semi-supervised tasks. Generally, attention mechanisms are classified into the following types: channel attention mechanisms, spatial attention mechanisms, channel-spatial combined attention mechanisms, temporal attention mechanisms, spatial and temporal combined attention mechanisms, and branching attention mechanisms. Different attention mechanisms focus on different target feature information. The classification of attention mechanisms is as follows: Figure 4 As shown.

[0059] Research on lightweight networks has shown that channel attention mechanisms can significantly improve model performance; however, channel attention typically ignores selective location information in the generation space. Attention mechanisms are generally used to tell the model which content and locations to focus on and have been widely used in deep neural networks to enhance model performance. YOLOv5n is the smallest and least complex model in the YOLOv5 series, characterized by its fast execution speed, allowing for real-time industrial inspection deployment on lightweight devices. However, in lightweight networks where model feature fusion is strictly limited, the use of attention mechanisms is heavily influenced by hardware limitations, primarily because the overhead of most attention mechanisms is unaffordable for lightweight networks. Considering the limited computational power of lightweight networks, the mainstream attention mechanism remains the SE attention mechanism proposed by SENet. As shown in Figure 5(a), the SE module establishes relationships between channels by introducing Squeeze and Excitation operations. In the Squeeze stage, it compresses the output feature map of the convolutional layer into a feature vector through global average pooling. Then, in the Excitation stage, it learns to generate channel weight vectors by using fully connected layers and non-linear activation functions. This weight vector is then applied to each channel of the original feature map to weight the features of different channels. However, the SE module only considers the encoding of information between channels and ignores the importance of positional information, which is still crucial for many visual tasks that capture target structures.

[0060] Compared to previous attention mechanisms on lightweight networks, Coordinate Attention (CA) has the following advantages: CA can capture not only cross-channel information but also orientation and position information, which can effectively help the model establish more accurate localization and identify targets of interest; secondly, CA has a very small number of parameters that can be flexibly embedded into the network feature extraction structure to enhance the features of information representation; finally, CA has very strong scalability and can be easily applied to downstream computer vision tasks, such as image classification and instance segmentation. The CA module encodes channel relationships and long-distance dependencies through precise positional information, which is similar to the SE module in many ways. Specifically, the CA attention mechanism consists of two main steps: coordinate information embedding and coordinate attention generation, and its specific structure diagram is shown in Figure 5(b). For the input channel (C) × height (H) × width (W) data, the channels are first encoded through two average pooling operations. The output expression of the Cth channel with height H and width W is shown below:

[0061]

[0062]

[0063] Aggregating information along both width and height dimensions helps the network more accurately locate targets of interest. Then, channel-level concatenation and convolutional smoothing produce a more precise information representation with a global receptive field, as shown in the following equation.

[0064] f=δ(F1([z h ,z w ]))

[0065] Then, through batch regularization and nonlinear mapping transformation, and with the same number of channels as the input data, as shown in the following equation,

[0066] g h =σ(F h (f h ))

[0067] g w =σ(F w (f w ))

[0068] Finally, weight expansion is performed to obtain the final weights for attention, and the final output is as follows:

[0069]

[0070] Among them, y c (i,j) represents the feature of the final output, x c (i,j) represents the original features. This indicates that the feature recovers the original number of channels in the height dimension after aggregation processing. This indicates a feature that restores the original number of channels in the width dimension after aggregation processing.

[0071] Figure 6(b) shows the structure of the RFB module. This structure borrows from the multi-branch, multi-scale design of Inception in Figure 6(a), and explores diverse information in the feature extraction network by setting receptive fields of different sizes. The RFB module consists of consecutive 1×1 convolutional blocks, 3×3 convolutional blocks, 5×5 convolutional blocks, and short connections. The core design uses the dilation rate parameter in the convolutional module to control and adjust the receptive field of the convolutional blocks, and uses large-scale 5×5 convolutional kernels to enhance the diversity of kernel sampling. The 1×1 convolutional blocks perform channel correction and smoothing on the input and output features. Finally, the short connection idea of ​​residual design is used to enhance gradient transfer efficiency, prevent overfitting in the network during training, and greatly improve the generalization level of the module.

[0072] Figure 7(a) shows the feature map structure used by the SSD algorithm detector head. Although this type of algorithm uses multi-scale feature maps, it does not fully utilize feature maps of different scales, resulting in insufficient utilization of structural feature information and thus relatively low efficiency in small object detection. Figure 7(b) shows the most basic FPN structure, which adopts a dual-path structure of bottom-up, top-down, and lateral connections to fuse shallow and deep feature maps at the same scale. The FPN network structure greatly improves the accuracy of small object detection and has been widely used in other vision tasks, becoming an important network design principle for multi-scale feature fusion. Figure 7(c) shows the PANet structure designed and proposed by the instance segmentation network. It is an important FPN structure for feature fusion in YOLOv4 and YOLOv5. The principle of PANet is to add a bottom-up path layer on the basis of the FPN design, that is, to perform deeper interactive learning on the fused information. Compared with the original FPN structure, the computational cost increases significantly, but the performance improvement is also very considerable. Figure 7(d) shows the FPN structure used in the Mask-YOLO algorithm. Based on PANet, it adopts a cross-stage connection method to directly fuse feature information from different stages. This greatly increases the efficiency and diversity of information transmission, eliminating the need for information transmission through complex paths and avoiding the loss of original discriminative information. This allows the network to learn the importance of different input features, further simplifying the information transmission process and fusing more features without increasing computational costs, enabling the network to learn more classification and localization feature knowledge.

[0073] The loss function for object detection generally consists of two parts: classification loss and bounding box regression loss. The regression loss function is usually replaced by Intersection over Union (IoU), which refers to a standard for measuring the accuracy of detecting corresponding objects in specific data. IoU is calculated by processing the overlapping portion of two regions, obtaining the result from the combined data of the two regions, and comparing it with this IoU result using a set threshold. The expression is shown in Figure 8(a).

[0074]

[0075] For the traditional IoU loss function, the IoU value is 0 when the predicted box and the target box do not intersect. In this case, the loss function is not differentiable and cannot reflect the distance between the two boxes, nor can it optimize for cases where the two boxes do not intersect. The GIoU loss function alleviates this phenomenon to some extent by adding the minimum bounding matrix of the two boxes, but it still faces the problem of the predicted box being inside the target box and smaller than the target box. In this case, the difference between the predicted box and the target box is the same, making effective prediction impossible. The DIoU loss function introduces the distance between the diagonals of the center points of the two boxes into the GIoU loss function. When the target box wraps around the predicted box, it directly measures the Euclidean distance between the diagonals of the center points of the two boxes. In this case, the DIoU loss function is more effective and converges faster, as shown in Figure 8(b) and the following equation.

[0076]

[0077] Where IoU represents the intersection-union ratio of the ground truth bounding box and the predicted bounding box, b,b gt These represent the center points of the predicted and ground truth boxes, respectively. ρ represents the Euclidean distance between the two center points, and c represents the diagonal distance of the smallest closure region that can simultaneously contain both the predicted and ground truth boxes. The entire expression is the DIoU loss function.

[0078] Soft-NMS, a crucial post-processing step in object detection, removes overlapping predicted bounding boxes based on a threshold. Boxes exceeding the threshold are deleted, while those below are retained; non-overlapping boxes are always kept. The typical object detection process sorts boxes by score, retaining higher-scoring boxes and deleting those with a greater than a certain overlap. However, this approach has limitations. In practical inference, if an object lies within the overlap area of ​​a high-scoring box, it may be missed, leading to inaccurate positioning of many high-confidence boxes. The core idea of ​​Soft-NMS is to improve the IoU and thresholding processes in the loop. It uses weights to attenuate the confidence scores of predicted boxes and introduces a weighting function to mitigate this problem, requiring the setting of a threshold.

[0079] This embodiment also discloses a mask detection system, including:

[0080] Image dataset acquisition module: used to acquire mask image datasets;

[0081] Initial Mask Detection Model Mask-YOLO Establishment Module: Used to establish the initial mask detection model Mask-YOLO, which includes a feature extraction part, a multi-scale fusion part, and a classification and detection head part. The feature extraction part adopts the Coodinate Attention mechanism and the RFB module, and the multi-scale fusion part adopts the FPN network structure.

[0082] The initial mask detection model Mask-YOLO training module is used to train the initial mask detection model Mask-YOLO using a mask image dataset, thus obtaining the mask detection model Mask-YOLO.

[0083] Detection Results Module: This module is used to input the image to be detected into the Mask-YOLO mask detection model and obtain the detection results.

[0084] Example 2

[0085] This embodiment discloses the specific experimental method:

[0086] This experiment used the Moxa dataset, which contains 3000 images: 2800 for training and 200 for testing. 678 of these images came from the Maskhsun2020 dataset. The crowd density in the images effectively distinguishes between wearing and not wearing masks. There are also 757 close-up facial images, including frontal and side views. An additional 1565 images were crawled from Google Image Search. These 3000 images were divided into two categories: 9161 faces without masks and 3015 faces with full masks.

[0087] The computer operating system used in this experiment was Ubuntu 22.04, PyTorch version 2.0.1, CUDA version 11.8, and CPU version [missing information]. The system used a Core™ i7 13700KF processor, an Nvidia RTX 4090 (24G) GPU, and 64G of RAM. The experimental parameters were set as follows: 150 training epochs, a batch size of 16, SGD optimization strategy, an input image size of 640, and cosine annealing decay algorithm for learning rate decay.

[0088] The evaluation metrics used in this experiment are precision, recall, mean accuracy (mAP@0.5 and mAP@0.5-0.95), number of model parameters, and model complexity (GFLOPs) to assess the model's generalization performance, defined as follows:

[0089]

[0090]

[0091]

[0092] Where TP represents the number of positive samples identified, FP represents the number of falsely reported negative samples, and FN represents the number of falsely reported positive samples. mAP represents the average of the AP of all images in each class for a specific IoU value.

[0093] Table 1 Comparison of experimental performance of YOLO series lightweight models

[0094]

[0095]

[0096] Table 1 shows a performance comparison between the Mask-YOLO algorithm proposed in this invention and the lightweight YOLO series algorithms. YOLOv3-tiny, as an early algorithm, achieved a mAP of 0.339 in mask detection model accuracy (0.5-0.95 overall detection effect). However, due to its large number of parameters and model complexity, it does not have an advantage in the overall performance evaluation of lightweight networks. The experimental results of YOLOv5s and YOLOv5m are comparable. Due to its large number of parameters, YOLOv5m takes longer to train than YOLOv5n, and its model complexity is also higher, leading to more complex integration. YOLOv8n, as the latest detector in the current YOLO series, integrates various excellent algorithmic theories and designs, ultimately achieving an average accuracy performance of 0.345 mAP@0.5-0.95. Compared with the baseline YOLOv5n, the model complexity is improved by 97.6%, the number of parameters increases by 70.6%, and the algorithm mAP@0.5-0.95 is improved by 2.1%. However, negative growth was observed in the evaluation metrics of P, R, and mAP@0.5. This phenomenon may be due to the fact that the model complexity cannot match the capacity of the current dataset, and it is not an ideal algorithm choice for the research of lightweight mask algorithms. Mask-YOLO integrates the excellent design of the above methods. Compared with the baseline model YOLOv5n, the model complexity increases from 4.1 GFLOPs to 4.4 GFLOPs, while achieving a performance improvement of 8.58% in the overall evaluation index of mAP@0.5-0.95. It also improves the performance of the latest YOLOv8n algorithm in mAP@0.5-0.95 by 6.38%, achieving efficient and stable detection performance.

[0097] Table 2 Performance Comparison of Activation Functions

[0098] Note: "*" indicates the method used in this embodiment.

[0099] Sigmoid 0.777 0.686 0.768 0.329 1761871 4.1 Tanh 0.737 0.695 0.751 0.335 1761871 4.1 SiLU 0.769 0.752 0.777 0.338 1761871 4.1 Mish 0.747 0.705 0.776 0.341 1761871 4.1 Hardswish 0.788 0.729 0.788 0.343 1761871 4.1 ReLU 0.74 0.743 0.782 0.345 1761871 4.1 LeakyReLU 0.701 0.705 0.78 0.347 1761871 4.1 Softplus* 0.791 0.734 0.789 0.355 1761871 4.1

[0100] Table 2 shows the impact of different activation functions on the overall model performance. In this experiment, the baseline YOLOv5n model used the SiLU activation function, achieving an mAP of 0.338 in the range of 0.5-0.95. When the convolutional blocks used the Sigmoid activation function, performance degraded. This phenomenon may be due to the vanishing gradient at boundary points of the Sigmoid function, which slows down model training convergence and ultimately affects model optimization, failing to achieve performance improvement. The Tanh, Mish, Hardswish, ReLU, and LeakReLU activation functions all improved the performance of the convolutional blocks, achieving performance improvements compared to the baseline model. Among them, the Softplus activation function achieved the best results, improving mAP by 5% compared to the baseline model using the SiLU activation function. This function further smooths the ReLU activation function, making gradient propagation more gradual and alleviating the vanishing gradient phenomenon to some extent.

[0101] Table 3 Comparison of IoU bounding box loss functions

[0102] BasicIoU 0.779 0.71 0.781 0.343 1761871 4.1 CIoU 0.769 0.752 0.777 0.338 1761871 4.1 SIoU 0.803 0.687 0.772 0.342 1761871 4.1 DIoU* 0.786 0.705 0.792 0.345 1761871 4.1

[0103] Note: "*" indicates the method used in this embodiment.

[0104] Table 3 shows the impact of different IoU bounding box loss functions on model performance. The baseline uses the CIoU loss function, which only shows a slight increase in recall compared to the original IoU loss function, but degrades the overall mAP@0.5-0.95. This is likely because the mask dataset has relatively few categories and low annotation complexity, and does not exhibit the complex intersecting situations between predicted and ground truth boxes that are present in the CIoU loss function. Therefore, the CIoU loss function is not suitable for this mask dataset. The SIoU loss function also exhibits the same phenomenon as CIoU. When using the DIoU loss function as the Mask-YOLO bounding box processing function, the best performance is achieved at 0.345 in mAP@0.5-0.95, a 2.1% improvement over the baseline model. DIoU is simple and feasible, making it more suitable for datasets with low category and annotation complexity, and it is faster and more efficient in handling the inclusion of predicted and ground truth boxes.

[0105] Table 4 Comparison of Deep Feature Extraction Modules

[0106] SPP 0.749 0.69 0.774 0.338 1761871 4.1 SPPF 0.769 0.752 0.777 0.338 1761871 4.1 SimSPPF 0.776 0.707 0.78 0.343 1762255 4.1 RFB* 0.788 0.699 0.789 0.346 1927919 4.3

[0107] Note: "*" indicates the method used in this embodiment.

[0108] Table 4 shows the impact of different feature extraction modules on network performance in the backbone feature extraction network. Deep networks possess very rich semantic information, and how to fully explore and utilize it is an important step in object detection tasks. The baseline model uses SPPF, which achieves certain improvements in model performance metrics P, R, and mAP@0.5 compared to the original SPP module. SimSPFF is a faster version of SPPF, but its performance is not significant, possibly due to the architecture design leading to some loss of accuracy. RFB achieves the best results, improving P, R, and mAP@0.5-0.95 by 2.5%, 1.5%, and 2.4% respectively compared to the baseline. RFB diversifies the convolutional receptive field by using an Inception multi-branch multi-path structure and different dilation rates, and further increases the efficiency of gradient propagation through short connections, thus achieving a more comprehensive efficiency improvement.

[0109] Table 5 Ablation experiments with the Mask-YOLO improved module

[0110] √ 0.769 0.752 0.777 0.338 √ √ 0.791 0.734 0.789 0.355 √ √ √ 0.801 0.692 0.779 0.344 √ √ 0.786 0.705 0.792 0.345 √ √ √ 0.743 0.72 0.77 0.358 √ √ √ √ √ 0.75 0.73 0.794 0.343 √ √ 0.782 0.715 0.783 0.337 √ √ √ √ √ √ 0.772 0.741 0.783 0.361 √ √ √ √ √ √ √ 0.742 0.738 0.776 0.37

[0111] Table 5 shows the ablation experiments of each improved module in Mask-YOLO. The baseline model used is YOLOv5n. When the Softplus activation function was added to the convolutional feature extraction block, the mAP@0.5-0.95 evaluation metric improved by 5%. Using the DIoU loss function, due to its simple and efficient processing characteristics, it improved by 2.1% compared to the baseline. Using only the SoftPlus and RFB modules, the mAP@0.5-0.95 performance improved from 0.338 to 0.358, an improvement of 5.9%. The efficient semantic information feature extraction processing of RFB significantly improved the model performance. The BiFPN design was used to fuse and learn cross-stage feature maps, further shortening the feature propagation path and achieving efficient feature complementarity to assist in small target detection, improving the accuracy (P) metric by 1.7%, confirming the efficiency and effectiveness of the BiFPN module design. Finally, when all the designs were integrated into Mask-YOLO, a final mAP of 0.367 was achieved, representing an 8.58% improvement compared to the baseline model YOLOv5n's 0.338. Experiments demonstrate that the Mask-YOLO design proposed in this invention can achieve efficient and stable mask target detection.

[0112] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.

[0113] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined in this invention may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for testing face masks, characterized in that, Includes the following steps: Obtain a dataset of mask images; Establish an initial mask detection model, Mask-YOLO: It includes a feature extraction part, a multi-scale fusion part, and a classification and detection head part. The feature extraction part adopts the Coodinate Attention mechanism and the RFB module, and the multi-scale fusion part adopts the FPN network structure. The initial mask detection model Mask-YOLO was trained using a mask image dataset to obtain the mask detection model Mask-YOLO; The image to be detected is input into the Mask-YOLO mask detection model to obtain the detection results.

2. The mask testing method according to claim 1, characterized in that, The Coodinate Attention mechanism is set up as follows: The input channel data is first encoded by two average pooling operations. Information is aggregated in both width and height dimensions, and then processed by channel-level concatenation and convolutional smoothing to generate a global receptive field. After batch regularization and non-linear mapping transformation, and with the same number of channels as the input data, the weights are expanded to serve as the final weights for attention.

3. The mask testing method according to claim 2, characterized in that, The final weight expression is as follows: Among them, y c (i,j) represents the feature of the final output, x c (i,j) represents the original features. This indicates that the feature recovers the original number of channels in the height dimension after aggregation processing. This indicates a feature that restores the original number of channels in the width dimension after aggregation processing.

4. The mask testing method according to claim 1, characterized in that, The RFB module consists of consecutive 1×1 convolutional blocks, 3×3 convolutional blocks, 5×5 convolutional blocks, and short connections.

5. The mask testing method according to claim 1, characterized in that, The FPN network structure, based on PANet, adopts a cross-stage connection method to fuse feature information from different stages.

6. The mask testing method according to claim 1, characterized in that, The activation function of the Mask-YOLO mask detection model is as follows: Softplus(x)=log(1+e x ); Where x represents the input feature, and the whole expression is the Softplus activation function expression.

7. The mask testing method according to claim 1, characterized in that, The loss function of the Mask-YOLO mask detection model is as follows: Where IoU represents the intersection-union ratio of the ground truth bounding box and the predicted bounding box, b,b gt These represent the center points of the predicted and ground truth boxes, respectively. ρ represents the Euclidean distance between the two center points, and c represents the diagonal distance of the smallest closure region that can simultaneously contain both the predicted and ground truth boxes. The entire expression is the DIoU loss function.

8. A mask detection system, characterized in that, include: Image dataset acquisition module: used to acquire mask image datasets; Initial Mask Detection Model Mask-YOLO Establishment Module: Used to establish the initial mask detection model Mask-YOLO. It includes a feature extraction part, a multi-scale fusion part, and a classification and detection head part. The feature extraction part adopts the CoodinateAttention mechanism and the RFB module, and the multi-scale fusion part adopts the FPN network structure. The initial mask detection model Mask-YOLO training module is used to train the initial mask detection model Mask-YOLO using a mask image dataset, thus obtaining the mask detection model Mask-YOLO. Detection Results Module: This module is used to input the image to be detected into the Mask-YOLO mask detection model to obtain the detection results.