我想用.tfrecord在一个批处理中加载tf.contrib.learn.read_batch_features(...)条目。当我在训练估计器时使用下面的代码(类似于read_and_decode()的内容),它可以工作。当我运行load_samples()时,它挂在eval(session=sess)上,当运行没有估计器的脚本时。我想这是输油管道的问题,但不知何故,我无法确定问题的所在。我在tensorflow网站上跟随了向导,但没有任何运气。
def read_and_decode(sess, cnt):
def get_reader():
return tf.TFRecordReader()
features = tf.contrib.learn.read_batch_features(
file_pattern=os.path.join('.', 'test.tfrecord'),
batch_size=cnt,
reader=get_reader,
features={
'label': tf.FixedLenFeature([], tf.int64),
'data': tf.FixedLenFeature([], tf.string),
})
label = tf.cast(features['label'], tf.int64)
data = tf.decode_raw(features['data'], tf.float32)
patch = tf.reshape(data, tf.stack( [cnt, 6, 20, 20] ))
patch.set_shape( [cnt, 6, 20, 20] )
return label.eval(session=sess), patch.eval(session=sess)
def load_samples():
with tf.Session() as sess:
sess.run([
tf.local_variables_initializer(),
tf.global_variables_initializer()
])
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
try:
while not coord.should_stop():
samples = read_and_decode(sess,100)
except tf.errors.OutOfRangeError as error:
coord.request_stop(error)
finally:
coord.request_stop()
coord.join(threads)你能解释一下我做错了什么吗?
发布于 2017-06-26 15:43:58
原因是您正在启动队列运行程序,然后定义队列。您需要首先定义函数read_and_decode(),然后启动队列运行程序,这将解决问题。
https://stackoverflow.com/questions/44723310
复制相似问题