# YOLO-PWSL-Enhanced Robotic Fish: An Integrated Object Detection System for Underwater Monitoring
## 2 Materials and Methods
### Yolo-Pwsl
#### 2.3.3. Wise-ShapeIoU Loss Function  
(1) ShapeIoU is an IoU calculation method based on the shape characteristics of the target for irregularly shaped targets [40]. The traditional IoU only considers the overlapping region of the bounding box and ignores the shape characteristics of the target, which may lead to inaccurate evaluation of irregularly shaped targets. In contrast, ShapeIoU introduces shape information based on the traditional IoU, which improves the consideration of the target shape and geometric structure and the accuracy of the bounding box regression. In the equations below, scale is the scaling factor, which is related to the size of the target in the dataset; \(ww\) and \(hh\) denote the weighting coefficients in the horizontal and vertical directions, respectively, and their values are related to the shapes of the GT boxes. Underwater fish populations are often irregular in shape and arrangement, and the  
Figure 7: LGFB structure. bounding box may cover multiple objects of different shapes, not just regular rectangles. With the traditional IoU loss function, it is difficult to obtain accurate matches for such irregular target shapes, whereas ShapeIoU can better deal with these irregular shapes and morphological changes, particularly, the complex structure of different individuals in a fish school, by considering the geometry of the target and the alignment of the bounding box. The formulas for ShapeIoU are as follows:  
\[ww=\frac{2\times\left(w\textsl{o}^{st}\right)^{scale}}{\left(w\textsl{o}^{ st}\right)^{scale}+\left(h\textsl{o}^{st}\right)^{scale}} \tag{6}\]  
\[hh=\frac{2\times\left(h\textsl{o}^{st}\right)^{scale}}{\left(w\textsl{o}^{ st}\right)^{scale}+\left(h\textsl{o}^{st}\right)^{scale}} \tag{7}\]  
\[distance^{shape}=hh\times\frac{\left(x_{c}-x_{c}\textsl{o}^{st}\right)^{2}}{ \textl{o}^{2}}+ww\times\frac{\left(y_{c}-y_{c}\textsl{o}^{st}\right)^{2}}{ \textl{o}^{2}} \tag{8}\]  
\[\Omega^{shape}=\sum_{t=w,h}\left(1-e^{-w_{t}}\right)^{\theta},\ \theta=4 \tag{9}\]  
\[L_{shape-IoU}=1-IoU+distance^{shape}+0.5\times\Omega^{shape} \tag{10}\]
2. Wise-IoU \[\text{Wise-IoU}\]  
Wise-IoU is a dynamic, non-monotonically focused IoU optimization method that improves evaluations in the presence of complex and inhomogeneous backgrounds [41]. Compared with the traditional IoUs, Wise-IoU improves the detection performance of the model in various complex scenarios by weighting different parts of the IoU and dynamically adjusting the weighting mechanism. In underwater environments, fish are often disturbed by factors such as water currents, light changes, and marine impurities, which may lead to complex background information. Individual fish sometimes obscure or overlap each other, which results in blurred boundaries between the targets. The Wise-IoU loss function can effectively address these challenges by increasing the focus on important regions (e.g., regions with more occlusion or overlap) based on the feedback of the model during the training process, which improves the accuracy of target detection in these complex background and occlusion situations. The formula for Wise-IoU is as follows:  
\[L_{WIoU1}=R_{WIoU}L_{IoU} \tag{11}\]  
\[R_{WIoU}=exp\left(\frac{\left(x-x_{gt}\right)^{2}+\left(y-y_{gt}\right)^{2}}{ \left(W_{\tilde{g}}^{2}+H_{\tilde{g}}^{2}\right)^{*}}\right) \tag{12}\]  
\[L_{WIoUv2}=L_{IoU}^{rs}L_{WIoUv1},\ r>0 \tag{13}\]  
\[ww=\frac{2\times\left(w\textsl{o}^{st}\right)^{scale}}{\left(w\textsl{o}^{ st}\right)^{scale}+\left(h\textsl{o}^{st}\right)^{scale}} \tag{6}\]0
3. Wise-ShapeIoU \[ww=\frac{2\times\left(w\textsl{o}^{st}\right)^{scale}}{\left(w\textsl{o}^{ st}\right)^{scale}+\left(h\textsl{o}^{st}\right)^{scale}} \tag{6}\]1  
Wise-ShapeIoU combines the weighting mechanism of Wise-IoU and the shape feature mechanism of ShapeIoU, thus further enhancing the ability to evaluate target detection performance. Underwater fish are usually densely distributed, and the targets are easily occluded from each other in varying amounts.