# SAR Image Aircraft Target Recognition Based on Improved YOLOv5
## 3 Materials and Methods
### Loss Function Update  
The loss function of YOLOv5's output terminal consists of three parts: classification loss, confidence loss, and bounding box loss. The bounding box loss adopts the CIOU loss function in the YOLOv5 network. The purpose of this is to make the predicted box closer to the ground truth box more quickly and accurately. The formula for CIOU loss is as follows:  
\[CIOU\_Loss=1-CIOU=1-IOU+\frac{\rho^{2}\big{(}b,bs^{t}\big{)}}{c^{2}}+\alpha \tag{7}\]  
where IOU represents the intersection over the union of loss between the predicted box and the ground truth box; \(c\) represents the diagonal length of the minimum outside rectangle of the predicted box and the ground truth box; \(\rho\) represents the Euclidean distance of the center point between the predicted box and the ground truth box; and \(v\) and \(\alpha\) are defined as follows:  
\[v=\frac{4}{\pi^{2}}\bigg{(}arctan\frac{ws^{t}}{hs^{t}}-arctan\frac{w}{h} \bigg{)}^{2} \tag{8}\]  
\[\alpha=\frac{v}{(1-IOU)+v} \tag{9}\]  
where \(w\) and \(h\) represent the width and height of the predicted box and \(ws^{t}\) and \(hs^{t}\) represent the width and height of the ground truth box, respectively. CIOU loss considers three factors, namely the overlapping area, the distance from the center point, and the aspect ratio, but it does not consider the mismatch angle between the predicted box and the ground truth box. Therefore, we introduce SIOU loss as the position loss function of the regression for the bounding box. The formula for SIOU loss is as follows:  
\[SIOU\_Loss=1-SIOU=1-IOU+\frac{\Omega+\Delta}{2} \tag{10}\]  
where \(\Omega\) represents the loss of shape, which is defined as follows:  
\[\Omega=\sum_{d=w,h}\big{(}1-e^{-\omega_{h}}\big{)}^{\theta} \tag{11}\]  
\[\omega_{w}=\frac{\left|w-w^{gt}\right|}{max(w,w^{gt})},\omega_{h}=\frac{\left| h-hs^{gt}\right|}{max(h,hs^{gt})} \tag{12}\]  
where \(\theta\) is an important parameter used to adjust the degree of attention to the loss of shape. The value of \(\theta\) was set as 4 in our experiment. Here, \(\triangle\) represents the loss of distance, which is defined as follows:  
\[\Delta=\sum_{d=x,y}\big{(}1-e^{-\gamma\rho_{t}}\big{)} \tag{13}\]  
\[\rho_{x}=\bigg{(}\frac{b_{cz}^{gt}-b_{cz}}{c_{w}}\bigg{)}^{2},\rho_{y}=\bigg{(} \frac{b_{cy}^{gt}-b_{cz}}{c_{h}}\bigg{)}^{2},\gamma=2-\Lambda \tag{14}\]  
where (\(b_{cz}\), \(b_{cz}\)) and (\(b_{cz}^{gt}\), \(b_{cz}^{gt}\)) represent the center coordinates of the predicted box and of the ground truth box, respectively; and \(c_{w}\) and \(c_{h}\) represent the width and height of the minimum outside rectangle of the predicted box and the ground truth box, respectively. \(\Lambda\) represents the angle loss factor, which is defined as follows:  
\[\Lambda=1-2\times sin^{2}\Big{(}\arcsin(x)-\frac{\pi}{4}\Big{)} \tag{15}\]  
\[x=\frac{c_{h}^{\prime}}{\sigma} \tag{16}\]  
\[\sigma=\sqrt{\Big{(}b_{c_{x}}^{gt}-b_{c_{x}}\Big{)}^{2}+\Big{(}b_{c_{y}}^{gt}-b _{c_{y}}\Big{)}^{2}} \tag{17}\]  
\[c_{h}^{\prime}=\max\Big{(}b_{c_{y}}^{gt},b_{c_{y}}\Big{)}-\min\Big{(}b_{c_{y}}^ {gt},b_{c_{y}}\Big{)} \tag{18}\]  
where \(\sigma\) represents the distance of the center point from both the predicted box and the ground truth box; and \(c_{h}^{\prime}\) represents the difference in the height of the center point between the predicted box and the ground truth box. SIOU redefines the loss function by introducing the angle loss factor, effectively reduces the degrees of freedom of the regression, accelerates the convergence of the network, and further improves the accuracy of detection.