## 2 Materials and Methods
### Framework of HM-YOLO
#### 2.3.4. Focaler-Shape-IoU Loss Function  
YOLOv8 originally used CIoU [25] as the loss function for bounding boxes, which performs well in box overlap, center distance, and shape similarity. However, it lacks sensitivity to small targets like strawberries and struggles with complex environments and sample imbalance. To address these issues, the Focaler-shape-IoU loss function combines Focaler-IoU and Shape-IoU to improve the level of sensitivity to small and irregular strawberry targets. Shape-IoU focuses on the impact of bounding box shape and scale, making it particularly well suited to address the diverse shapes of strawberries. By incorporating the actual shape and scale of the strawberries into the loss computation, it is better able to adapt to and recognize various shapes of strawberries, thereby improving both detection accuracy and recall. Shape-IoU is calculated as follows:  
\[IoU=\frac{\left|B\cap B^{st}\right|}{\left|B\cup B^{st}\right|} \tag{11}\]  
where \(IoU\) represents the ratio of the intersection area to the union area between the predicted bounding box and the ground truth bounding box. Here, \(B\) denotes the predicted box, and \(B^{st}\) denotes the ground truth box. Additionally, the weight coefficients for horizontal and vertical directions, \(ww\) and \(hh\), are introduced as follows:  
\[ww=\frac{2\times\left(w^{gt}\right)^{scale}}{\left(w^{gt}\right)^{scale}+\left( h^{gt}\right)^{scale}} \tag{12}\]  
\[hh=\frac{2\times\left(h^{gt}\right)^{scale}}{\left(w^{gt}\right)^{scale}+\left( h^{gt}\right)^{scale}} \tag{13}\]  
where the scale factor \(scale\) is closely related to the size of strawberries in the dataset. The weight coefficients for horizontal and vertical directions, \(ww\) and \(hh\), are adjusted according to the shape of the ground truth box. The distance cost is defined as follows:  
\[distance^{shape}=hh\times\left(x_{c}-x_{c}^{gt}\right)^{2}/c^{2}+ww\times \left(y_{c}-y_{c}^{gt}\right)^{2}/c^{2} \tag{14}\]  
where \(w_{w}\), \(w_{h}\), and \(\theta\) collectively define the shape cost, with the calculation process detailed in Equation (15). In this equation, the value of \(\theta\) is a crucial component, as it controls the degree of emphasis placed on the shape cost. \[\Omega^{shape}=\sum_{t=w,h}\left(1-e^{-w_{t}}\right)^{\theta},\theta=4 \tag{15}\]  
Figure 9: Dysample network structure. where \(w_{w}\) and \(w_{h}\) represent the ratios of the weighted differences in width and height, with the calculation formula provided in Equation (16). Here, \(w^{gt}\) and \(h^{gt}\) denote the width and height of the ground truth box, respectively. \[\left\{ \begin{array}{l}w_{w}=hh\times\frac{|w-w^{gt}|}{\max(w,w^{gt})}\\ w_{h}=ww\times\frac{|h-h^{gt}|}{\max(h,h^{gt})}\end{array} \right. \tag{16}\]  
The calculation expression for the Shape-IoU bounding box regression loss is given as follows:  
\[L_{Shape-IoU}=1-IoU+distance^{shape}+0.5\times\Omega^{shape} \tag{17}\]  
Focaler-IoU enhances the model's focus on difficult samples--such as occluded objects, small objects, or objects with similar backgrounds--by increasing their relative weight during training. This improves recognition accuracy for challenging samples and balances the model's attention by reducing the weight of easier ones, thereby enhancing generalization and robustness. The IoU loss is redefined by Focaler-IoU using a linear interval mapping method, as detailed below:  
\[IoU^{focaler}= \begin{cases}0,&IoU<d\\ \frac{IoU-d}{u-d},&d<<IoU<<u\\ 1,&IoU>u\end{cases}  \tag{18}\]  
where \(IoU^{focaler}\) represents the reconstructed Focaler-IoU, with \([d,u]\in[0,1]\). By adjusting the values of \(d\) and \(u\), Focaler-IoU can be effectively directed to focus on different regression samples.