我试图让一个非常简单的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.train.string_input_producer()
的较新API,它提到num\u epoch将被创建为一个局部变量。这里发生的是队列中没有可供它读取的内容,因此它显示requested 1 current 0。只需添加以下内容:我已经推了更新。在
问题也可能不在TFRecords上,而是在设置num_epochs时,使用LOCAL_VARIABLES collection的string_input_producer。见here。在
op
tf.initialize_all_variables()
并没有像它的名字那样初始化所有的变量。快速修复方法如下:init_op = tf.group(tf.initialize_all_variables(), tf.initialize_local_variables())
,但请考虑使用Tensorflow r0.12,其中不推荐使用此操作,取而代之的是}
tf.global_variables_initializer
和{相关问题 更多 >
编程相关推荐