# YOLOv7 Optimization Model Based on Attention Mechanism Applied in Dense Scenes
## 5 Application
### Detection in Face Mask Dataset
\begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Model** & **mAP50** & **FPS** & **Parameters** & **GFLOPs** \\  & & & **(M)** & \\ \hline YOLOv5s & 0.769 & 128.2 & 7.01 & 15.8 \\ YOLOv5m & 0.835 & 90.9 & 20.86 & 48 \\ YOLOv5l & 0.842 & 49.3 & 46.11 & 107.8 \\ YOLOv5x & 0.873 & 26.2 & 86.19 & 204 \\ \hline YOLOv6s & 0.574 & 102 & 18.5 & 45.23 \\ YOLOv6m & 0.515 & 58.8 & 34.8 & 85.74 \\ YOLOv6l & 0.538 & 39.8 & 59.54 & 150.67 \\ \hline YOLOv7 & 0.871 & 66.7 & 36.49 & 103.4 \\ YOLOv7H-CA & 0.871 & 62.9 & 36.48 & 103.2 \\ YOLOv7H-SimAM & 0.865 & 67.1 & 36.47 & 103.1 \\ YOLOv7H-CBAM & 0.891 & 66.2 & 36.49 & 103.4 \\ YOLOv7B-CBAM & 0.901 & 49.5 & 36.49 & 103.5 \\ YOLOv7X & 0.816 & 49.3 & 70.8 & 188.2 \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Results of face mask dataset. Figure 9: Results after identification: (**a**) YOLOv7 original model’s result; (**b**) YOLOv7B-CBAM model’s results. 2. When comparing the YOLOv7 model with the added attention mechanism, as shown in Figure 11, the accuracy of the proposed YOLOv7B-CBAM model is the best, with a 3.0% improvement over the original YOLOv7 model and 1.0% improvement over the YOLOv7H-CBAM. Compared with YOLOv7H-CA and YOLOv7H-SimAM, the accuracy is improved by 3.0% and 3.6%, respectively. It proves that the model in this paper can more accurately identify whether the mask is worn or not and the specification. The CBAM module effectively extracts the important features of images and noise reduction of irrelevant information, and the accuracy has surpassed that of the YOLOv7 model using other attention mechanisms as well as the original model. 3. In terms of model size and recognition speed, YOLOv5s and YOLOv5m, with less computation due to their number of parameters, improve the FPS to 128.2 and 90.9, respectively, at the expense of accuracy, which is higher than the YOLOv7 model. The comparison between the YOLOv7 models with the added attention mechanism shows that YOLOv7H-SimAM has less computation and number of parameters than the YOLOv7 model due to its parameter-free characteristics, but its accuracy is not improved. In contrast, YOLOv7B-CBAM does not change the number of parameters  
Figure 11: Optimized YOLOv7 models comparison. Figure 10: YOLOv5 and YOLOv7B-CBAM comparison. but slightly increases the computational power and decreases the FPS by 7, which results in an improvement in accuracy. This comparison shows that the improved YOLOv7B-CBAM model in this paper can more accurately identify the location of the face and determine whether masks are worn properly, which greatly reduces labor cost and improves the safety and hygiene of mask identification. Due to its high accuracy and low missed detection rate, in addition to preventing the new coronavirus, this model can also be applied to places that need to ensure that masks need to be worn properly--for example, in hospital outpatient clinics to reduce the spread of bacteria and viruses and in restaurants or cafeteria kitchens to prevent droplet contamination of food and so on to ensure the hygiene and safety of the premises. The model may be used to test existing models and boost their precision in the future by being applied to more face detection datasets.