# Multi-Scale Safety Helmet Detection Based on SAS-YOLOv3-Tiny
## 2 The Principles of YOLOv3-Tiny
### Bounding Box Prediction  
YOLOv3 continued to employ K-means clustering of YOLOv2 to determine the prior boxes, which drew on the anchor box mechanism of RPN in Faster R-CNN. K-means clustering algorithm in YOLOv3-tiny obtained K prior boxes on the Common Objects in Context (COCO) dataset according to the annotated ground truth boxes, which could improve the detection accuracy and speed. [PERSON] et al. modified the clustering distance in the k-means algorithm [12]. As shown in Formula (1), it is defined by _IOU_. The larger the _IOU_ is, the closer distance of the two bounding boxes is.  
\[d(box,centroid)=1-IOU(box,centroid) \tag{1}\]  
In Formula (1), \(d(box,centroid)\) represents the clustering distance, _centroid_ represents the box that is selected as the center of mass by the algorithm, _box_ represents the other bounding boxes and _IOU_ represents the ratio of the intersecting area of the two boxes to the combined area. Even though too many prior boxes can guarantee the detection effects, it greatly affects the efficiency of the algorithm. YOLOv3-tiny used six prior boxes. The corresponding relationship between feature maps and prior boxes is as follows. Feature maps of size 14, 28 correspond [(81,82); (135,169); (344,319)], [(10,14); (23,27); (37,58)], respectively. Generally, large feature maps usually have small receptive fields,  
Figure 1: YOLOv3-tiny network structure.  
which are very sensitive to small-scale objects, and thus, they will select small prior boxes. On the contrary, small feature maps always have large receptive fields, which are suitable for detecting large objects, and thus, they select large prior boxes.  
The final predicted bounding box coordinates of the YOLOv3-tiny network can be obtained by Formulas (2) and (3), and the final bounding box prediction schematic is shown in Figure 2. The confidence is divided into two parts: one is the probability of the existence of the object, showed by \(P_{r}(object)\) (if the object exists, \(P_{r}(object)=1\), otherwise it is 0), while the other is the accuracy of the predicted bounding box, which is shown in Formula (4).  
\[b_{x}=\sigma(t_{x})+c_{x}\quad b_{y}=\sigma(t_{y})+c_{y} \tag{2}\]  
\[b_{w}=p_{w}e^{t_{w}}\quad b_{h}=p_{h}e^{t_{h}} \tag{3}\]  
\[C_{conf}=P_{r}(class_{i}|object\,)\times P_{r}(object)\times IOU_{pred}^{truth }{=}P_{r}(class)\times IOU_{pred}^{truth} \tag{4}\]  
In Formulas (2) and (3), \(b_{x}\) and \(b_{y}\) are the coordinates of the center point of the modified bounding box; \(b_{w}\) and \(b_{h}\) represent the width and height of the modified bounding box, respectively; \(t_{x}\) and \(t_{y}\) represent the offset between the object center point and the upper-left corner of the grid; \(t_{w}\) and \(t_{h}\) represent the offset of the width and height of the predicted bounding box, respectively; \(c_{x}\) and \(c_{y}\) represent the offset of the grid relative to the upper-left corner. \(p_{w}\) and \(p_{h}\) are the width and height of the prior box, respectively. The sigmoid function is used to control the range of value within (0, 1) and control the offset of the object center within the corresponding grid cell to ensure that it is not out of bounds. In Formula (4), \(C_{conf}\) represents the confidence score of a specific category for each box; \(P_{r}(class_{i}|object)\) represents the probability of predicting C conditional class in each grid cell (\(I=1,2,\,\ldots,\,C\)); \(P_{r}(object)\times IOU_{pred}^{truth}\) represents the confidence score; \(IOU_{pred}^{truth}\) represents the intersection ratio of the ground truth box and the prediction box.