# Automobile Fine-Grained Detection Algorithm Based on Multi-Improved YOLOv3 in Smart Streetlights
## 3 Methodology
### Introduction of YOLOv3
Therefore, in YOLOv3, the lattices of all real-value tags and current predicted value are used to calculate the IoU, and the highest one is used as the final IoU of this lattice to participate in the subsequent operation. To sum up, the loss function of YOLOv3 is as shown in the following Formula (2):  
\[\textit{loss}=\textit{loss}_{\textit{scale1}}+\textit{loss}_{\textit{scale2} }+\textit{loss}_{\textit{scale3}} \tag{2}\]  
Because the loss functions under various scales are very similar, this paper only provides the loss function of one scale. The loss function of Scale I is as shown in Formula (3):  
\[ \begin{array}{l}\textit{loss}_{\textit{scale1}}=\sum\limits_{i=0}^{S_{1}^{ 2}}\sum\limits_{j=0}^{B}a_{ij}l_{ij}^{obj}\Big{[}(x_{i}-\hat{x}_{i})^{2}+(y_{i} -\hat{y}_{i})^{2}\Big{]}+\\ \sum\limits_{i=0}^{S_{1}^{2}}\sum\limits_{j=0}^{B}a_{ij}l_{ij}^{obj}\Big{[}(w _{i}-\hat{w}_{i})^{2}+\Big{(}h_{i}-\hat{h}_{i}\Big{)}^{2}\Big{]}+\\ \sum\limits_{i=0}^{S_{1}^{2}}\sum\limits_{j=0}^{B}l_{ij}^{obj}\Big{(}C_{i}- \hat{C}_{i}\Big{)}^{2}+\sum\limits_{i=0}^{S_{2}^{2}}\sum\limits_{j=0}^{B}\hat {g}_{ij}l_{ij}^{\textit{noobj}}\Big{(}C_{i}-\hat{C}_{i}\Big{)}^{2}+\\ \sum\limits_{i=0}^{S_{1}^{2}}\sum\limits_{j=0}^{B}l_{ij}^{obj}\sum\limits_{ \textit{cc}\textit{classes}}\Big{(}p_{ij}(c)-\hat{p}_{ij}(c)\Big{)}^{2}\end{array}  \tag{3}\]  
where \(S_{1}^{2}\) refers to the number of lattices in the first scale and \(B\) represents the number of anchors under each scale, or the maximum number of lattices predicted by each lattice under each scale. In YOLOv3, \(B\) is set at 3; \(a_{ij}\) refers to the scale factor corresponding to the \(j\)th prediction of the \(i\)th bounding box; as mentioned above, each lattice will predict three bounding boxes, \(l_{ij}^{obj}\) represents that the object is in the \(j\)th prediction box of the \(i\)th lattice, while \(l_{ij}^{\textit{noobj}}\) indicates that the object is not in the \(j\)th prediction box of the \(i\)th lattice; \((x,y,w,h,C,p)\) is the true value, and \((\hat{x},\hat{y},\hat{w},\hat{h},\hat{C},\hat{p})\) is the predicted value of the model. The third line represents the confidence error. The confidence error consists of two parts: one type is the lattice with true value and target, and it only requires calculating the error between the corresponding positions of predicted value and true value in a normal way; the other type is the lattice with the true value but without the target; in this case, the predicted value of the confidence in corresponding position might be too high, and we need to determine whether such a high predicted value of confidence is normal. As mentioned above, current lattices with high predicted values and the IoUs of all real-value bounding boxes need to be calculated, so as to determine whether the lattice with high predicted confidence is close to a certain real-value bounding box. If it is close, it does not need to calculate the loss of the current lattice; otherwise, it requires calculating the loss. In this process, \(\beta_{\tilde{\mathfrak{ij}}}\) indicates whether it requires calculating the loss of current lattice. If the ignore thresh is T, the computation formula of \(\beta_{\tilde{\mathfrak{ij}}}\) is as shown in Formula (4). \[\beta_{\tilde{\mathfrak{ij}}}= \begin{cases}0&\textit{IoU}(\textit{ pred},\textit{true})>\text{T}\\ 1&\text{else}\end{cases}  \tag{4}\]  
The fourth line shows the class error. Because the calculation of class error is only meaningful when there is a target, this line also uses \(l_{ij}^{obj}\) to filter out the lattices without a target, and it only calculates the loss between lattices with targets. To sum up, YOLOv3 still uses the L2 distance massively during loss calculation. In position calculation, although the scale factor \(\alpha\) is used to balance the influence of object loss with different scales, this influence still cannot be completely eliminated, which will cause negative influence on the optimization of the network.