# Monocular Depth Estimation Using Res-UNet with an Attention Model
## 4 Results and Discussion
### Ablation Study
#### 4.5.2 Loss Function  
During training, we used different loss functions but the model did not converge. We used the depth loss function borrowed from [PERSON] and [PERSON] [9] and it returned very good results. Our model was trained with minimum loss and, on limited epochs, we achieved promising results. Our loss function has four parameters. The parameters are lambda, depth loss, depth gradient loss, and depth structural similarity loss. The depth loss measures the difference between the predicted and original depth maps. Depth gradient loss measures the gradient magnitude between the predicted depth image and the ground truth depth image. This loss encourages the model to produce images with similar gradient magnitudes. Similarly, structure similarity loss measures the similarity between the true and predicted depth maps. SSIM loss helps the model to predict depth maps which are structurally similar to the ground truth. All of the parameters are dependent on each other. We checked different combinations of these parameters, where only the cumulative results of these losses started to train our model. A brief summary of the experimentation of such losses is shown in Table 5 below.  
From the Table 5 we can see that all the loss parameters are highly dependent on each other. Even if we change one value, the model will not train properly. Hence, we used the combination of all parameters in our training loss with a lambda of 0.1 to achieve the best performance. The effect of lambda can also be seen in Figure 13.  
In depth maps, loss function plays a key role and proper attention should be given to it. Loss functions compares the actual or ground truth values to the predicted value. If the loss value is minimum, it means the model accurately created the depth map, and the model is learning in a right way. If the loss values are higher, it means the model did not detect the depth values correctly.  
Figure 13: Effect of lambda on predictions.  
\begin{table}
\begin{tabular}{c c c} \hline \hline
**Loss Functions** & **Training Loss** & **Output** \\ \hline \((y,y^{\prime})=0.1L_{depth}(y,y^{\prime})+L_{grad}(y,y^{\prime})+L_{ssim}(y,y^ {\prime})\) & 0.0094 & Model was trained to minimum loss \\ \hline \((y,y^{\prime})=0.2L_{depth}(y,y^{\prime})+L_{grad}(y,y^{\prime})+L_{ssim}(y,y^ {\prime})\) & 0.0251 & Model was trained to acceptable loss \\ \hline \((y,y^{\prime})=0.3L_{depth}(y,y^{\prime})+L_{grad}(y,y^{\prime})+L_{ssim}(y,y^ {\prime})\) & 0.0291 & Model was trained to acceptable loss \\ \hline \((y,y^{\prime})=0.1L_{depth}(y,y^{\prime})+L_{grad}(y,y^{\prime})\) & 0.0261 & Model failed at 4 th epoch \\ \hline \((y,y^{\prime})=0.1L_{depth}(y,y^{\prime})+L_{ssim}(y,y^{\prime})\) & 0.0557 & Model failed at 6 th epoch \\ \hline \((y,y^{\prime})=L_{grad}(y,y^{\prime})+L_{ssim}(y,y^{\prime})\) & 0.0207 & Model failed at 2 nd epoch \\ \hline \((y,y^{\prime})=0.1L_{depth}(y,y^{\prime})\) & 0.096 & Model failed at 1 st epoch \\ \hline \hline \end{tabular}
\end{table}
Table 5: Effect of change in loss parameters on model training.  
Sometimes the loss metric gives larger errors for larger depths. By larger depths, we mean that the model detects the far pixels incorrectly. Most of the time, this can be allowed for far objects, but for near objects with smaller depths if the error is more, it could be catastrophic. For example, in autonomous cars, if the depth is 70 m and the prediction is 65 m, this can be allowed, as the obstacle is far from a car; however, for near objects if the loss is more, this is not allowed because the car is already near to the obstacle. Therefore, the network loss metric should focus on the weights for smaller depths, such that the close predictions could be estimated more accurately.