21 lines
690 B
Python
21 lines
690 B
Python
import tensorflow as tf
|
|
|
|
|
|
def dense_depth_loss_function(y, y_pred):
|
|
"""
|
|
Implementation of the loss from the dense depth paper https://arxiv.org/pdf/1812.11941.pdf
|
|
"""
|
|
# Point-wise L1 loss
|
|
l1_depth = tf.reduce_mean(tf.math.abs(y_pred - y), axis=-1)
|
|
|
|
# L1 loss over image gradients
|
|
dy, dx = tf.image.image_gradients(y)
|
|
dy_pred, dx_pred = tf.image.image_gradients(y_pred)
|
|
gradient = tf.reduce_mean(tf.math.abs(dy_pred - dy) +
|
|
tf.math.abs(dx_pred - dx), axis=-1)
|
|
|
|
# Structural Similarity (SSIM)
|
|
ssim = (1 - tf.image.ssim(y, y_pred, 500)) / 2
|
|
|
|
return 0.1 * tf.reduce_mean(l1_depth) + tf.reduce_mean(gradient) + ssim
|