# Segmentation of Preretinal Space in Optical Coherence Tomography Images Using Deep Neural Networks
## 5 Experiment Design
### Training
#### 5.1.1 Loss Function  
The training is aimed at minimizing a loss function \(L(I,\hat{I})\) between the arrays of ground truth \(I\) and prediction \(\hat{I}\). It is designed as a weighted sum of multi-class logistic loss (\(L_{log}\)) and Dice loss (\(L_{Dice}\)). The utilized loss function is implemented as it was proposed in the referenced and compared methods [35; 40] to sustain a consistency between each network architecture. The multi-class log loss, otherwise known also as Categorical Cross-Entropy, is a type of distribution-based criterion calculated as follows:  
\[L_{log}(I,\hat{I})=-\sum_{c\in C}\Bigg{(}\frac{1}{n_{c}}\sum_{x,y}\omega_{c}(x, y)\cdot I_{c}(x,y)\cdot\log(\hat{I}_{c}(x,y))\Bigg{)}, \tag{3}\]  
where \(I_{c}(x,y)\) is a binary ground truth mask for class \(c\in C=\{0,1,2,3\}\) taking value 0 or 1 at each location \((x,y)\), for \(x\in X=\{1,...,w\}\) and \(y\in Y=\{1,...,h\}\), where \(w\) and \(h\) denote the width and height of the image, respectively; \(\hat{I}_{c}(x,y)\) is the prediction probability of the pixel with indices \(x\) and \(y\) belonging to class \(c\); \(n_{c}\) is the number of pixels in a given class \(c\); and \(\omega_{c}(x,y)\) is an additional weight given to each pixel depending on its class and position within it.  
In detail, since the PCV line is very often on the level of noise in the image and due to OCT characteristics, the edges of the regions can be blurred. To boost the network's sensitivity to class boundaries, the pixels at the edges are given an additional weight \(q_{1}\). Furthermore, the pixels belonging to classes of interest (namely preretinal space and retina) are given an additional weight \(q_{2}\) to adjust for their lower area in the image (as opposed to the background). Equation (4) describes the overall pixel weight calculation:  
\[\omega_{c}(x,y)=1+q_{1}\cdot f(|\
abla_{y}I_{c}(x,y)|>0)+q_{2}\cdot f(I_{c}(x, y)_{|c=1,2}), \tag{4}\]  
where \(f(*)\) is an indicator function taking a value of one if the \((*)\) is true, and else zero. The \(\
abla_{y}\) operator represents the vertical gradient.  
The second component of the loss function is computed based on a Dice coefficient. The Dice as region-based metric measures the overlap of two regions according to the equation:  
\[Dice_{c}=\frac{2|I_{c}\cap\hat{I}_{c}|}{|I_{c}|+|\hat{I}_{c}|}, \tag{5}\]  
where \(|*|\) denotes a sum of pixels in the corresponding mask of ground-truth \(I_{c}\) and prediction \(\hat{I}_{c}\) for a class \(c\).  
Consequently, the Dice loss \(L_{Dice}\) takes into account the Dice scores for all the classes and can be expressed as follows:  
\[L_{Dice}(I,\hat{I})=1-\sum_{c\in C}\lambda_{c}Dice_{c}(I_{c},\hat{I}_{c}), \tag{6}\]  
where \(\lambda_{c}\) is a weight assigned to each class to compensate for their imbalance within the set. Numeric analysis of all the pixels in the dataset belonging to each class shows that the preretinal space is the most underrepresented class, while the background (vitreous region even more than the region below the retina) spans the largest area in each volume. We calculated the weights for each class as presented in Table 2 using the following equation:  
\[\lambda_{c}=\frac{\frac{1}{n_{c}}}{\sum_{c}\frac{1}{n_{c}}}, \tag{7}\]  
where \(n_{c}\) is the number of pixels belonging to the class \(c\in C\). All the weights sum up to 1, so that a maximum Dice score for all the classes would produce a Dice loss equal to 0, according to Equation (6).  
The overall loss function \(L(I,\hat{I})\), being a weighted sum of the above-described formulas, is calculated as follows:  
\[L(I,\hat{I})=\alpha L_{log}(I,\hat{I})+\beta L_{Dice}(I,\hat{I}), \tag{8}\]  
where \(\alpha\) and \(\beta\) are the weights assigned to each loss component. During the experiment, their values were empirically chosen as \(\alpha=1\) and \(\beta=0.5\). The parameters for pixel-wise weight in Equation (4) are also consistent with the compared methods: \(q_{1}=10\) and \(q_{2}=5\).