# Research on a UAV-View Object-Detection Method Based on YOLOv7-Tiny
## 3 UAV View Object-Detection Method Based on YOLOv7-Tiny
### The Improved YOLOv7-tiny Algorithm
#### 3.2.1. VarifocalLoss Loss Function  
The loss function in the YOLOv7-tiny algorithm is finely designed, including the classification loss (\(L_{cls}\)), the bounding box regression loss (\(L_{bbox}\)), and the object confidence loss (\(L_{obj}\)), in which the bounding box regression loss adopts the _CloU_ loss function. The _CloU_ loss function formula is as follows:  
\[L_{CloU}=1-IoU+\frac{\rho^{2}(b,u)}{c^{2}}+\alpha v \tag{1}\]  
In Equation (1), _IoU_ is the intersection and concatenation ratio, \(\rho(b,u)\) is the Euclidean distance between the centroid of the predicted frame \(b\) and the actual frame \(u\), \(c\) is the diagonal length of the smallest closed box that contains both frames, \(v\) is the consistency term of the aspect ratio, and \(\alpha\) is the weighting parameter.  
The _CloU_ loss is an improved IoU (Intersection and Ratio) loss that considers not only the overlapping area of the bounding box but also the distance from the center point of the bounding box, the aspect ratio, and the scale. This makes the _CloU_ loss perform better than the traditional IoU loss when dealing with the object-detection task, and significantly better when the scale and aspect ratios differ.  
However, despite improvements in geometric metrics, _CloU_ loss still faces certain limitations when dealing with highly dynamic aerial perspectives and complex multi-scale object-detection tasks. Particularly in severe object overlapping and occlusion cases, its performance may not be ideal [23]. This is mainly because _CloU_ loss still focuses on the physical properties of bounding boxes and cannot adequately address complexities caused by visual salience nor effectively distinguish between foreground and background in situations of extreme class imbalance.  
To better address these issues, this study introduces the VarifocalLoss loss function, which is a composite loss function that combines FocalLoss and cross-entropy loss and is formulated as  
\[L_{VF}(p_{t})=\alpha_{t}(1-p_{t})^{\gamma}log(p_{t})+\beta(1-\alpha_{t})p_{t}^ {k}(1-log(p_{t})) \tag{2}\]  
In Equation (2), \(p_{t}\) is the probability of the object category predicted by the model; \(\alpha_{t}\) is a balancing factor used to adjust for the effects of positive and negative samples; \(\gamma\) is used to reduce the contribution of easy-to-categorize samples to the loss function so that the model pays more attention to the difficult-to-categorize samples; and \(\beta\) and k are parameters used to adjust the weights of samples predicted positively, but with a low level of confidence.  
FocalLoss is mainly used to solve the class imbalance problem in classification problems by adjusting the focus parameter in the loss function to reduce the weight of easy-to-categorize samples and increase the influence of difficult-to-categorize samples. This makes the model pay more attention to the samples that are difficult to classify correctly during training. Combined with the cross-entropy loss, the classification accuracy is further optimized, especially when the background is complex, or the object categories are extremely unbalanced [24].  
In the whole algorithmic framework, the VarifocalLoss loss function plays a key optimization role, which adjusts the model's response to objects of different sizes and degrees of occlusion at the initial level, especially when working with the feature extraction network, and distinguishes the foreground from the background more accurately through a weighting mechanism, thus reducing false detections and improving the algorithm's ability to discriminate occluders. Applied to the task of object detection from the viewpoint of an uncrewed aerial vehicle (UAV), VarifocalLoss can effectively improve the detection of small objects and objects in complex backgrounds. Whether tiny objects in urban landscapes or dense trees and other obstacles in natural environments, the loss function helps the model to achieve higher detection accuracy and robustness in these challenging environments.