本文介绍了在tensorflow中使用RGB图像的SSIM损失函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 SSIM指标作为我在 tensorflow 中正在研究的模型的损失函数. SSIM应该测量我的去噪自动编码器的重构输出图像与输入的未破坏图像(RGB)之间的相似性.

I want to use SSIM metric as my loss function for the model I'm working on in tensorflow. SSIM should measure the similarity between my reconstructed output image of my denoising autoencoder and the input uncorrupted image (RGB).

据我了解,为了在张量流中使用SSIM指标,图像应归一化为[0,1]或[0,255],而不是[-1,1].将张量转换为[0,1]并将SSIM作为损失函数实现后,重建的图像将是黑白图像,而不是彩色RGB图像.

As of what I understood, for using the SSIM metric in tensorflow, the images should be normalized to [0,1] or [0,255] and not [-1,1]. After converting my tensors to [0,1] and implementing SSIM as my loss function, the reconstructed image is black and white instead of a colorful RGB image.

tf.reduce_mean(tf.image.ssim(reconstructed, truth, 1.0))

我的模型在 MSE (均方误差)下工作正常,重建的图像是彩色(RGB).

My model is working fine with MSE (mean squared error), the reconstructed images are colorful (RGB).

使用tf.losses.mean_squared_error(truth, reconstructed)重建的图像将是RGB图像,而使用SSIM将给我一维图像.

using tf.losses.mean_squared_error(truth, reconstructed) the reconstructed image would be RGB image, while using SSIM would give me a one dimensional image.

为什么使用 SSIM作为损失函数在张量流中给我的结果与MSE 不同(在重建图像通道方面)?

Why using SSIM as loss function gives me different result than MSE (in terms of reconstructed image channels) in tensorflow?

推荐答案

我能够通过将图像的动态范围更改为 2.0 来解决此问题,因为我在 > [-1,1] 通过:

I was capable of solving the issue by changing the dynamic range of the images to 2.0, since I have images scaled between [-1, 1] by:

loss_rec = tf.reduce_mean(tf.image.ssim(truth, reconstructed, 2.0))

由于较高的 SSIM 值显示出更好的图像质量,因此我必须最小化损失函数(SSIM)的负数以优化模型:

And since a better image quality is shown by a higher SSIM value, I had to minimize the negative of my loss function (SSIM) to optimize my model:

optimizer = tf.train.AdamOptimizer(learning_rate).minimize(-1 * loss_rec)

这篇关于在tensorflow中使用RGB图像的SSIM损失函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 17:44