开始不知道这个张量如何输出,也不知道对错,引入v1的输出,v1的输出张量方法,注意:图片的分辨率要相同,要不然会报错
import tensorflow as tf
import numpy as np
tf.compat.v1.disable_eager_execution()
print(tf.version.VERSION)
# Read images from file.
im1 = tf.io.read_file("630.png")
im2 = tf.io.read_file("640.png")
img1 = tf.image.decode_png(im1)
img2 = tf.image.decode_png(im2)
#图片的分辨率要相同,要不然会报错
psnr1 = tf.image.psnr(img1, img2, max_val=255)
with tf.compat.v1.Session() as sess:
psnr = psnr1.eval()
print(psnr)
v2.3的输出方法,通过psnr1.numpy()就可以了,如果是两张相同的图片输出的会是inf
import tensorflow as tf
import numpy as np
print(tf.version.VERSION)
# Read images from file.
im1 = tf.io.read_file("630.png")
im2 = tf.io.read_file("640.png")
im3 = tf.io.read_file("650.png")
img1 = tf.image.decode_png(im1)
img2 = tf.image.decode_png(im2)
img3 = tf.image.decode_png(im3)
#图片的分辨率要相同,要不然会报错
psnr1 = tf.image.psnr(img1, img2, max_val=255)
print(psnr1.shape)
print(psnr1.dtype)
print(psnr1.numpy())
# print(psnr1.numpy())和下面代码输出结果相同
# tf.compat.v1.disable_eager_execution()
# with tf.compat.v1.Session() as sess:
# psnr = psnr1.eval()
# print(psnr)
im1 = tf.image.convert_image_dtype(img1, tf.float32)
im2 = tf.image.convert_image_dtype(img2, tf.float32)
psnr2 = tf.image.psnr(im1, im2, max_val=1.0)
print(psnr2.shape)
print(psnr2.dtype)
print(psnr2.numpy())
界面截图