我试图让一个非常简单的TFRecord阅读器工作,但无济于事。 (我可以让作家工作得很好)。
在this github repo中,有一个reader.py
文件,看起来像这样:
import tensorflow as tf
import numpy as np
import time
from PIL import Image
def read_and_decode(filename_queue):
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
features = tf.parse_single_example(
serialized_example,
# Defaults are not specified since both keys are required.
features={
'height':tf.FixedLenFeature([], tf.int64),
'image_raw': tf.FixedLenFeature([], tf.string),
'label': tf.FixedLenFeature([], tf.int64)
})
image = tf.decode_raw(features['image_raw'], tf.uint8)
image = tf.reshape(image,[478, 717, 3])
image = tf.cast(image, tf.float32) * (1. / 255) - 0.5
label = tf.cast(features['label'], tf.int32)
return image
'''
Pointers: Remember to run init_op
tf.reshape may not be the ideal way.
'''
def run():
with tf.Graph().as_default():
filename_queue = tf.train.string_input_producer(["sample.tfrecords"],num_epochs=1)
images = read_and_decode(filename_queue)
image_shape = tf.shape(images)
init_op = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init_op)
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
img = sess.run([images])
coord.request_stop()
coord.join(threads)
run()
问题是,当我运行它时,出现以下错误:
所以,在最后一天,我一直在为此努力。我不确定该怎么办,甚至不知道为什么不起作用。似乎是一个足够简单的示例,应该没有问题。我正在使用TF010。
谢谢
最佳答案
在新版TensorFlow中:
tf.initialize_all_variables()
已过时。
他们提到您必须使用:
tf.global_variables_initializer()
这不能解决问题。如果我们查看更新的tf.train.string_input_producer()
API,它会提到num_epochs将被创建为局部变量。这里发生的是队列中没有任何要读取的内容,因此它表示请求1当前为0。只需添加以下内容:
tf.local_variables_initializer()
我已经推送了更新。