I am trying to use SSIM as loss value for my Keras Sequential model. The output value is a set of 6 images - (6, 32, 28, 3). I want to implement a custom loss function for the model.fit() function but cannot understand how to implement this. I am attaching what I have tried before-

def ssim_loss(y_true, y_pred):
    return 1-tf.reduce_mean(tf.image.ssim_multiscale(y_true, y_pred, 2.0))
def ssim_loss(y_true, y_pred):
  loss = 0
  for i in range(6):
    loss += tf.reduce_mean(tf.image.ssim_multiscale(y_true[i], y_pred[i], 2.0))
  return loss

y_true shape is same as y_pred which I have checked. These both solutions do not work. I do not know how to access each element of y_pred. My input shape is - (6, 192, 56, 3). Please help. TIA


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.