# The Application of Improved YOLO V3 in Multi-Scale Target Detection
## 3 Our Approach
### Appropriate Size for Anchor Boxes  
YOLO V3 introduced the idea of anchor boxes used in Faster R-CNN. Anchor boxes are a set of initial candidate boxes with a fixed width and height. The choice of the initial anchor boxes will directly affect the detection accuracy and the detection speed. Instead of choosing anchor boxes by hand, YOLO V3 runs K-means clustering on the dataset to find good priors automatically. The clusters generated by K-means can reflect the distribution of the samples in each dataset, which can make it easier for the network to get good predictions. In this paper, Avg IOU is used as a metric of target clustering analysis. The objective function of clustering Avg IOU is as follows:  
\[\underset{\text{argmax}\times}{\sum\limits_{i=1}^{k}\sum\limits_{j=1}^{n_{k}} IOU(box,\text{\emph{centroid}})\over n}, \tag{1}\]  
where \(box\) is the sample, namely the ground truth of the target. _centroid_ is the center of the cluster. \(n_{k}\) is the numbers of samples in the \(k\)th cluster center. \(k\) is the total number of samples. \(n\) is the numbers of clusters. \(IOU(box,\text{\emph{centroid}})\) is the intersection over Union of the clusters and the sample. We applied K-means clustering on the PASCAL VOC and KITTI dataset, respectively. The Figure 3 shows the average IOU we got with different value of \(k\). With the increase of \(k\), the change of the objective function became more and more stable. Considering Avg IOU and the number of detection layers, we selected 12 anchor boxes. The width and the height of the corresponding clusters on PASCAL VOC dataset and KITTI dataset are shown in Table 1. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Dataset** & **PASCAL VOC** & **KITTI** \\ \hline \multirow{3}{*}{Clusters} & (22, 23), (29, 39), (37, 43), (59, 59), (53, 89), & (21, 22), (32,24), (26, 40), (45, 40), (63, 32), \\  & (81, 98), (119, 117), (128, 163), (173, 185), & (62, 56), (73, 60), (106, 57), (92, 116), \\  & (248, 229), (308, 231), (428, 320) & (131, 118), (200, 130), (316, 181) \\ \hline \hline \end{tabular}
\end{table} 
Table 1: The corresponding clusters on PASCAL VOC and KITTI dataset. Figure 3: K-means clustering analysis result. **(a)** KITTI dataset; **(b)** PASCAL VOC. After K-means clustering on the dataset, cluster centers are generated. YOLO V3 divides up the clusters evenly across scales. This may cause some clusters to be placed at inappropriate scales because the clusters are arbitrarily allocated. It is essential to determine what size of the anchor box is suitable for each scale of the network. Inspired by the method of the proposal generation [33], we used mathematical derivation based on IOU to help select the appropriate size of the anchor boxes for each scale. There are two extreme cases, as shown in Figure 4. The red box represents the anchor box and the black box represents the ground truth box, and the green box is the grid cell of the feature map. If \(S_{a}\) is the side length of an anchor box and \(S_{g}\) is the side length of the ground truth box, and \(2^{d}\) is the side length of the grid cell in the feature map. \(d\) is the numbers of downsampling layers. Consider the extreme case in Figure 4a: We assume the anchor boxes and the ground truth boxes are quadrate and the anchor box is bigger than the ground truth box (\(S_{a}\geq S_{g}\)). The IOU between the anchor box and the ground truth box can be defined as  
\[IOU(anchor,GT)=\frac{S_{g}^{2}}{S_{a}^{2}}=\lambda \tag{2}\]  
where \(GT\) is ground truth box. The common metric to decide the prediction results is to see if the IOU is greater than 0.5 (\(\lambda\geq 0.5\)). Then we can get the result as follows  
\[\sqrt{2}S_{g}\geq S_{a}\geq S_{g} \tag{3}\]  
Consider the extreme case in Figure 4b: The center of the anchor box is in the upper left corner of the grid cell of the feature map and the center of the ground truth box is in the bottom right corner of the grid cell.