An adaptive mask-wearing detection method optimized for small targets

CN117423144BActive Publication Date: 2026-09-18NANJING UNIV OF POSTS & TELECOMM
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311422976.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-31
Publication Date
2026-09-18
Estimated Expiration
2043-10-31

AI Technical Summary

Technical Problem

[0004]虽然YOLO系列模型与R-CNN系列模型均有各自的优点,但在复杂场景下对目标的检测特别是对小目标的检测,仍存在漏检率高、精度较低等问题

Benefits of technology

[0051] (1) This invention is an adaptive mask-wearing detection method optimized for small targets, and designs an adaptive mask detection network (AMNet-SO) optimized for small targets. The default anchor boxes used in this method have four sizes, which are applied to feature maps of different sizes. The smallest anchor box is specifically responsible for detecting small targets. AMNet-SO can obtain large-scale feature maps by upsampling in the neck network, which can avoid the downsampling factor being too large and causing small target features to be ignored, so that the model can better focus on small targets.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117423144B_ABST
    Figure CN117423144B_ABST
Patent Text Reader

Abstract

This invention belongs to the field of computer vision technology and discloses an adaptive mask-wearing detection method optimized for small targets. An adaptive mask detection network (AMNet-SO) is designed, incorporating a convolutional attention module. A structure for small target detection is designed in the neck network, using a dynamic region-aware convolutional module to enhance feature representation and leveraging cross-stage local network bottlenecks for multi-scale feature fusion. The head network receives feature maps at four scales for detection, calculates the training sample loss, and participates in the gradient backpropagation process. Multiple rounds of iterative training yield the adaptive mask detection network model. The image to be tested is preprocessed and input into the detection model to calculate the detection box. The detection boxes are then fused using weighted boxes to obtain the final detection box and score, thus achieving mask-wearing detection. This invention significantly improves the accuracy of mask-wearing detection in complex scenes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer vision technology, specifically relating to an adaptive mask-wearing detection method optimized for small targets. Background Technology

[0002] Object detection is an active and challenging task in the field of computer vision. Its purpose is to find all objects of interest in an image and determine their category and location. Applications such as vehicle detection and pedestrian detection are of great value to many fields. Among these, face mask detection is a method used to detect and determine whether a person is wearing a mask correctly, playing a significant role in current public safety. However, in complex scenarios, current object detection methods suffer from low accuracy and high false negative rates when detecting small objects.

[0003] Currently, the mainstream object detection models are mainly the R-CNN series and the YOLO series. The R-CNN series includes models such as R-CNN, Fast R-CNN, Faster R-CNN, and Mask R-CNN. This series of models uses deep convolutional neural networks and employs a two-step approach for object detection. First, candidate object regions are extracted using a selective search method, and then a support vector machine classifier is used for object classification. The YOLO series mainly includes models such as YOLOv1, YOLOv2, YOLOv3, and YOLOv4. This series of models uses a single-stage approach, treating object detection as a regression problem, and simultaneously detects bounding boxes and class information through a CNN network.

[0004] Although both the YOLO and R-CNN series models have their own advantages, they still suffer from problems such as high false negative rates and low accuracy in complex scenes, especially in the detection of small targets. Summary of the Invention

[0005] To address the problems existing in the prior art, this invention provides a mask-wearing detection method optimized for small objects. Inspired by the YOLOv5 network structure, an adaptive mask-detection network (AMNet-SO) optimized for small objects is designed. Then, the model learns from the training samples to focus on the mask-wearing features of faces in the image.

[0006] To achieve the above objectives, the present invention is implemented through the following technical solution:

[0007] This invention is an adaptive mask-wearing detection method optimized for small targets, which specifically includes the following steps:

[0008] S1: Read the mask wearing detection dataset, randomly select image data from the dataset for mosaic data augmentation, and obtain training images of the original images;

[0009] S2: Perform adaptive anchor box calculation on the original mask wearing detection dataset, and calculate the best anchor box that is suitable for the real box of the current dataset based on the default anchor box;

[0010] S3: Perform adaptive image scaling on the training images obtained in step 1, uniformly scaling the original images to a standard size, calculating and filling the gray edges, and then feeding them into the network for training to obtain the final training images.

[0011] S4: Input the final training image after step 3 preprocessing into the backbone network of AMNet-SO, and obtain feature maps of different scales after feature extraction.

[0012] S5: Input the feature maps of different scales obtained in step 4 into the neck network of AMNet-SO, and after multi-scale feature fusion, a series of enhanced feature maps are obtained.

[0013] S6: Input the enhanced feature map obtained in step 5 into the head network of AMNet-SO, and perform detection on the feature map based on the anchor boxes to obtain the position, category, and confidence of the detection boxes;

[0014] S7: Match the detection boxes obtained in step 6 with the ground truth boxes to obtain positive and negative samples, then calculate the sample loss, participate in the gradient backpropagation process, update the network parameters, and after multiple iterations, obtain the final detection model.

[0015] S8: Perform data preprocessing on the images to be tested in the dataset, and input the processed images into the final detection model trained in step 7. Perform weighted box fusion on the detection boxes detected by the model to obtain the final position and accuracy of the detected target in the image to be tested. Then calculate the accuracy of the two classes of wearing and not wearing masks, and use the average of the two as the result of the final detection accuracy to achieve mask wearing detection.

[0016] Furthermore, the process of selecting an image for mosaic data enhancement in S1 is specifically as follows:

[0017] S1-1: Randomly read four images from the dataset and perform operations such as flipping, scaling, and color gamut transformation on the four images respectively;

[0018] S1-2: Combine four images into one image to use as training data;

[0019] S1-3: Calculate the offset from the small image to the large image, which is used to calculate the position of the ground truth box after mosaic data augmentation.

[0020] Furthermore, the default anchor boxes in S2 have four sizes: [4,5,8,10,22,18], [10,13,16,30,33,23], [30,61,62,45,59,119], and [116,90,156,198,373,326], which are applied to feature maps with downsampling factors of 4, 8, 16, and 32, respectively. The optimal anchor box that best matches the true bounding boxes in the current dataset is calculated based on the default anchor boxes. The specific process is as follows:

[0021] S2-1: Obtain the width and height of all images and bounding boxes in the dataset, and resize each image to a specified size proportionally. Change the ground truth bounding boxes from relative coordinates to absolute coordinates, and retain ground truth bounding boxes whose width and height are both greater than two pixels;

[0022] S2-2: Verify the ground truth boxes in the dataset using the default anchor boxes, calculate the optimal recall rate for the ground truth boxes relative to the default anchor boxes, and determine whether to update the current anchor boxes based on the recall rate. If the recall rate is less than 0.98, proceed to the following steps; otherwise, skip.

[0023] S2-3: Use the K-means algorithm to cluster all ground truth bounding boxes in the dataset to obtain four different anchor box sizes. Then, use a genetic algorithm to mutate the obtained anchor boxes. If the mutation produces good results, keep it; otherwise, skip it. Finally, return the optimal anchor box.

[0024] Furthermore, in step S4, the final training image obtained in step 3 is input into the backbone network of AMNet-SO, passing sequentially through a 6×6 convolutional layer with a stride of 2, a feature extraction module, a Convolutional Block Attention Module (CBAM), and a Spatial Pyramid Pooling-Fast (SPPF) layer. The first stage of the feature extraction module includes a 3×3 convolutional layer with a stride of 2 and a Cross Stage Partial Network Bottleneck with 3 convolutions (C3) layer; the second stage includes a 3×3 convolutional layer with a stride of 2 and two C3 modules; the third stage includes a 3×3 convolutional layer with a stride of 2 and three C3 modules; and the fourth stage includes a 3×3 convolutional layer with a stride of 2 and one C3 module. After processing by the feature extraction module, feature maps with downsampling factors of 4, 8, 16, and 32 are obtained. CBAM consists of a channel attention module and a spatial attention module, used to enhance the model's attention to small targets, thereby reducing false positives and false negatives. The SPPF layer mainly contains three 5×5 max-pooling layers with a stride of 1. The input feature map passes sequentially through these three max-pooling layers, and the result is obtained by concatenating the input feature map with the outputs of the three max-pooling layers.

[0025] Furthermore, in step S5, the feature maps of different scales obtained in step 4 are input into the neck network of AMNet-SO. The neck network as a whole adopts a combination of Feature Pyramid Network (FPN) and Path Aggregation Network (PAN) to perform multi-scale feature fusion. FPN uses the semantic enhancement module to perform three consecutive upsampling operations to convey strong semantic information. The semantic enhancement module includes one Dynamic Region-Aware Convolution (DRConv), one upsampling, one concatenation module, and one faster Cross Stage Partial Network Bottleneck with 2convolutions-fast (C2f). DRConv can automatically allocate customized convolution kernels to spatial regions, enhancing the ability to model the semantic diversity of images while reducing computational redundancy. C2f takes into account both detailed information and semantic information, completing feature fusion. The multiple upsampling of FPN yields large-scale feature maps, avoiding excessive downsampling factors that ignore small target features, allowing the model to better focus on small targets. PAN utilizes a localization enhancement module to perform three consecutive downsampling operations to transmit strong localization information. The localization enhancement module consists of a 3×3 convolutional layer with a stride of 2, a stitching module, a C2f layer, and a CBAM layer.

[0026] Furthermore, in step S6, the enhanced feature maps obtained in step 5 are input into the head network of AMNet-SO. The head network receives feature maps of four different dimensions: 64×160×160, 128×80×80, 256×40×40, and 512×20×20. These feature maps are then dimensionality-reduced using 1×1 convolutional layers with a stride of 1, and then they are gridded before prediction begins.

[0027] Furthermore, this method uses the SIoU loss function to calculate the sample loss. The SIoU loss function calculation steps in S7 are as follows:

[0028] S7-1: Angle loss is defined as:

[0029]

[0030] Among them, c h σ is the height difference between the center points of the ground truth bounding box and the detection bounding box, and σ is the center point of the ground truth bounding box and the detection bounding box.

[0031] S7-2: Distance loss is defined as...

[0032]

[0033] in, γ=2-Λ,(c w ,c h ) are the width and height of the smallest bounding rectangle of the ground truth bounding box and the detection bounding box, respectively;

[0034] S7-3: Shape loss is defined as:

[0035]

[0036] in (w,h) and (w) gt ,h gt ) are the width and height of the detection box and the ground truth box, respectively. θ controls the degree of attention to shape loss. In order to avoid focusing too much on shape loss and reducing the movement of the detection box, θ is calculated to be close to 4 by a genetic algorithm, and the general range is [2,6].

[0037] S7-4: The final SIoU result is as follows:

[0038]

[0039] Wherein, IoU is the intersection-union ratio between the detected bounding box and the ground truth bounding box.

[0040] Furthermore, in step S8, weighted box fusion (WBF) is performed on the detection boxes detected by the model to obtain the final position and accuracy of the detected target. The operation is as follows:

[0041] S8-1: Define list B, where each position in B stores a detection box. Add all detection boxes in the image to be tested to list B and sort them in descending order of confidence C.

[0042] S8-2: Define list L, where each position in L stores a cluster of detection boxes, representing different detection boxes for the same target. Define list F, where each position in F stores a merged box. Lists L and F are initially empty, and the clusters of detection boxes in L correspond one-to-one with the positions of the merged boxes in F within the lists.

[0043] S8-3: Iterate through list B. For each detection box in B, try to find a matching merge box in F. A match is considered found when the intersection-union ratio (IU) of the detection box and the merge box is greater than a threshold, which is usually 0.55.

[0044] S8-4: If no match is found in F, add the detection box to the end of L and F as a new entry, and then continue to traverse the next detection box in B; if a match is found in F, continue to do the following: denote the matching position in F as p, and add the detection box to the p-th cluster in L;

[0045] S8-5: Using the existing T bounding boxes in the p-th cluster of L, recalculate the coordinates and confidence score of the fused bounding box at the p-th position in F. The fusion formula is as follows:

[0046]

[0047]

[0048] Where T is the number of detection boxes in the p-th cluster of L, and C i Let X1 be the confidence score of the i-th detection box in the cluster. 2i Y1 is the x-coordinate of the i-th detection box in the cluster. 2i X1,2 is the ordinate of the i-th detection box in the cluster, X1,2 is the x-coordinate of the fused box, and Y1,2 is the ordinate of the fused box.

[0049] The confidence score of the fused bounding box is the average confidence score of these T detection boxes. The coordinates of the fused bounding box are the weighted sum of the coordinates of these T boxes, where the weight is the confidence score of the corresponding box. Therefore, detection boxes with higher confidence scores contribute more to the coordinates of the fused bounding box than detection boxes with lower confidence scores.

[0050] The beneficial effects of this invention are:

[0051] (1) This invention is an adaptive mask-wearing detection method optimized for small targets, and designs an adaptive mask detection network (AMNet-SO) optimized for small targets. The default anchor boxes used in this method have four sizes, which are applied to feature maps of different sizes. The smallest anchor box is specifically responsible for detecting small targets. AMNet-SO can obtain large-scale feature maps by upsampling in the neck network, which can avoid the downsampling factor being too large and causing small target features to be ignored, so that the model can better focus on small targets.

[0052] (2) This invention integrates an attention mechanism into AMNet-SO and uses CBAM to enhance the model's attention to small targets, reducing false positives and false negatives. At the same time, AMNet-SO uses DRConv instead of ordinary convolution in FPN, which can reduce the computational redundancy caused by stacking ordinary convolutions and increase the feature representation capability; AMNet-SO uses C2f for multi-scale feature fusion in the neck network, taking into account both detailed information and semantic information.

[0053] (3) In the process of training the model, the present invention uses the SIoU loss function to calculate the sample loss. SIoU adds angle perception and redefines the penalty index, which enables the model to converge faster and improves the training speed and accuracy. After detecting the detection box, the weighted box fusion is used to obtain the final result, making the detection result more accurate. Attached Figure Description

[0054] Figure 1 This is a flowchart of the adaptive mask wearing detection method of the present invention.

[0055] Figure 2 This is a network structure diagram of the adaptive mask wearing detection model of the present invention. Detailed Implementation

[0056] To make the content of this invention easier to understand, the invention will be further described in detail below with reference to specific embodiments and accompanying drawings.

[0057] like Figure 1 As shown, this invention is an adaptive mask-wearing detection method optimized for small targets. The mask-wearing detection method specifically includes the following steps:

[0058] S1: Read the training set from the mask wearing detection dataset, randomly select image data from the training set for data preprocessing, including mosaic data augmentation, adaptive anchor box calculation, and adaptive image scaling, to obtain the training images of the original images, and then send the training images of the original images into AMNet-SO.

[0059] S2: The preprocessed image first enters the backbone network of AMNet-SO, and after feature extraction, feature maps of different scales are obtained;

[0060] S3: Input the feature maps of different scales obtained in step 2 into the neck network of AMNet-SO to perform multi-scale feature fusion, and then obtain a series of enhanced feature maps;

[0061] S4: Input the enhanced feature map obtained in step 3 into the head network of AMNet-SO, and perform detection on the feature map based on the anchor boxes to obtain the position, category, and confidence of the detection boxes;

[0062] S5: Match the detection boxes obtained in step 4 with the ground truth boxes to obtain positive and negative samples, then calculate the sample loss, participate in the gradient backpropagation process, and update the network parameters. After multiple iterations, the final detection model is obtained;

[0063] S6: Perform data preprocessing on the image to be tested, and input the processed image into the final detection model obtained in step 5. Weighted bounding box fusion is performed on the detection boxes detected by the model to obtain the final position and accuracy of the detected target in the image. Then, the accuracy for both wearing and not wearing masks is calculated, and the average of the two is used as the final detection accuracy result, thus achieving mask-wearing detection.

[0064] like Figure 2 As shown, the detection method proposed in this invention comprises four stages: input, AMNet-SO backbone network, AMNet-SO neck network, and AMNet-SO head network. The input stage is responsible for preprocessing the image before inputting it into AMNet-SO. Preprocessing mainly includes mosaic data augmentation, which combines images to enrich the background; adaptive anchor box calculation, which iteratively calculates the most suitable anchor box by comparing the detection box with the ground truth box; and adaptive image scaling, which scales the image to a standard size. The preprocessed image has dimensions of 3×640×640.

[0065] The preprocessed image first enters the AMNet-SO backbone network. The backbone network is responsible for feature extraction from the input image. The input image sequentially passes through a 6×6 convolutional layer with a stride of 2, a feature extraction module, a CBAM (Concurrent Feature Amplifier), and an SPPF layer. In this embodiment, CBAM is integrated into the backbone network. The CBAM module processes the input feature map through a channel attention module and a spatial attention module to obtain the result. The channel attention module aggregates the spatial information of the feature map using average pooling and max pooling, and feeds it into a shared multilayer perceptron to compress the feature map in the spatial dimension, obtaining a one-dimensional vector. The vector is then summed and merged element-wise to obtain the result from the channel attention module, which is then fed into the spatial attention module. The spatial attention module performs max pooling and average pooling on the input features based on the channels, concatenates them across the channels, reduces the dimensionality to one channel using a 7×7 convolution, activates it with the Sigmoid function, and multiplies this feature with the input features of the module to obtain the final generated feature. The input feature map is fed into the SPPF layer, where it is processed sequentially through three 5×5 max-pooling layers with a stride of 1. The input feature map is then concatenated with the outputs of the three max-pooling layers and fed into the AMNet-SO neck network.

[0066] like Figure 2As shown, the AMNet-SO neck network employs a combination of FPN and PAN for multi-scale feature fusion. FPN utilizes a semantic enhancement module to continuously upsample the feature map multiple times, conveying strong semantic information; while PAN utilizes a localization enhancement module to continuously downsample the feature map multiple times, conveying strong positional information. The combination of FPN and PAN captures richer feature information. AMNet-SO uses a portion of DRConv in the neck network instead of ordinary convolution. DRConv uses a learnable guided mask to partition the space into regions, assigning semantically similar features to the same region. Then, within each region, multiple convolutional kernels generated by a kernel generator are used for convolution operations, enhancing the ability to capture specific features from different images. In addition, AMNet-SO uses C2f for multi-scale feature fusion. The C2f module first processes the input feature map through ordinary convolution, then performs segmentation, and then inputs the segmented feature map into multiple sequential bottleneck layers for processing. Finally, the results from each bottleneck layer are concatenated with the segmented feature map to complete feature fusion. C2f captures richer gradient flow information while maintaining lightweight design.

[0067] The AMNet-SO head network is responsible for object detection on multi-scale feature maps in the neck network. The AMNet-SO head network in this invention can detect feature maps at four different scales, thus improving the detection of small targets.

[0068] This invention uses the SIoU loss function to calculate the sample loss, which participates in gradient backpropagation. The calculation method is as follows:

[0069] Angle loss is defined as:

[0070]

[0071] Among them, c h σ is the height difference between the center points of the ground truth bounding box and the detection bounding box, and σ is the center point of the ground truth bounding box and the detection bounding box.

[0072] Distance loss is defined as

[0073]

[0074] in, γ=2-Λ,(c w ,c h ) are the width and height of the smallest bounding rectangle of the ground truth bounding box and the detection bounding box, respectively;

[0075] Shape loss is defined as:

[0076]

[0077] in (w,h) and (w) gt ,h gt ) are the width and height of the detection box and the ground truth box, respectively. θ controls the degree of attention to shape loss. In order to avoid focusing too much on shape loss and reducing the movement of the detection box, θ is calculated to be close to 4 by a genetic algorithm, and the general range is [2,6].

[0078] The final SIoU result is as follows:

[0079]

[0080] Wherein, IoU is the intersection-union ratio between the detected bounding box and the ground truth bounding box.

[0081] This invention performs object detection on the image to be tested using the trained model, and performs WebBF on the obtained detection boxes. The specific operations are as follows:

[0082] Define list B, where each position in B stores a detection bounding box. Add all detection bounding boxes from the image to be tested to list B, sorted in descending order of confidence C. Define list L, where each position in L stores a cluster of detection bounding boxes, representing different detection bounding boxes for the same target. Define list F, where each position in F stores a fused bounding box. Lists L and F are initially empty, and the detection bounding box clusters in L correspond one-to-one with the positions of the fused bounding boxes in F within the lists.

[0083] Iterate through list B. For each detection box in B, try to find a matching merge box in F. A match is considered found when the intersection-union ratio (IU) of the detection box and the merge box is greater than a threshold, which is usually 0.55. If no match is found in F, add the detection box to the end of L and F as a new entry, and then continue iterating through the next detection box in B. If a match is found in F, continue with the following: denote the matching position in F as p, and add the detection box to the p-th cluster in L.

[0084] Using the existing T bounding boxes in the p-th cluster of L, recalculate the coordinates and confidence score of the fused bounding box at the p-th position in F. The fusion formula is as follows:

[0085]

[0086]

[0087] Where T is the number of detection boxes in the p-th cluster of L, and C i Let X1 be the confidence score of the i-th detection box in the cluster. 2i Y1 is the x-coordinate of the i-th detection box in the cluster. 2iX1,2 is the ordinate of the i-th detection box in the cluster, X1,2 is the x-coordinate of the fused box, and Y1,2 is the ordinate of the fused box.

[0088] The confidence score of the fused bounding box is the average confidence score of these T detection boxes. The coordinates of the fused bounding box are the weighted sum of the coordinates of these T boxes, where the weight is the confidence score of the corresponding box. Therefore, detection boxes with higher confidence scores contribute more to the coordinates of the fused bounding box than detection boxes with lower confidence scores.

[0089] To verify the effectiveness of the method, multiple sets of comparative and ablation experiments were conducted on multiple datasets to compare the performance of the method of this invention with some classic or advanced methods.

[0090] Experimental Example 1

[0091] A. Test conditions

[0092] 1. Experimental Database

[0093] The two datasets used in this invention are derived from: ① face images selected from the WIDER FACE and MAFA datasets; ② open-source face datasets collected online. These two datasets are named WIDER FACE&MAFA and FACE MASK DETECTION, respectively. To accommodate mask-wearing detection, the datasets were divided, as detailed in Table 1.

[0094] Table 1 provides a detailed description of the dataset.

[0095]

[0096]

[0097] 2. Experimental parameter settings

[0098] The model hyperparameter settings are shown in Table 2 below:

[0099] Table 2 Model Hyperparameters

[0100]

[0101] B. Evaluation Criteria for Test Results

[0102] To ensure fairness in performance evaluation, as with most object detection work, this invention selects the average accuracy (mAP@0.5) for both the mask-wearing and unmasked categories at IoU = 0.5 as the evaluation metric. This reflects the average performance of the model in recognizing each category at IoU = 0.5. The higher the value of mAP@0.5, the better the detection performance of the model.

[0103] C. Comparative Experimental Scheme

[0104] This invention was compared with other current state-of-the-art object detection methods on two datasets, WIDER FACE&MAFA and FACE MASK DETECTION. The comparison results are shown in Table 3.

[0105] Table 3 Comparison of Mask Wearing Test Results

[0106]

[0107]

[0108] AMNet-SO is an adaptive mask detection network optimized for small targets designed in this invention. As shown in Table 3, compared to classic target detection methods, the method of this invention achieves the best results on both datasets, with mAP@0.5 significantly higher than the other five classic methods. On the WIDER FACE & MAFA dataset, AMNet-SO's mAP@0.5 reaches 93.2%, which is 2.1%, 10.5%, 7.1%, 14.4%, and 18.8% higher than YOLOv5s, YOLOv4, YOLOv3, YOLOv3-tiny, and SSD methods, respectively. On the FACE MASK DETECTION dataset, AMNet-SO's mAP@0.5 reaches 82.0%, which is 1.9%, 12.2%, 5.3%, 14.4%, and 18.4% higher than YOLOv5s, YOLOv4, YOLOv3, YOLOv3-tiny, and SSD methods, respectively. In addition, AMNet-SO has 8.5M parameters and 21.8 GFLOPs of floating-point operations. Compared to YOLOv5s, both are within a reasonable range, significantly lower than YOLOv4's 64.4M and 60.5 GFLOPs, YOLOv3's 61.5M and 154.6 GFLOPs, and SSD's 24.1M and 274 GFLOPs. Furthermore, AMNet-SO maintains a high frame rate (FPS), enabling good real-time detection. In summary, the method of this invention has significant advantages over other methods.

[0109] D. Ablation test

[0110] To concretely demonstrate the effectiveness of each module, ablation experiments were conducted on the WIDER FACE & MAFA datasets, and the results are shown in Table 4. The first row of the table shows the experimental results after removing the main modules from AMNet-SO, i.e., the network prototype. The remaining rows show the experimental results after fusing different modules into the network prototype, and comparing them with the first row verifies the effectiveness of each module. The last row shows the experimental results of the network after fusing all modules (i.e., AMNet-SO).

[0111] As shown in Table 4, after adding a small object detection module to the network prototype, the network's ability to detect small objects is enhanced by fusing feature maps from different stages, resulting in a 1.5% improvement in mAP@0.5. Using DRConv in the network prototype allows the network to adaptively adjust the size of the convolutional kernel within different receptive fields, thereby better capturing feature information from different regions of the input, leading to a 1.4% improvement in mAP@0.5. Using C2f in the neck network better achieves information transfer and fusion between feature maps at different levels, resulting in a 1.4% improvement in mAP@0.5. Introducing CBAM improves mAP@0.5 by 1.3%. Using the SloU loss function and redefining the penalty metric, the model converges faster than before, also improving mAP@0.5 by 0.4%. Adding WBF allows the model to comprehensively utilize information from various detection boxes to calculate the final detection box during the detection phase, resulting in a significant improvement when combined with other modules. When several modules are used in combination, the performance is significantly better than when used individually. The test results were optimal when all modules were integrated into the model simultaneously, with mAP@0.5 showing a 2.1% improvement compared to the network prototype performance.

[0112] Table 4 Ablation experiments of each module in the network structure

[0113]

[0114]

[0115] In summary, the ablation experiments conducted by AMNet-SO on the WIDER FACE & MAFA datasets demonstrate the effectiveness of each module in the adaptive mask detection network optimized for small targets designed in this invention.

[0116] The above description is merely a preferred embodiment of the present invention and is not intended to further limit the present invention. All equivalent changes made based on the description and drawings of the present invention are within the protection scope of the present invention.

Claims

1. An adaptive mask-wearing detection method optimized for small targets, characterized in that: The adaptive mask-wearing detection method specifically includes the following steps: Step 1: Read the mask wearing detection dataset, randomly select image data from the dataset for mosaic data augmentation, and obtain training images of the original images; Step 2: Perform adaptive anchor box calculation on the original mask wearing detection dataset. Calculate the best anchor box that best fits the real bounding box of the current dataset based on the default anchor boxes. Step 3: Perform adaptive image scaling on the training images obtained in Step 1, uniformly scaling the original images to a standard size, calculating and filling the gray edges, and then feeding them into the network for training to obtain the final training images. Step 4: Input the final training image after the preprocessing in Step 3 into the backbone network of AMNet-SO, and extract features to obtain feature maps at different scales. Step 5: Input the feature maps of different scales obtained in Step 4 into the neck network of AMNet-SO, and perform multi-scale feature fusion to obtain a series of enhanced feature maps; Step 6: Input the enhanced feature map obtained in Step 5 into the head network of AMNet-SO, and perform detection on the feature map based on the anchor boxes to obtain the position, category, and confidence of the detection boxes; Step 7: Match the detection boxes obtained in Step 6 with the ground truth boxes to obtain positive and negative samples, then calculate the sample loss, participate in the gradient backpropagation process, update the network parameters, and after multiple iterations, obtain the final detection model; Step 8: Perform data preprocessing on the images to be tested in the dataset, and input the processed images into the final detection model trained in Step 7. Perform weighted bounding box fusion on the detected bounding boxes to obtain the final position and accuracy of the detected target in the image. Then, calculate the accuracy for both wearing and not wearing masks, and use the average of the two as the final detection accuracy result to achieve mask wearing detection; AMNet-SO consists of a backbone network, a neck network, and a head network. The backbone network of AMNet-SO includes a 6×6 convolutional layer with a stride of 2, a feature extraction module, a convolutional attention module (CBAM), and a spatial pyramid pooling (SPPF) layer. The first stage of the feature extraction module includes a 3×3 convolutional layer with a stride of 2 and a cross-stage local network bottleneck C3 layer with 3 convolutions. The second stage of the feature extraction module includes a 3×3 convolutional layer with a stride of 2 and two C3 modules. The third stage of the feature extraction module includes a 3×3 convolutional layer with a stride of 2 and three C3 modules. The fourth stage of the feature extraction module includes a 3×3 convolutional layer with a stride of 2 and one C3 module. The neck network of AMNet-SO adopts a combination of Feature Pyramid Network (FPN) and Path Aggregation Network (PAN) to perform multi-scale feature fusion. The Feature Pyramid Network uses a semantic enhancement module to perform three consecutive upsampling operations to convey strong semantic information. The semantic enhancement module includes one Dynamic Region Aware Convolution (DRConv), one upsampling operation, one concatenation module, and one cross-stage local network bottleneck C2f with two convolutions. The Path Aggregation Network uses a localization enhancement module to perform three consecutive downsampling operations to convey strong localization information. The localization enhancement module includes one 3×3 convolutional layer with a stride of 2, one concatenation module, one C2f, and one CBAM. The AMNet-SO head network receives feature maps of four different dimensions: 64×160×160, 128×80×80, 256×40×40, and 512×20×20. It uses 1×1 convolutional layers with a stride of 1 to reduce their dimensionality, then grids them, and then starts prediction.

2. The adaptive mask-wearing detection method optimized for small targets according to claim 1, characterized in that: The specific process of selecting images for mosaic data enhancement in step 1 includes the following steps: Step 1-1: Randomly read four images from the dataset and perform operations such as flipping, scaling, and color gamut changes on the four images respectively; Step 1-2: Combine the four images into one image to use as training data; Steps 1-3: Calculate the offset from the small image to the large image, which is used to calculate the position of the ground truth bounding box after mosaic data augmentation.

3. The adaptive mask-wearing detection method optimized for small targets according to claim 1, characterized in that: Calculate the best anchor box that matches the true bounding box in the current dataset based on the default anchor boxes. This involves the following steps: Step 2-1: Obtain the width and height of all images and bounding boxes in the dataset, resize each image to the specified size proportionally, change the ground truth boxes from relative coordinates to absolute coordinates, and retain ground truth boxes with both width and height greater than two pixels. Step 2-2: Use the default anchor box to verify the ground truth boxes in the dataset, calculate the best recall rate of the ground truth boxes relative to the default anchor box, and determine whether the current anchor box needs to be updated based on the recall rate. If the recall rate is less than 0.98, proceed to the following steps; otherwise, skip. Steps 2-3: Use the K-means algorithm to cluster all the ground truth boxes in the dataset to obtain four sizes of anchor boxes. Then use the genetic algorithm to mutate the obtained anchor boxes. If the mutation results are good, keep them; otherwise, skip them. Finally, return the optimal anchor box.

4. The adaptive mask-wearing detection method optimized for small targets according to claim 1, characterized in that: In step 7, the sample loss is calculated using the SIoU loss function, and the SIoU loss function calculation steps are as follows: Step 7-1: Angle loss is defined as: in, The height difference between the center points of the ground truth bounding box and the detection bounding box. The center point of the ground truth bounding box and the detection bounding box; Step 7-2: Distance loss is defined as in, , , , ( , ) are the width and height of the smallest bounding rectangle of the ground truth bounding box and the detection bounding box, respectively; Step 7-3: Shape loss is defined as: in , , and These are the width and height of the detection bounding box and the ground truth bounding box, respectively. To control the degree of attention given to shape loss and avoid reducing the movement of the detection box due to excessive focus on shape loss, a genetic algorithm is used to calculate... It is close to 4, and its general range is [2,6]. Step 7-4: The final SIoU result is as follows: in, This is the intersection-union ratio (IU) between the detected bounding box and the ground truth bounding box.

5. The adaptive mask-wearing detection method optimized for small targets according to claim 1, characterized in that: In step 8, weighted bounding box fusion (WBF) is performed on the detection boxes detected by the model to obtain the final position and accuracy of the detected target. The WBF operation in step 8 is as follows: Step 8-1: Define the list , Each location in the list stores a detection bounding box; all detection bounding boxes in the image to be tested are added to the list. In, and according to confidence level Sort in descending order; Step 8-2: Define the list list Each location in the list stores a cluster of detection boxes, which are different detection boxes for the same target. list Each position in the list stores a merge box. and list Initially, all lists are empty. Detection box clusters and lists The positions of the merge boxes in the list correspond one-to-one; Step 8-3: Traverse the list For lists For each detection box in the list, try to... Find a matching fusion box. When the intersection-union ratio of the detection box and the fusion box is greater than the threshold, a match is considered to have been found. Step 8-4: If not in the list If a match is found, the detection box is added to the list. and list The end of the list is used as the new entry, and then the process continues to iterate through the list. The next detection box in the list, if it is in the list If a match is found, continue with the following operations: Record the list... The matching position is p, and the detection box is added to the list. In the p-th cluster; Step 8-5: Using a list Given the T existing detection boxes in the p-th cluster, recalculate the list. The coordinates and confidence score of the fused bounding box at position p are given by the following fusion formula: , . in for The number of detection boxes in the p-th cluster, The first in the cluster Confidence of each detection box, The first in the cluster The x-coordinate of each detection box, The first in the cluster The ordinate of each detection box, The x-coordinate of the merge box. The vertical coordinate of the fusion box.