# An Oracle Bone Inscriptions Detection Algorithm Based on Improved YOLOv8
## 2 Materials and Methods
### The Proposed Method
#### 2.4.2 Improving the Loss Function  
The loss function for bbox (bounding box) regression is pivotal in achieving accurate object detection. By learning to predict the location of bboxes, the model can closely approximate true bounding boxes, providing precise localization and crucial information about key areas for detecting objects. YOLOv8_n uses CloU (Complete IoU) [21; 22] as its loss function for bbox regression, as shown in Formulas (5)-(8).  
\[L_{\text{IoU}}=1-\text{IoU} \tag{5}\]  
where IoU [23] denotes the intersection over the union between the predicted and ground-truth box.  
\[L_{\text{CIoU}}=L_{\text{IoU}}+\frac{\left(x_{p}-x_{gt}\right)^{2}+\left(y_{p }-y_{gt}\right)^{2}}{{W_{g}}^{2}+{H_{g}}^{2}}+\alpha\
u \tag{6}\]  
Figure 4: Improved YOLOv8_n network model.  
where \(\left(x_{p},y_{p}\right)\) and \(\left(x_{gt},y_{gt}\right)\) denote the central points of the prediction box and the ground-truth box, \(W_{g},H_{g}\) are the width and height of the smallest enclosing box covering the two boxes, \(\alpha\) is a positive trade-off parameter, and \(\
u\) measures the consistency of the aspect ratio.  
\[\
u=\frac{4}{\pi^{2}}\bigg{(}arctan\frac{w_{gt}}{h_{gt}}-arctan\frac{w_{p}}{h_{ p}}\bigg{)}^{2} \tag{7}\]  
The width and height of the ground-truth box are indicated by \(w_{gt}\) and \(h_{gt}\), where \(w_{p}\) and \(h_{p}\) stand for the width and height of the prediction box, respectively.  
\[\alpha=\frac{\
u}{L_{IoU}+\
u} \tag{8}\]  
As a result of the unavoidable presence of substandard instances within the training data, the penalty for low-quality examples can be augmented by considering factors, ultimately leading to a decline in the model's generalization capabilities. In addition, when the overlap between the predicted box and the ground-truth box is very small or non-existent, CIoU may not provide effective gradient information. To tackle these challenges, this study uses the WIoU loss function. WIoU is a type of boundary loss based on the non-monotonic dynamic focusing method that evaluates the anchor boxes' quality through outlier evaluation and offers a prudent strategy for allocating gradient gains. The proposed strategy effectively diminishes the competitiveness of superior-quality anchor boxes and simultaneously mitigates adverse gradients emanating from inferior examples. As a result, WIoU concentrates on moderate-quality anchor boxes, leading to an improvement in the detector's overall performance. The distance attention is shown in Formulas (9) and (10).  
\[L_{\text{WIoU}}=R_{\text{WIoU}}\cdot L_{\text{IoU}} \tag{9}\]  
\[R_{\text{WIoU}}=exp\left(\frac{\left(x_{p}-x_{gt}\right)^{2}+\left(y_{p}-y_{ gt}\right)^{2}}{\left(W_{g}^{2}+H_{g}^{2}\right)^{*}}\right) \tag{10}\]  
To avoid generalizing the gradients with WIoU, which could potentially hinder convergence, the computational graph does not include \(W_{g}\) or \(H_{g}\) (denoted by the superscript \(*\)). This effectively removes the convergence-hindering factor. Therefore, there is no need to introduce new metrics. When the anchor boxes align well with the target box, WIoU diminishes the penalty imposed by the geometric factors, thereby allowing for minimal intervention during training and enhancing the model's generalization capability.  
The primary step in implementing WIoU is computing the basic IoU value. Building on this, the final loss value is further refined by introducing distance attention mechanisms and dynamic adjustment factors. Subsequently, the obtained WIoU values are integrated into the loss function to replace the original CIoU loss component. During the model training phase, optimization adjustments are made based on the values of WIoU to more precisely calibrate the predicted bounding box positions and shapes.