读取TF记录文件需要很长时间

时间:2017-09-14 00:25:51

标签: python tensorflow tfrecord

试图在这里经历张量流tutorial;我用~100个图像构建了一个tf记录文件,现在当我尝试以下内容时,内核挂起;为什么会这样? tf记录文件不大只有30MB左右,读取它们不需要很长时间:

import tensorflow as tf
import os

print(os.path.exists("../carmakesorter/train-00000-of-00001"))

filenameQ = tf.train.string_input_producer(["../carmakesorter/train-00000-of-00001"],num_epochs=None)

# object to read records
recordReader = tf.TFRecordReader()

# read the full set of features for a single example 
key, fullExample = recordReader.read(filenameQ)

# parse the full example into its' component features.
features = tf.parse_single_example(
    fullExample,
    features={
        'image/height': tf.FixedLenFeature([], tf.int64),
        'image/width': tf.FixedLenFeature([], tf.int64),
        'image/colorspace': tf.FixedLenFeature([], dtype=tf.string,default_value=''),
        'image/channels':  tf.FixedLenFeature([], tf.int64),            
        'image/class/label': tf.FixedLenFeature([],tf.int64),
        'image/class/text': tf.FixedLenFeature([], dtype=tf.string,default_value=''),
        'image/format': tf.FixedLenFeature([], dtype=tf.string,default_value=''),
        'image/filename': tf.FixedLenFeature([], dtype=tf.string,default_value=''),
        'image/encoded': tf.FixedLenFeature([], dtype=tf.string, default_value='')
    })

label = features['image/class/label']
with tf.Session() as sess:
    print('start ...')
    print(sess.run(label))               # I want to check the label here
    print('end ...')

打印:

True
start ...

我的笔记本内核已经挂了10分钟,我看不到会有结局。有人可以指出我做错了吗?

1 个答案:

答案 0 :(得分:2)

您忘记使用&t; tf.train.start_queue_runners(sess)'

运行队列运行器