python语言tensorflow2.3的psnr测试

开始不知道这个张量如何输出,也不知道对错,引入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())

界面截图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

花开花落的个人博客

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值