我的训练过程使用tfrecord格式的火车& eval数据集。TFRecordReader看起来非常慢,并且多线程阅读不起作用
我测试阅读器的基准,只有8000记录/秒。和io速度(见iotop命令)只有400KB-500KB/s。
我使用的protobuf的CPP版本在这里
如果可能的话,提供一个最小的可重复的例子(我们通常没有时间来阅读数百你的代码的行)
def read_and_decode(filename_queue):
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
return serialized_example
serialized_example = read_and_decode(filename_queue)
batch_serialized_example = tf.train.shuffle_batch(
[serialized_example],
batch_size=batch_size,
num_threads=thread_number,
capacity=capacity,
min_after_dequeue=min_after_dequeue)
features = tf.parse_example(
batch_serialized_example,
features={
"label": tf.FixedLenFeature([], tf.float32),
"ids": tf.VarLenFeature(tf.int64),
"values": tf.VarLenFeature(tf.float32),
})
您尝试过其他尝试的解决方案吗?
我尝试在tf.train.shuffle_batch中设置num_threads,但无法正常工作。
似乎当设置为2个线程时,它工作在8000个记录/秒,当放大线程数时,它变慢。 (我删除了所有花费cpus的ops,只是读取数据。)
我的服务器是24核心cpus。
您受CPU或磁盘限制吗?做时间线可视化可以帮助看到瓶颈在哪里 –
很高兴再次见到你。 1)不,我不限制CPU的使用。 2)我的tfrecords文件存储在本地磁盘驱动器中。这是表现的原因吗? 3)我现在要做时间线。感谢您的建议。我稍后再更新。 – ericyue
这里是我的基准脚本和时间轴结果(timeline.json原始文件inlcude)https://gist.github.com/ericyue/7705407a88e643f7ab380c6658f641e8 – ericyue