# Improved YOLOv7 Algorithm for Small Object Detection in Unmanned Aerial Vehicle Image Scenarios
## 3 Methodology
### Regression Loss SloU  
The overall loss (\(L_{\text{total}}\)) in the traditional YOLOv7 algorithm is defined by a weighted loss equation [24]:  
\[L_{\text{total}}=W_{1}\times L_{\text{box}}+W_{2}\times L_{\text{obj}}+W_{3} \times L_{\text{cls}} \tag{2}\]  
where \(L_{\text{box}}\), \(L_{\text{obj}}\), and \(L_{\text{cls}}\) denote the localization loss, confidence loss, and classification loss, respectively. \(W_{1}\), \(W_{2}\), and \(W_{3}\) represent the weight values assigned to these parameters, respectively.  
The CIoU function is responsible for calculating the coordinate regression loss function for the traditional YOLOv7 algorithm, which incorporates considerations of the overlap area, the length-width ratio and the distance between the ground-truth box and the prediction box [37]. In addition to the three factors mentioned above, the SIoU loss function includes an angle loss to speed up the training convergence process [38]. The SIoU regression loss function can be expressed as follows:  
\[L_{\text{box}}=1-\text{IoU}+\frac{\Delta+\Omega}{2} \tag{3}\]  
where \(\Omega\), IoU, and \(\Delta\) denote the shape loss, intersection-over-union loss, and distance loss, respectively.  
The IoU is calculated as the ratio of the intersection and union of the ground-truth box and prediction box, denoted by [38]  
\[\text{IoU}=\frac{B\bigcap B^{gt}}{B\bigcup B^{gt}} \tag{4}\]  
where \(B^{gt}\) and \(B\) denote the ground-truth box and the prediction box, respectively. The \(\bigcap\) and \(\bigcup\) operations are the intersection and union of the two boxes, respectively.  
The shape cost \(\Omega\) considers the relationship between the prediction box and the ground-truth box and is given by [38]  
\[\Omega=\left(1-e^{-\frac{\left|m-a\delta^{gt}\right|}{\max(y,n\delta^{gt})}} \right)^{\theta}+\left(1-e^{-\frac{\left|k-b\delta^{gt}\right|}{\max(y,n\delta ^{gt})}}\right)^{\theta} \tag{5}\]  
where \(w\) and \(w^{gt}\) denote the width of the prediction box and the ground-truth box, respectively. \(h\) and \(h^{gt}\) denote the heights of the prediction box and the ground-truth box, respectively. Moreover, \(\theta\) is an adjustable variable representing the weight of the network on the shape cost.  
The distance cost \(\Delta\) corresponds to the distance between the centers of two boxes, which is given by [38]  
\[\Delta=2-e^{(\Lambda-2)\times\left(\frac{C_{g}}{c_{g}}\right)^{2}}-e^{(\Lambda -2)\times\left(\frac{C_{g}}{c_{g}}\right)^{2}} \tag{6}\]  
where \(C_{g}\) and \(C_{g}\) denote the height and width of the rectangle constructed diagonally by connecting the center points of the ground-truth box and the prediction box, respectively. \(C_{g}\) and \(C_{g}\) denote the height and width of the minimum bounding rectangle of the two boxes, respectively.  
As shown in Figure 6, the angle loss \(\Lambda\) is introduced as a new factor in the SIoU regression loss function, which is expressed as follows [38]:  
\[\Lambda=1-2\sin^{2}\left(\arcsin(x)-\frac{\pi}{4}\right) \tag{7}\]  
\[x=\frac{C_{g}}{\sigma}=\sin(\alpha) \tag{8}\]where \(\sigma\) represents the distance between the centers of the ground-truth box and the prediction box. \(\alpha\) and \(\beta\) denote the included angles between the line connecting the centers of the two boxes and the x-axis and y-axis, respectively.  
The SIoU function has the capability to adjust the position of the prediction box toward the nearest axis by minimizing the angle \(\alpha\) or \(\beta\): i.e., \(\alpha\) is minimized if \(\alpha\leq 45^{\circ}\), and otherwise, \(\beta\) is minimized [38].