Skip to content

Instantly share code, notes, and snippets.

@Eligijus112
Created September 23, 2022 04:57
Show Gist options
  • Save Eligijus112/f574f7eb19a604c695435cf7fdba2a2d to your computer and use it in GitHub Desktop.
Save Eligijus112/f574f7eb19a604c695435cf7fdba2a2d to your computer and use it in GitHub Desktop.
Custom MSE loss for tensorflow
# Importing the package
import tensorflow as tf
class NMSE(tf.keras.losses.Loss):
def __init__(self):
super().__init__()
def call(self, y_true, y_pred):
# Calculating the mse;
# Adding an additional division by 2 to mimic sklearn
return tf.reduce_mean(tf.square(y_true - y_pred)) / 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment