## 2 Materials and Methods
### Cotton-YOLO Structure
#### 2.3.4 Improved Loss Function
When the target and prediction boxes overlap within a specific range, reducing the penalty on geometric metrics facilitates better model generalization. The formulas for calculating _WIoU_\(v1\) are presented in Equations (19) to (21). \[L_{WIoUv1}\ =\ R_{WIoU}\times L_{IoU} \tag{21}\]  
\[R_{WIoU}\ =\ exp\left(\frac{\left(b_{c_{x}}^{gt}-b_{c_{x}}\right)^{2}+\left(b_{c_{ y}}^{gt}-b_{c_{y}}\right)^{2}}{\left(c_{w}{}^{2}+{c_{h}}^{2}\right)}\right) \tag{22}\]  
\[L_{IoU}=1-IoU \tag{23}\]  
By constructing a monotonic focusing coefficient \(L_{IoU}^{*}\), _WIoU_\(v1\) is integrated into _WIoU_\(v2\), effectively reducing the weight of simple examples in the loss value. However, given that \(L_{IoU}^{*}\) decreases as \(L_{IoU}\) decreases during the model training process, representing a factor that contributes to slower convergence rates, the average value of \(L_{IoU}\) is introduced to normalize \(L_{IoU}^{*}\). The calculation formula for _WIoU_\(v2\) is presented in Equation (24). \[L_{WIoUv2}=\left(\frac{L_{IoU}^{*}}{L_{IoU}}\right)^{\gamma}\times L_{WIoUv1},\gamma>0 \tag{24}\]  
_WIoU_\(v3\) defines the outlier \(\beta\) to assess the quality of anchor boxes and constructs a non-monotonic focusing factor \(r\), which is incorporated into _WIoU_\(v1\). The smaller the \(\beta\) value is, the higher the anchor box quality. Conversely, the smaller the \(r\) value is, the less significant the weight of high-quality anchor boxes within a broader loss function. Larger \(\beta\) values denote poorer anchor box quality, resulting in reduced gradient gains assigned to these, thereby diminishing the detrimental gradients generated by low-quality anchor boxes. _WIoU_\(v3\) employs a well-calibrated gradient gain distribution strategy to dynamically adjust the weights of high-quality and low-quality anchor boxes in the loss, thereby shifting the model's focus towards average quality samples and enhancing overall performance. The formulas for _WIoU_\(v3\) are presented in Equations (25)-(27). The variables \(\beta\) and \(r\) in Equation (26) are adjustable hyperparameters, enabling adaptation to various models. \[L_{WIoUv3}=r\times L_{WIoUv1} \tag{25}\]  
\[L_{CloU}=1-IoU+\frac{\rho^{2}\big{(}b,b^{gt}\big{)}}{\left(c_{\omega}\right)^{ 2}+\left(c_{h}\right)^{2}}+\frac{4}{\pi^{2}}\left(tan^{-1}\frac{\omega^{gt}}{ h^{gt}}-tan^{-1}\frac{\omega}{h}\right) \tag{19}\]0  
\[L_{CloU}=1-IoU+\frac{\rho^{2}\big{(}b,b^{gt}\big{)}}{\left(c_{\omega}\right)^{ 2}+\left(c_{h}\right)^{2}}+\frac{4}{\pi^{2}}\left(tan^{-1}\frac{\omega^{gt}}{ h^{gt}}-tan^{-1}\frac{\omega}{h}\right) \tag{19}\]1  
Comparison of the aforementioned mainstream loss functions reveals that _WIoU_\(v3\) has significant advantages in target boundary box regression loss. Consequently, _WIoU_\(v3\) is chosen for introduction. First, _WIoU_\(v3\) integrates some advantages of _EIoU_ and _SIoU_, aligning with the design philosophy of a superior loss function. Secondly, _WIoU_\(v3\) employs a dynamic non-monotonic mechanism to evaluate the quality of anchor boxes, enabling the model to focus more on anchor boxes of average quality and enhancing the model's object localization capability. For the detection task of cotton bolls in complex environments, the presence of small cotton bolls complicates detection. _WIoU_\(v3\) dynamically optimizes the loss weights of small objects, thereby improving the model's detection performance.