## 2 Materials and Methods
### Camellia Oleifera Fruit Object Detection Algorithm
#### 2.3.6 Loss Function Improvement  
_Camellia oleifera_ fruit's precise position in the detection task is a key technology for harvest informatization, which usually uses bounding box regression for localization and a rectangular box to predict the location of the object in the image, and continuously adjusts the position and size of the rectangular predicted box to make it match the ground truth box more accurately. The whole process neural network needs to correct and refine the predicted box position by the loss function. The original YOLOv5s model uses the CIoU (complete intersection over union) loss function, which considers the distance between the center point of the ground truth box and the predicted box, and the diagonal distance of the minimum wrapped box of the two boxes, but it does not consider the angle between the ground truth box and the predicted box, which affects the regression accuracy. It is more complicated to measure the aspect ratio, which reduces the convergence speed, so the SIoU (Scylla intersection over union loss) loss function is introduced to the improved model [37; 38], adding the vector angle loss penalty term between the ground truth box and the predicted box. Finally, the loss function specifically includes angle loss, distance loss, shape loss, and intersection over union ratio (IoU) loss. Figure 7 shows a schematic diagram of the SIoU bounding box loss function. The angular loss \(\xi\) is defined in Equation (4). \[\xi=1-2\sin^{2}\Bigl{[}\sin^{-1}\Bigl{(}\frac{c_{h_{1}}}{\sigma}\Bigr{)}- \frac{\pi}{4}\Bigr{)}] \tag{4}\]  
Figure 6: Image of activation function and derivative function. Figure 7: Schematic diagram of SIoU bounding box loss function. \[c_{h_{1}}=\max\left(b_{c_{y}}^{gt},b_{c_{y}}\right)-\min\left(b_{c_{y}}^{gt},b_{c_{ y}}\right) \tag{5}\]  
\[\sigma=\sqrt{\left(b_{c_{x}}^{gt}-b_{c_{x}}\right)^{2}+\left(b_{c_{y}}^{gt}-b_{c _{y}}\right)^{2}} \tag{6}\]  
where \(c_{h_{1}}\), \(\sigma\) are the height difference and distance between the center point of the ground truth box and the predicted box, respectively; \(b_{c_{x}}\),\(b_{c_{y}}\) represent coordinates of the center point of the bounding box; and \(b_{c_{x}}^{gt}\),\(b_{c_{y}}^{gt}\) are coordinates of the center point of the ground truth box [39]. The angle loss calculation is applied to the distance loss calculation by redefining the distance loss \(\Delta\), as shown in Equation (7). \[ \begin{array}{c}\Delta=\sum\limits_{t=x,y}(1-e^{-\gamma p_{t}})\\ =2-e^{-(2-\xi)p_{x}}-e^{-(2-\xi)p_{y}}\\ =2-e^{-(2-\xi)\left(\frac{b_{c_{x}}^{gt}-b_{c_{y}}}{c_{w}}\right)^{2}}\\ \end{array}  \tag{7}\]  
where \(c_{w}\), \(c_{h}\) are the width and height of the minimum outer rectangle of the ground truth box and the predicted box, and \(\rho_{x}\), \(p_{y}\) are the distance loss. The shape loss is defined as \(\epsilon\) in Equation (8). \[ \begin{array}{c}\epsilon=\sum\limits_{t=w,h}(1-e^{-\omega_{t}})^{\theta}\\ =(1-e^{-\omega_{w}})^{\theta}+(1-e^{-\omega_{h}})^{\theta}\\ =(1-e^{-\frac{|w-b_{c}|}{\max(w,b_{c}|^{\theta})}})^{\theta}+(1-e^{-\frac{|w- b_{c}|}{\max(w,b_{c}|^{\theta})}})^{\theta}\end{array}  \tag{8}\]  
where (\(w\), \(h\)) and (\(w^{gt}\), \(h^{gt}\)) are the width and height of the ground truth box and the predicted box. The weight factor \(\theta\) controls the degree of attention to shape loss in the network model, to avoid too much attention to shape loss, and to reduce the movement of the predicted box, generally taking the best 4. The existing loss functions are based on additive implementation, and the principle of \(L_{i}=L_{IOU}+R_{i}\) is followed in constructing the penalty term, the final penalty term \(R_{i}\) contains the influence factors angle loss \(\xi\), distance loss \(\Delta\) and shape loss \(\epsilon\), and its bounding box regression loss function is calculated by Equation (9). \[ \begin{array}{c}L_{box}=L_{IOU}+R_{box}\\ =(1-IoU)+\frac{\Delta+\epsilon}{2}\end{array}