This commit is contained in:
jh 2021-03-12 18:11:05 -08:00
commit 6c42cd3a8f

View file

@ -17,8 +17,8 @@ class MsSsim(nn.LayerBase):
def __call__(self, y_true, y_pred, max_val):
# Transpose images from NCHW to NHWC
y_true_t = tf.transpose(tf.cast(y_true), [0, 2, 3, 1])
y_pred_t = tf.transpose(tf.cast(y_pred), [0, 2, 3, 1])
y_true_t = tf.transpose(tf.cast(y_true, tf.float32), [0, 2, 3, 1])
y_pred_t = tf.transpose(tf.cast(y_pred, tf.float32), [0, 2, 3, 1])
loss = tf.image.ssim_multiscale(y_true_t, y_pred_t, max_val, power_factors=self.power_factors)
return (1.0 - loss) / 2.0