Implement details of dense depth paper
This commit is contained in:
26
losses.py
26
losses.py
@@ -2,21 +2,19 @@ import tensorflow as tf
|
||||
import tensorflow.keras.backend as K
|
||||
|
||||
|
||||
def dense_depth_loss_function(y_true, y_pred, theta=0.1, maxDepthVal=1000.0 / 10.0):
|
||||
# Point-wise depth
|
||||
l_depth = K.mean(K.abs(y_pred - y_true), axis=-1)
|
||||
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
|
||||
l_depth = K.mean(K.abs(y_pred - y), axis=-1)
|
||||
|
||||
# Edges
|
||||
dy_true, dx_true = tf.image.image_gradients(y_true)
|
||||
# L1 loss over image gradients
|
||||
dy, dx = tf.image.image_gradients(y)
|
||||
dy_pred, dx_pred = tf.image.image_gradients(y_pred)
|
||||
l_edges = K.mean(K.abs(dy_pred - dy_true) + K.abs(dx_pred - dx_true), axis=-1)
|
||||
l_grad = K.mean(K.abs(dy_pred - dy) + K.abs(dx_pred - dx), axis=-1)
|
||||
|
||||
# Structural similarity (SSIM) index
|
||||
l_ssim = K.clip((1 - tf.image.ssim(y_true, y_pred, maxDepthVal)) * 0.5, 0, 1)
|
||||
# Structural Similarity (SSIM)
|
||||
l_ssim = (1 - tf.image.ssim(y, y_pred, 500)) / 2
|
||||
|
||||
# Weights
|
||||
w1 = 1.0
|
||||
w2 = 1.0
|
||||
w3 = theta
|
||||
|
||||
return (w1 * l_ssim) + (w2 * K.mean(l_edges)) + (w3 * K.mean(l_depth))
|
||||
return 0.1 * K.mean(l_depth) + l_grad + l_ssim
|
||||
|
||||
Reference in New Issue
Block a user