## 3 Materials and Methods
### Overview of the Proposed Approach
#### 3.1.2 Loss Function and Optimizer  
The loss function and optimizer represent key factors in model optimization and convergence. The loss function measures the model's performance through the training epochs while the optimizer adjusts the model parameters to minimize or maximize the loss function.  
The segmentation task in MRI images presents a class imbalance problem since the target objects to be segmented in the images, also known as foreground, usually occupy fewer pixels than the non-target objects or background. The class imbalance directly impacts the performance of the optimizer loss function of a model.  
Regarding the optimizer, the Stochastic Gradient Descent (SGD) method has been widely employed as a usual optimizer for training neural network models. However, this optimizer has been demonstrated to lead to poor results when the tasks involve data imbalance [30]. Therefore, the optimizer employed for training the model was the Adaptive Moment Estimation with Weight Decay (AdamW) [31]. The AdamW optimizer computes the gradients' first and second-order moments to adapt the parameters' learning rate. Then, the \(L_{2}\) regularization is used to avoid overfitting. These features allow fast training compared with other commonly used optimizers, such as SGD.  
Concerning the loss function, the proposed model was trained using the Generalized Dice Focal Loss (GDFL) function, which uses Generalized Dice Loss (GDL) and Focal Loss (FL), as described below.  
The GDL function is an extension of Dice Loss (DL), which considers the Dice Coefficient to evaluate the similitude of two sets. In binary labeling, DL considers the True Positives (TP), False Positives (FP), and False Negatives (FN) computed from the confusion matrix built with the label predictions of the model and the reference label map known as ground truth. This loss function is defined as follows [32]:  
\[\mathfrak{L}_{DL}=1-\frac{2\text{TP}}{2\text{TP}+\text{FP}+\text{FN}}. \tag{1}\]  
In segmentation tasks where the area sizes of the background and foreground classes are considerably different, the subrepresented class has less influence on the computation of  
Figure 1: Scheme of the proposed model.  
\(\mathfrak{L}_{DL}\). Therefore, the GDL includes weights based on the frequency of the classes to mitigate the class imbalance [33]:  
\[\mathfrak{L}_{GDL}=1-2\frac{\sum_{c=1}^{2}\omega_{c}\sum_{n=1}^{N}p_{n,c}g_{n,c}} {\sum_{c=1}^{2}\omega_{c}\sum_{n=1}^{N}(p_{n,c}+g_{n,c})}, \tag{2}\]  
where \(p_{n,c}\) represents the probability of the pixel \(n\) to belong to class \(c\), \(g_{n,c}\) is the binary value of the pixel \(n\) in the ground truth map for class \(c\), and \(\omega_{c}\) is a weight given to the class \(c\) calculated as:  
\[\omega_{c}=\frac{1}{\left(\sum_{n=1}^{N}g_{n,c}\right)^{2}}. \tag{3}\]  
Another function that considers the class imbalance is the FL. The FL function is based on the Balance Cross Entropy (BCE), which uses the class frequency. The class imbalance generated from easily classified background pixels in the segmentation task is addressed by a modulating factor that depends on a focusing parameter \(\gamma\). This parameter aids in the reduction of the contribution to the loss function of samples that are easy to classify. The FL function is defined as [34]:  
\[\mathfrak{L}_{FL}=-\alpha(1-q)^{\gamma}\log(q), \tag{4}\]  
\[q=\begin{cases}\hat{p}&\text{if }g=1,\\ 1-\hat{p}&\text{if }g=0,\end{cases} \tag{5}\]  
where \(\hat{p}\) is the estimated probability for the foreground class resulting from the model output and \(\alpha\) is a weight factor to balance the class contribution.  
The GDFL function addresses the class imbalance using GDL and focuses more on challenging samples to classify by utilizing FL. Given \(\lambda_{GDL}\) and \(\lambda_{FL}\) to ponderate GDL and FL, the loss function combines \(\mathfrak{L}_{GDL}\) and \(\mathfrak{L}_{FL}\) by summing the weighting loss functions as follows:  
\[\mathfrak{L}_{GDFL}=\lambda_{GDL}\mathfrak{L}_{GDL}+\lambda_{FL}\mathfrak{L}_ {FL}. \tag{6}\]