## 2 Materials and Methods
### YOLOv2 Object Detector Training  
The YOLOv2 detection model dataset was split into 1967 images for training and 328 for validation. The input image is split throughout the training phase into an S \(\times\) S grid, where each cell predicts B bounding boxes. A number of predicted bounding boxes is selected before the training phase, considering that each object has a different shape of anchor boxes [28]. For every bounding box, certain confidence is assigned. The confidence score represents the probability that an object is contained inside a bounding box and how accurate the decision is. In other words, it is the minimum score that the model will consider the prediction to be a true prediction. The output layer of the YOLOv2 network predicts refined bounding box locations by optimizing the mean squared error loss between predicted bounding boxes and the ground truth. The loss function consists of localization loss, confidence loss, and classification loss. The localization loss measures error between the predicted bounding box and the ground truth as follows:  
\[K_{1}\sum_{i=0}^{s^{2}}\sum_{j=0}^{B}1_{ij}^{obj}\Big{[}(x_{i}-\hat{x}_{i})^{2 }+(y_{i}-\hat{y}_{i})^{2}\Big{]}+K_{2}\sum_{i=0}^{s^{2}}\sum_{j=0}^{B}1_{ij}^{ obj}\Bigg{[}\Big{(}\sqrt{w_{i}}-\sqrt{\hat{w}_{i}}\Big{)}^{2}+\Big{(}\sqrt{h_{i}}- \sqrt{\hat{h}_{i}}\Big{)}^{2}\Bigg{]} \tag{5}\]  
where \(K_{1}\) is the weight for localization loss, \(S\) is the number of grid cells, \(B\) is the number of bounding boxes in each grid cell, \(1_{ij}^{obj}\) is 1 when the \(j\)th bounding box in grid cell \(i\) is responsible for detecting the object, otherwise it is set to 0, (\(x_{i}\), \(y_{i}\)) is the center of the \(j\)th bounding box relative to grid cell \(i\), (\(\hat{x}_{i}\), \(\hat{y}_{i}\)) is the center of the ground truth relative to grid cell \(i\), (\(w_{i}\), \(h_{i}\)) is the width and the height of the \(j\)th bounding box in grid cell \(i\), and (\(\hat{w}_{i}\), \(\hat{h}_{i}\)) is the width and the height of the ground truth in grid cell \(i\).  
The confidence loss computes the objectness (confidence score) error when the object is detected in the \(j\)th bounding box of the grid cell \(i\) with the following formula:  
\[K_{2}\sum_{i=0}^{S^{2}}\sum_{j=0}^{B}1_{ij}^{obj}\big{(}C_{i}-\hat{C}_{i}\big{)} ^{2}+K_{3}\sum_{i=0}^{S^{2}}\sum_{j=0}^{B}1_{ij}^{nobbj}\big{(}C_{i}-\hat{C}_ {i}\big{)}^{2} \tag{6}\]  
where \(K_{2}\) is the weight for the objectness error when an object is detected in the predicted bounding box, \(K_{3}\) is the weight for the objectness error when an object is not detected in the predicted bounding box, \(1_{ij}^{obj}\) is 1 when the \(j\)th bounding box in grid cell \(i\) is responsible for detecting the object, \(1_{ij}^{nobbj}\) is 1 when the \(j\)th bounding box in grid cell \(i\) does not contain any object, \(C_{i}\) is the confidence score of the \(j\)th bounding box in grid cell \(i\), and \(\hat{C}_{i}\) is the confidence score of the ground truth in grid cell \(i\).  
Figure 3: (**a**) Number of Anchors vs. Mean _IoU_; (**b**) 20 clustering anchor boxes.  
The classification loss measures the squared error between the class conditional probabilities for each class in grid cell \(i\). The classification loss is defined as:  
\[K_{4}\sum_{i=0}^{S^{2}}1_{ij}^{obj}\sum_{c\in\text{classes}}\left(p_{i}(c)-\hat{p }_{i}(c)\right)^{2} \tag{7}\]  
where \(K_{4}\) is the weight for the classification error when an object is detected in the grid cell, \(p_{i}(c)\) is the estimated conditional class probability for object class \(c\) in grid cell \(i\), and \(\hat{p}_{i}(c)\) is the actual conditional class probability for object class \(c\) in grid cell \(i\)[6].