gpt4 book ai didi

python - Tensorflow read_file() 什么都不做

转载 作者:太空宇宙 更新时间:2023-11-03 13:27:30 25 4
gpt4 key购买 nike

我正在尝试使用 Tensorflow 读取和解码图像文件。我有以下代码:

dir_path = os.path.dirname(os.path.realpath(__file__))
filename = dir_path + '/images/cat/cat1.jpg'
image_file = tf.read_file(filename)
image_decoded = tf.image.decode_jpeg(image_file, channels=3)

print(image_file)
print(image_decoded)

这会产生以下输出:

Tensor("ReadFile:0", shape=(), dtype=string)
张量("DecodeJpeg:0", shape=(?, ?, 3), dtype=uint8)

Tensorflow 似乎根本没有读取该文件。但是我找不到任何表明出现问题的错误消息。我不知道如何解决这个问题,如有任何帮助,我们将不胜感激!

最佳答案

Tensorflow 创建一个计算图,然后对其进行评估。您在结果中看到的是创建的操作。您需要定义一个 Session 对象来获取您的操作结果。

dir_path = os.path.dirname(os.path.realpath(__file__))
filename = dir_path + '/images/cat/cat1.jpg'
image_file = tf.read_file(filename)
image_decoded = tf.image.decode_jpeg(image_file, channels=3)
with tf.Session() as sess:
f, img = sess.run([image_file, image_decoded])
print(f)
print(img)

看看这个 tensorflow帮助您进一步了解的资源!

关于python - Tensorflow read_file() 什么都不做,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52747947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com