# The Application of Improved YOLO V3 in Multi-Scale Target Detection
## 3 Our Approach
### Appropriate Size for Anchor Boxes
We assume that half the side length of the anchor boxes and the ground truth box is longer than the length of the grid cell in the feature map. \[\frac{1}{2}S_{a}\geq 2^{d} \tag{4}\]  
\[\frac{1}{2}S_{g}\geq 2^{d} \tag{5}\]  
Figure 4: Two extreme cases between anchor box and ground truth box. (**a**) The ground truth box is right in the anchor box (**b**) The center of the anchor box is in the upper left corner of the grid cell and the center of the ground truth box is in the bottom right corner of the grid cell. The IOU between the anchor box and the ground truth box can be expressed by (6)  
\[IOU(anchor,GT)=\frac{\left(\frac{S_{a}}{2}-2^{d}+\frac{S_{g}}{2}\right)^{2}}{S_{g} ^{2}+S_{a}^{2}-\left(\frac{S_{a}}{2}-2^{d}+\frac{S_{g}}{2}\right)^{2}} \tag{6}\]  
\[\frac{\left(\frac{S_{a}}{2}-2^{d}+\frac{S_{g}}{2}\right)^{2}}{S_{g}^{2}+S_{a}^ {2}-\left(\frac{S_{a}}{2}-2^{d}+\frac{S_{g}}{2}\right)^{2}}\geq\frac{\left( \sqrt{S_{a}S_{g}}-2^{d}\right)^{2}}{S_{g}^{2}+S_{a}^{2}-\left(\sqrt{S_{a}S_{g} }-2^{d}\right)^{2}} \tag{7}\]  
when \(S_{a}=S_{g}\), the equal sign in the inequality (7) is true. From (3), the IOU between anchor box and the ground truth box in Figure 4a can be 1. We hope the IOU in (6) is greater than 0.5 so we can get the inequality to appear as follows  
Figure 3:0  
Then we can get the side length \(S_{a}\) and the area of an anchor box with the numbers of the downsampling \(d\). This is shown in Figure 3:1  
With the results in Table 1, we got the appropriate size and area of the anchor boxes for each scale of the output detection layer. However, the clusters generated by K-means on each dataset are not quadratic. Like the cluster (63, 32) generated by K-means on KITTI dataset, the height of the anchor box is much longer than that of the width. What is more, the height of the anchor meet the demand of output detection layer which is downsampled by \(4\times\) and the width of the anchor box meet the demand of the detection layer, which is downsampled by \(8\times\) according to Figure 3:2 To solve this problem, suppose the height and the width of the anchor box are \(h\) and \(w\), we compare the value of \(\sqrt{h\times w}\) with \(S_{a}\) to determine which scale is suitable for this anchor. The cluster (63, 32) is suitable for the output detection layer which is downsampled by \(8\times\) (\(43.6\leq\sqrt{63\times 32}\leq 87.2\)). So the principle to select suitable anchor boxes for each scale of the output detection layer can be concluded as follows:  
* Apply the K-means clustering to get the candidate anchor boxes on each dataset. * Calculate the value of \(\sqrt{h\times w}\) for each candidate anchor box. * Compare \(\sqrt{h\times w}\) with \(S_{a}\) in Table 1 and select the appropriate scale for each anchor box. According to the principle above, we can allocate the clusters on PASCAL VOC dataset to each suitable scale. This is shown in Figure 3:3 \begin{table}
\begin{tabular}{c c c} \hline \hline \(d\) & \(S_{a}\)\(\geq\) & \(S_{a}^{2}\)\(\geq\) \\ \hline
2 & 21.8 & 476 \\
3 & 43.6 & 1901 \\
4 & 87.2 & 7604 \\
5 & 174.4 & 30,416 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: The relationship between the numbers of downsampling and the size of the anchor box. \begin{table}
\begin{tabular}{c c c} \hline \hline \(d\) & **Range** & **Anchor Boxes** \\ \hline
2 & \(21.8\leq\sqrt{h\times w}\leq 43.6\) & (22, 23), (29, 39), (37, 43) \\
3 & \(43.6\leq\sqrt{h\times w}\leq 87.2\) & (59, 59), (53, 89) \\
4 & \(87.2\leq\sqrt{h\times w}\leq 174.4\) & (81, 98), (119, 117), (128, 163) \\
5 & \(174.4\leq\sqrt{h\times w}\) & (173, 185), (248, 229), (308, 231), (428, 320) \\ \hline \hline \end{tabular}
\end{table} 
Table 3: The allocation of clusters on PASCAL VOC dataset at each scale. The allocation of each cluster on KITTI dataset can be shown in Table 4.