## 3 Methods
### Dynamic Adaptive Focal Loss  
In instance segmentation models, Focal Loss [32] is commonly used as the classification loss. Focal Loss is a loss function designed to improve the performance of classification models when dealing with highly imbalanced datasets. The formula for Focal Loss is as follows:  
\[FL(p_{t})=-\alpha_{t}*(1-p_{t})^{\gamma_{t}}*log(p_{t}) \tag{17}\]  
Here, \(p_{t}\) is the predicted probability for the true class, \(\alpha_{t}\) is a weighting factor that balances the impact of positive and negative samples, and \(\gamma_{t}\) is a tuning factor that controls the weight assigned to hard-to-classify samples. Although Focal Loss can enhance classification accuracy in situations with class imbalance, it presents certain challenges in practical applications. Focal Loss uses fixed \(\alpha_{t}\) and \(\gamma_{t}\) coefficients during training. Even though these parameters may be optimized prior to training, they remain unchanged throughout the entire process. As a result, Focal Loss is unable to dynamically adjust its parameters in response to varying sample distributions in each training batch. This static parameter configuration may lead to insufficient focus on hard-to-classify samples in some batches or excessive emphasis on easy-to-classify samples, thereby limiting the model's ability to handle data imbalance effectively. In underwater environments, the presence of large schools of fish often gathering around coral reefs results in a much higher number of images of marine life compared to other categories. This data imbalance causes the model to be biased towards frequently appearing categories during training while neglecting fewer common objects, thereby affecting the overall performance of the segmentation algorithm. To address this issue, we propose the Dynamic Adaptive Focal Loss (DAFL) method. DAFL introduces label smoothing and dynamically adjusts the \(\alpha_{t}\) and \(\gamma_{t}\) parameters, enabling the model to adaptively adjust its focus on hard-to-classify samples across different training batches. This dynamic adjustment mechanism not only further mitigates the impact of class imbalance on model performance but also improves segmentation accuracy on extremely imbalanced datasets. The label smoothing is applied to the true label y, defined as  
\[y_{smooth}=y\times(1-\epsilon)+\frac{\epsilon}{2} \tag{18}\]  
where \(y\) is the true label, taking values of 0 or 1, indicating whether the sample belongs to a given class. \(\epsilon\) is the smoothing coefficient. The purpose of label smoothing is to prevent the model from becoming overly confident in the training data, thereby improving generalization. Next, based on the smoothed label \(y_{smooth}\), we calculate the global mean of the labels, denoted as \(y_{smooth}\). The smoothed label \(y_{smooth}\) is a three-dimensional tensor, consistingof batch size, number of samples, and number of classes. To compute the mean, these dimensions are flattened into a one-dimensional vector, where the total number n is the product of these three dimensions:  
\[n=B\times S\times C \tag{19}\]  
where \(B\) is the batch size, \(S\) is the number of samples, and \(C\) is the number of classes. Then, the global mean of the smoothed labels is calculated:  
\[y_{smooth}=\frac{1}{n}\sum_{i=1}^{n}y_{smooth,i} \tag{20}\]  
This mean reflects the class distribution in the current training batch, helping to capture the balance between all classes and mitigate the impact of class imbalance. It also provides insights into the ratio of positive and negative samples and the difficulty of classification. Subsequently, we dynamically adjust the parameter \(\alpha\) as follows:  
\[\alpha_{t}^{\prime}=\alpha_{initial}\times\overline{y}_{smooth}+(1-\overline {y}_{smooth})\times(1-\alpha_{initial}) \tag{21}\]  
In this equation, \(\overline{y}_{smooth}\) represents the proportion of positive samples.