# Mask-Wearing Detection in Complex Environments Based on Improved YOLOv7
## 2 Related Works
### Detection Heads  
In object detection tasks, the detection head is a specific module used to recognize and locate targets, and its design significantly influences the model's detection accuracy and speed. Currently, detection heads can be mainly categorized into four types: anchor-based, anchor-free, self-attention, and cascade. Among them, anchor-based and anchor-free are the most widely used types. For instance, the YOLO series, SSD series, and most R-CNN series are predominantly designed based on anchors, utilizing predefined anchor boxes to match real target boxes. On the other hand, models such as CornerNet [16], CenterNet [17], \begin{table}
\begin{tabular}{p{42.7 pt} p{341.4 pt}} \hline \hline
**Name** & \multicolumn{1}{c}{**Loss Function Description**} \\ \hline IoU & Intersection over union: the ratio of the intersection area to the union area between the predicted and true bounding boxes. It ranges from 0 to 1, with 1 indicating perfect overlap. However, the IoU does not reflect the distance between non-overlapping boxes or distinguish accuracy when the IoU is the same for multiple predictions. \\ \hline GIoU & Generalized IoU: an extension of the IoU that introduces the smallest enclosing box for both the predicted and true boxes. It encourages the predicted box to be as close as possible to the true box, especially when they do not overlap. The GIoU reduces to the IoU when the boxes are horizontally aligned. \\ \hline DIoU & Distance IoU: builds upon the IoU by considering the Euclidean distance between the centers of the predicted and true boxes, along with the overlap area. This helps improve the convergence speed of the loss function. \\ \hline CIoU & Complete IoU: an extension of the DIoU that also incorporates aspect ratio information to enhance the stability of object box regression. It provides better judgment when the aspect ratios differ significantly. \\ \hline EIoU & Enhanced IoU: an extension of the CIoU that separates the aspect ratio’s influence factor for the predicted and true boxes. It calculates the lengths and widths independently, improving the convergence speed and achieving better localization accuracy. \\ \hline \(\alpha\) IoU & Alpha IoU: introduces a tunable alpha parameter to the IoU for increased flexibility in adapting to different horizontal boundary regression box accuracies. It exhibits better robustness in small datasets and noise. \\ \hline SIoU & Spatial IoU: an extension of the EIoU that adds the angle loss between the predicted and true box centers. It redefines distance loss, effectively reducing regression freedom. Additionally, it introduces a category information weighting factor to enhance detection model classification accuracy. \\ \hline WIoU & Weighted IoU: introduces attention-based bounding box losses. WIoU v1 constructs attention-based bounding box losses, while WIoU v2 and v3 further enhance the attention mechanism by introducing gradient gain (focus coefficient) calculation methods. \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Comparison of different loss functions. and FCOS are designed based on anchor-free principles. The key distinction lies in whether predefined anchor boxes are employed to match real target boxes. Furthermore, in object detection tasks, target classification and localization regression are highly correlated, but the learning mechanisms for these two tasks are inherently contradictory. Classification tasks, aiming to enhance semantic understanding, require richer global contextual information and coarse features. On the other hand, regression tasks prefer detailed information about the bounding boxes, necessitating fine features. As a result, the coupled detection head for both tasks is widely recognized to significantly impact model convergence, especially for mask targets that are densely distributed and prone to occlusion. Decoupled detection head (Decouple Head) is a method that decouples the tasks of object classification and localization regression, treating them as independent operations.