# UAV Image Small Object Detection Based on RSAD Algorithm
## 3 Proposed Method
### Loss Function  
Since small objects in UAV images occupy fewer pixels and contribute less to the loss function, it leads to insufficient attention to small objects in the training phase of the algorithm, which in turn leads to poor overall detection accuracy of the trained model for small objects in UAV images. In order to solve such problems, the Focal Loss has been proposed and achieved certain effects [43]. The Focal Loss can increase the importance of small objects in the loss function by increasing the value of the modulation coefficient \(\gamma\), increasing the algorithm's focus on small objects in the training phase, thus improving the model's detection accuracy of small objects, the focus loss function formula is as follows:  
\[FL(p_{t})=-\alpha_{t}(1-p_{t})^{\gamma}\text{log}(p_{t}) \tag{8}\]  
In the formula, \(FL(p_{t})\) is the Focal Loss function, \(\alpha_{t}\) is a decimal between 0 and 1, which is used as a weight to adjust the proportion of positive and negative samples, \(p_{t}\) represents the classification probabilities of the different classes, and \(\gamma\) ranging from 0 to 5, which is used to adjust the rate at which the weights of the samples are easily divided. In the case of imbalance between the positive and negative samples, the weight factor \(\alpha_{t}\), which affects the proportion of the positive and negative samples contributing to the loss function, can be set flexibly according to the data set. On the other hand, when the difficult and easy samples are unbalanced, the \(\gamma\) can be adjusted so as to reduce the contribution of the easy-to-categorize samples to the loss function, which makes the model training more focused on the difficult-to-categorize samples. When the authors proposed and analyzed the Focal Loss function in the study, it was based on binary classification, and Equation (8) was also derived based on binary classification. In this study, when object detection is carried out, it is a multiclassification case, so Equation (8) can be changed to Equation (9):  
\[FL(p_{c})=-\alpha_{c}(1-p_{c})^{\gamma}\text{log}(p_{c}) \tag{9}\]  
where: \(c\) denotes the category and the other parameters are the same as in Equation (8). Equation (9) is only applied on classification, for the localisation loss which is also known as IoU loss. The localisation loss in SSD will be followed and the formula is as follows:  
\[L_{loc}(x,l,g)=\sum_{i\in Pos,m\in\{cx,cy,w,h\}}^{N}\sum x_{ij}^{k}smooth_{L1} \left(l_{i}^{m}-\hat{g}_{j}^{m}\right) \tag{10}\]  
where \(Pos\) stands for position, \(N\) represents the number of prediction boxes; \(m\) for centroid coordinates and width and height of the surrounding box; \(x_{ij}^{k}\) for whether the \(i\)th prediction box matches the \(j\)th real box with respect to category \(k\): 0, 1; \(l_{i}^{m}\) stands for centroid coordinates and width and height information of the \(i\)th prediction box, \(\hat{g}_{j}^{m}\) stands for centroid coordinates and width and height information of the \(i\)th real box. The difference between the prediction boxes and the ground truth boxes is smoothed by smoothL1 after the difference between the prediction boxes and the ground truth boxes has been determined. This allows the loss to be more stable and not deviate from it along with the anomalous values, reducing the sensitivity of the loss to those values. Since \(\gamma\) dominates in Focal Loss. So, we set \(\alpha_{c}\) to the default value of 0.25. For the determination of the value of \(\gamma\), we did a pre-experiment with a small number of iterations on the VisDrone dataset. We set \(\gamma\) to 0, 1, 2, 3, 4, 5, and other parameters are the same as SSD, and performed 1000 iterations of the experiment to obtain the detection accuracy of various classes, respectively (Figure 6). It can be observed from Figure 6 that after 1000 iterations, the model has a slight ability to detect different kinds of detection targets. When the value of \(\gamma\) is 3, the model has outstanding detection ability for each kind.