Skip to content

Instantly share code, notes, and snippets.

@GeorgeSeif
Last active August 27, 2019 23:18
Show Gist options
  • Select an option

  • Save GeorgeSeif/03ee25ee927f6524fbb74904d6eeb3e4 to your computer and use it in GitHub Desktop.

Select an option

Save GeorgeSeif/03ee25ee927f6524fbb74904d6eeb3e4 to your computer and use it in GitHub Desktop.
import math
from keras import backend as K
# Define our custom metric
def PSNR(y_true, y_pred):
max_pixel = 1.0
return 10.0 * math.log10((max_pixel ** 2) / (K.mean(K.square(y_pred - y_true))))
# Define our custom loss function
def charbonnier(y_true, y_pred):
epsilon = 1e-3
error = y_true - y_pred
p = K.sqrt(K.square(error) + K.square(epsilon))
return K.mean(p)
# Compile our model
adam = Adam(lr=0.0001)
model.compile(loss=[charbonnier], metrics=[PSNR], optimizer=adam)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment