我想在我的tf模型中添加一个正则化损失,从而惩罚输入和中间表示之间的SSIM。我的代码在tensorflow 1.13.1中运行良好,但我今天升级到1.15,它不再工作
Tensorflow说我必须使用占位符。但是在哪里
我构建模型,然后添加我的损失:
class MS_SSIM:
# Input must be in range [0, max_value]
def __init__(self, max_value=1.0):
self.__name__ = 'MS_SSIM_Objective'
self.max_value = max_value
def __int_shape(self, x):
return tf.keras.backend.int_shape(x) if self.backend == 'tensorflow' else tf.keras.backend.shape(x)
def __call__(self, y_true, y_pred):
ms_ssim_val = tf.image.ssim_multiscale(y_true, y_pred, self.max_value)
return tf.keras.backend.mean(1.0 - ms_ssim_val)
loss = losses.MS_SSIM()
reconstructionLoss = 1e-6*loss(reconstruction.inputs[0], reconstruction.outputs[0])
model.add_loss(reconstructionLoss) # This is the line where it errors when using tf 1.14 and 1.5 but not 1.13.
我不知道在这里该怎么办。有什么想法吗
目前没有回答
相关问题 更多 >
编程相关推荐