为了账号安全,请及时绑定邮箱和手机立即绑定

Tensorflow read_file() 什么都不做

Tensorflow read_file() 什么都不做

慕侠2389804 2021-07-09 04:32:48
我正在尝试使用 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)Tensor("DecodeJpeg:0", shape=(?, ?, 3), dtype=uint8)看起来好像 Tensorflow 根本没有读取该文件。但是,我找不到任何表明出现问题的错误消息。我不知道如何解决这个问题,任何帮助将不胜感激!
查看完整描述

2 回答

?
拉莫斯之舞

TA贡献1820条经验 获得超10个赞

当我们第一次尝试使用 Tensorflow 时,这是一个很大的障碍。


现在,Tensorflow 团队已经做出了解决方案。


import tensorflow as tf

tf.enable_eager_execution()

在程序的最开始运行以上两行。


然后您的打印功能将产生如下所示的内容。


<tf.Tensor: id=15, shape=(), dtype=string, numpy=b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\

<tf.Tensor: id=17, shape=(747, 1024, 3), dtype=uint8, numpy=

array([[[ 0,  0,  0],

        [ 0,  0, 

Tensorflow 团队称之为急切执行。现在我们不需要运行 tf.Session 来查看张量里面有什么。


查看完整回答
反对 回复 2021-07-13
  • 2 回答
  • 0 关注
  • 216 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信