读取 TF Record 文件需要很长时间
Read TF Record file takes very long
在这里尝试通过张量流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 分钟了,我看不出会有什么结局。有人可以指出我做错了什么吗?
您忘记 运行 排队 运行 有 'tf.train.start_queue_runners(sess)'
的人
在这里尝试通过张量流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 分钟了,我看不出会有什么结局。有人可以指出我做错了什么吗?
您忘记 运行 排队 运行 有 'tf.train.start_queue_runners(sess)'
的人