# A Remote Sensing Image Target Detection Algorithm Based on Improved YOLOv8
## 3 Improvement of YOLOv8
### Improvement of the Loss Function  
In the target detection task, the detection performance depends on the design of the loss function. The IoU loss function is used to measure the overlap between the prediction box derived from the detection and the ground-truth box. Its value ranges between 0 and 1; the closer to 1, the greater the difference between the prediction result and the ground-truth box, and vice-versa. The classical IoU loss function is schematized in Figure 5 and is calculated as follows:  
\[\text{IoU}=\frac{\left|\text{A}\cap\text{B}\right|}{\left|\text{A}\cup\text{B }\right|} \tag{1}\]  
\[\text{L}_{\text{IoU}}=1-\text{IoU} \tag{2}\]  
where A is the prediction-box size, and B is the ground-truth box size. In order to continuously improve the localization effect of the prediction box, in recent years, on the basis of the traditional IoU loss function, many new types of loss functions have been produced, such as GIoU, DIoU, CIoU, SIoU, and EIoU. The YOLOv8 network adopts CIoU, which, in contrast with the other loss functions mentioned above, considers the aspect ratio into the computation so that the localization effect of the prediction box is improved. The schematic of CIoU is shown in Figure 6.  
\[\text{L}_{\text{CIoU}}=1-\text{IoU}+\frac{\rho^{2}(\text{A},\text{B})}{\text{ c}^{2}}+\alpha\text{V} \tag{3}\]  
\[\text{V}=\frac{4}{\pi^{2}}(\arctan\frac{\text{w}_{\text{b}}}{\text{h}_{\text {b}}}-\arctan\frac{\text{w}_{\text{a}}}{\text{h}_{\text{a}}})^{2} \tag{4}\]  
\[\alpha=\frac{\text{V}}{(1-\text{I}_{\text{IoU}})+\text{V}} \tag{5}\]  
where \(\frac{\rho^{2}(\text{A},\text{B})}{\text{c}^{2}}+\alpha\text{V}\) is a penalty term to minimize the overfitting problem that occurs during model training, where \(\mathbf{c}\) is the distance between the geometric centers of the two boxes, \(\alpha\) is the weight function, and V is the aspect ratio similarity metric function. However, since the training data will inevitably contain some low-quality examples that are not accurately labeled, the CIoU in the original YOLOv8 network, which only considers geometric factors such as the center spacing of the two boxes and the aspect ratio, inevitably increases the penalty term's punishment for these low-quality examples, thus reducing the overall generalization performance of the model [20]. Therefore, a good loss function is needed to replace the CIoU to achieve the weakening of the influence brought about by geometric factors, then reduce its intervention in the training process when the prediction box matches well with the ground-truth box so that the model can obtain better generalization ability. Figure 5: Sketch map of IoU. In this paper, Wise-IoU is used to replace the CIoU in the original YOLOv8 network. Wise-IoU provides a more reasonable gradient gain assignment strategy, which reduces the competitiveness of high-quality examples in the gain assignment and, at the same time, reduces the deleterious gradient produced by low-quality examples so that Wise-IoU can act on the ordinary-quality examples in a more focused way, thus improving the generalization ability of the model [21]. Wise-IoU has three versions: Wise-IoUv1, Wise-IoUv2, and Wise-IoUv3. The schematic of WIoU is shown in Figure 7.  
\[\mathrm{L_{WIoUv1}}=\mathrm{R_{WIoU}}\mathrm{L_{IoU}} \tag{6}\]  
\[\mathrm{R_{WIoU}}=\mathrm{exp}(\frac{(\mathrm{x_{b}}-\mathrm{x_{a}})^{2}+( \mathrm{y_{b}}-\mathrm{y_{a}})^{2}}{W^{2}+\mathrm{H}^{2}}) \tag{7}\]  
where \(\mathrm{R_{WIoU}}\) takes values between 1 and e, which amplify \(\mathrm{L_{IoU}}\) for ordinary-quality anchor boxes, while \(\mathrm{L_{IoU}}\) takes values between 0 and 1, which reduce \(\mathrm{R_{WIoU}}\) for high-quality anchor boxes in such a way that accelerates the rate of convergence of the loss function without introducing new computational metrics such as aspect ratios. Wise-IoUv2 with monotonic focusing ability can be obtained by introducing the monotonic focusing mechanism for cross-entropy on the basis of Wise-IoUv1.