# Focal Dice Loss-Based V-Net for Liver Segments Classification
## 2 Materials and Methods
### Convolutional Neural Network
#### 2.2.2 Focal Dice Loss  
After the introduction of the FL, [PERSON] et al. proposed the Focal Dice Loss (\(FDL\)) and effectively employed it for brain tumor segmentation [54]. The Dice coefficient (\(D_{H}\)) is usually defined for sets (let \(B\) be the binarized prediction and \(G\) the ground-truth volume) as:  
\[D_{H}=\frac{2\cdot|G\cap B|}{|G|+|B|} \tag{6}\]  
We define this as the \"hard\" Dice coefficient \(D_{H}\), in the sense that it is defined for binary data only. Let us consider the estimated probability predicted volume \(P\), composed of N voxels. Each element \(p_{i}\in P\) ranges in \([0,1]\), whereas each \(g_{i}\in G\) belongs to \(\{0,1\}\). Then, the \"soft\" Dice coefficient \(D_{S}\) can be defined as:  
\[D_{S}=\frac{2\sum_{i=1}^{N}p_{i}g_{i}+\epsilon}{\sum_{i=1}^{N}p_{i}+\sum_{i=1} ^{N}g_{i}+\epsilon} \tag{7}\]  
where \(\epsilon\) is a term for numerical stability, avoiding divisions by zero or by very small values. In our experiments, we set \(\epsilon=10^{-5}\). The \"hard\" Dice coefficient \(D_{H}\) is useful for assessing the final results, whereas the \"soft\" formulation \(D_{S}\) is needed during the optimization process, where a differentiable function is compulsory. Then, we can introduce a \"soft\" Dice coefficient loss \(DL_{S}\) simply as:  
\[DL_{S}=1-D_{S} \tag{8}\]  
These definitions hold for the binary classification case, but they can be easily generalized for \(t=1,\dots,k\) classes. For each value of \(t\), we can compute the binary \(DL_{S_{t}}\), so that the weighted multi-Dice loss (\(MDL_{S}\)) can be written as:  
\[MDL_{S}=\sum_{t=1}^{k}\omega_{t}DL_{S_{t}} \tag{9}\]  
where \(\omega_{t}\geq 0\) is the weighting parameter for the class \(t\) and \(DL_{S_{t}}\) is the binary soft Dice loss for class \(t\). A common way to tune the \(\omega_{t}\) parameters is to exploit the logarithm of the inverse class frequency, as reported in Table 1. Nonetheless, in our experiments, this did not result in improvements, so we chose the version with all \(\omega_{t}=1\), with \(t=1,\dots,k\). Starting from this definition, [PERSON] et al. defined their FDL as:  
\[FDL^{W}=\sum_{t=1}^{k}\omega_{t}(1-D_{S_{t}}^{\frac{1}{\gamma}}) \tag{10}\]  
where \(D_{S_{t}}\) is the \"soft\" Dice coefficient for class \(t\), and a factor \(\frac{1}{\gamma}\), with \(\gamma\geq 1\), is applied as the exponent of \(D_{S_{t}}\) for each class. According to [PERSON] et al., their \(FDL\) formulation has three properties:  
1. \(FDL\) is basically unaffected by pixels, which are misclassified to class \(t\) with a large \(D_{S_{t}}\). Conversely, \(FDL\) is significantly decreased when \(D_{S_{t}}\) is small;
2. The rate with which better-segmented classed are weighted lower is governed by the parameter \(\gamma\). For \(\gamma=1\), we have that \(FDL\) corresponds to \(MDL_{S}\). Increasing \(\gamma\), the network is forced to focus on classes with bad segmentation;
3. Since \(FDL\) is based on the definition of the Dice coefficient, it focuses on the relevant metric for assessing brain tumor segmentation (the case studied in [54]). In this paper, we defined two versions of the FDL. The first one is similar to the one proposed by [PERSON] et al. :  
\[FDL^{A}=\sum_{t=1}^{k}\omega_{t}(1-DL_{S_{t}})^{\gamma} \tag{11}\]  
with \(\gamma\geq 1\). The second one is based on the concept of the focal loss of [PERSON] et al. [55]. First, we define the \"soft\" Focal Dice Coefficient (FDC), which can be formulated as:  
\[FDC_{S_{t}}=\frac{2\sum_{i=1}^{N}p_{i}^{\gamma}S_{i}+\epsilon}{\sum_{i=1}^{N}p_{ i}^{\gamma}+\sum_{i=1}^{N}g_{i}+\epsilon} \tag{12}\]  
Then, we calculated the FDL as:  
\[FDL^{B}=\sum_{t=1}^{k}\omega_{t}(1-FDC_{S_{t}})=\sum_{t=1}^{k}\omega_{t}(FDL_{ t}) \tag{13}\]  
We excluded class \(t\) associated with the background, and we divided the sum in Equations (11) and (13) by \(k-1\). In our case, we note that the \(FDC_{S_{t}}\) numerator sums only the terms that have a \(g_{i}=1\).