assign device

This commit is contained in:
jh 2021-03-12 18:27:00 -08:00
commit beb8c30970

View file

@ -19,6 +19,15 @@ class MsSsim(nn.LayerBase):
# Transpose images from NCHW to NHWC
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])
def assign_device(op):
if op.type != 'Assert':
return '/gpu:0'
else:
return '/cpu:0'
with tf.device(assign_device):
loss = tf.image.ssim_multiscale(y_true_t, y_pred_t, max_val, power_factors=self.power_factors)
return (1.0 - loss) / 2.0