[英]how do I implement ssim for loss function in keras?
I need SSIM as a loss function in my network, but my network has 2 outputs.我需要 SSIM 作为我网络中的损失函数,但我的网络有 2 个输出。 I need to use SSIM for first output and
cross-entropy
for the next.我需要将 SSIM 用于第一个输出,并为下一个输出使用
cross-entropy
。 The loss function is a combination of them.损失函数是它们的组合。 However, I need to have a higher SSIM and lower
cross-entropy
, so I think the combination of them isn't true.但是,我需要更高的 SSIM 和更低的
cross-entropy
,所以我认为它们的组合是不正确的。 Another problem is that I could not find an implementation of SSIM in keras.另一个问题是我在 keras 中找不到 SSIM 的实现。
Tensorflow has tf.image.ssim
, but it accepts the image and I do not think I can use it in loss function, right? Tensorflow 有
tf.image.ssim
,但它接受图像,我认为我不能在损失函数中使用它,对吧? Could you please tell me what should I do?你能告诉我我该怎么办吗? I am a beginner in keras and deep learning and I do not know how can I make SSIM as a custom loss function in keras.
我是 keras 和深度学习的初学者,我不知道如何将 SSIM 作为 keras 中的自定义损失函数。
other choice would be ssim_loss = 1 - tf.reduce_mean(tf.image.ssim(target, output, max_val=self.max_val))
其他选择是
ssim_loss = 1 - tf.reduce_mean(tf.image.ssim(target, output, max_val=self.max_val))
then combine_loss = mae (or mse) + ssim_loss
In this way, you are minimizing both of them.然后
combine_loss = mae (or mse) + ssim_loss
这样,你就最小化了它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.