我正在尝试使用 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)
Run Code Online (Sandbox Code Playgroud)
这导致以下输出:
Tensor("ReadFile:0", shape=(), dtype=string)
Tensor("DecodeJpeg:0", shape=(?, ?, 3), dtype=uint8)
看起来好像 Tensorflow 根本没有读取该文件。但是,我找不到任何表明出现问题的错误消息。我不知道如何解决这个问题,任何帮助将不胜感激!
小智 5
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)
Run Code Online (Sandbox Code Playgroud)
查看此tensorflow资源以帮助您进一步了解!
归档时间: |
|
查看次数: |
4510 次 |
最近记录: |