Created
February 12, 2018 21:34
-
-
Save benbotto/204707cd5562d107b4da3b76632467b1 to your computer and use it in GitHub Desktop.
huber_loss for Tensorflow Keras
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def huber_loss(y_true, y_pred, clip_delta=1.0): | |
error = y_true - y_pred | |
cond = tf.keras.backend.abs(error) < clip_delta | |
squared_loss = 0.5 * tf.keras.backend.square(error) | |
linear_loss = clip_delta * (tf.keras.backend.abs(error) - 0.5 * clip_delta) | |
loss = tf.where(cond, squared_loss, linear_loss) | |
return tf.keras.backend.mean(loss) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment