# Mask-Wearing Detection in Complex Environments Based on Improved YOLOv7
## 2 Related Works  
### YOLOv7  
YOLOv7 [11] is an outstanding single-stage object detector that offers six different versions: YOLOv7-tiny, YOLOv7, YOLOv7-d6, YOLOv7-e6, YOLOv7-e6e, and YOLOv7-w6. Among them, YOLOv7 focuses on achieving a balance between accuracy and speed when performing inference on edge devices. This paper builds upon this version with improvements aimed at enhancing mask-wearing detection performance. The YOLOv7 network structure comprises three parts: the input stage, backbone, and the neck and head. The input stage is responsible for scaling the input image to meet the requirements of the backbone network. After preprocessing and data augmentation, the processed image is fed into the backbone network for feature extraction. The neck part merges the extracted features to generate features of different sizes: large, medium,and small. These fused features are then passed to the detection head, which outputs a tensor containing the class confidence, object center coordinates, width, and height. YOLOv7 uses the sigmoid function to map the output values between 0 and 1 and applies a non-maximum suppression algorithm for filtering. During inference, YOLOv7 adopts a center-based detection approach where the model predicts the center coordinates, width, height, and object class for each object. Finally, objects are classified and localized based on the prediction results, followed by non-maximum suppression for filtering, resulting in the detection output. The YOLOv7 network structure, as shown in Figure 1, takes 640 \(\times\) 640 three-channel RGB training images as input. It adopts the Mosaic data augmentation method proposed in YOLOv4, which involves randomly cropping four input images and then stitching them together to form a single training image. This enriches the dataset and enhances training efficiency. The backbone network consists mainly of efficient layer aggregation network (ELAN) modules and MP (MaxPool) modules. The ELAN modules are used for image feature extraction and channel control, while the MP modules maintain consistency in the number of channels before and after processing. The neck and detection head comprise the Spatial Pyramid Pooling, Cross-Stage Partial Channel (SPCSPC) modules, extended ELAN (E-ELAN) modules, and MP2 modules. It adopts the same Path Aggregation Feature Pyramid Network (PAFPN) structure as YOLOv5 for aggregating features of multiple sizes. This structure forms large, medium, and small IDetect detection heads and decouples the feature information obtained from the neck. The RepVGG Block (REP) structure is used to adjust the number of channels in the decoupled feature information. Finally, the generated feature maps are predicted and output using 1 \(\times\) 1 convolutions. Through the collaboration of these modules, the YOLOv7 network achieves excellent results in object detection tasks. In recent years, various improvement methods for YOLOv7 have been proposed, leading to a continuous stream of research achievements. [PERSON] et al. [12] introduced the YOLOv7-CPCSDA detection model for mask-wearing detection. They utilized the CatPConv structure to reduce computational redundancy and memory access, added the SD module to enhance the detection of small targets, and introduced the SA mechanism to enhance the collection of local information. The model achieved an average precision of 88.4%. [PERSON] et al. [13] proposed an improved YOLOv7 model for apple detection in complex backgrounds. By introducing a specific multi-head attention mechanism to capture complex interactions between regions and features, they improved the accuracy of  
Figure 1: Network structure of YOLOv7. apple detection, achieving a precision value of 91%. [PERSON] et al. [14] presented an improved mask-wearing detection algorithm based on YOLOv7. They enhanced the perception of small targets by adding attention mechanisms to the backbone network and introducing partial convolution methods.