Readers are not supported when eager execution is enabled

最近在复现tensorflow框架第二版代码的时候遇到了

Readers are not supported when eager execution is enabled. Instead, please use tf.data to get data into your model.

这个问题。

源码如下:

# 创建一个reader类读取TFRecord文件中的样例
reader = tf.TFRecordReader()

#创建一个队列来维护输入文件列表
filename_queue = tf.train.string_input_producer(["F:/anaconda/workspace/Data/output.tfrecords"])

# 从文件中读出一个样例,也可以用read_up_to函数一次性读取多个样例
_,serialized_example = reader.read(filename_queue)
#解析读入的一个样例,如果需要解析多个样例,也可以用parse_example函数
features = tf.parse_single_example(
           serialized_example,
           features = {
               'image_raw': tf.FixedLenFeature([],tf.string),
               'pixels': tf.FixedLenFeature([],tf.int64),
               'label': tf.FixedLenFeature([],tf.int64),
            })

# tf.decode_raw可以将字符串解析成图像对应的像素数组
image = tf.decode_raw(features['image_raw'],tf.uint8)
label = tf.cast(features['label'],tf.int32)
pixels = tf.cast(features['pixels'],tf.int32)

sess = tf.Session()
#启动多线程处理输入数据
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess = sess, coord = coord)

# 每次运行可读取TFReccord文件中的一个样例。当所有的样例都读完之后,在此样例中程序会再重头读取
for i in range(10):
    print(sess.run([image,label,pixels]))

看似毫无问题,但是运行起来就报错。

根据报错信息改成tf.data还是报错,后来没办法就在代码开头加了一句:

tf.compat.v1.disable_eager_execution() 

完美解决

 

多内容下载机器学习资料请扫描下方二维码关注小编公众号:程序员大管

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值