File size: 387 Bytes
6fd61b9
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import tensorflow as tf
from tensorflow.keras import losses


class CharbonnierLoss(losses.Loss):
    def __init__(self, epsilon: float = 1e-3, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.epsilon = epsilon

    def call(self, y_true, y_pred):
        return tf.reduce_mean(
            tf.sqrt(tf.square(y_true - y_pred) + tf.square(self.epsilon))
        )