tensorflow - TFRecord IO 比 python hdf5 阅读器慢,如何提高它的速度?
问题描述
我按照官方 TF 指南使用tf.data.Dataset
API 来构建数据管道,但我发现它比我使用 hdf5 的 python 数据管道慢 2 倍。
这是我的实验结果:
TFRecordDataset:66万样本/秒 hdf5 reader + feed_dict 到占位符:110 万样本/秒
我的实验设置是:
- 批量大小 = 1000,
- 每 1000 万个样本打印一次日志以显示时间,
- 运行一个只将数据作为输入并且不计算任何东西的假模型。
更糟糕的是,当我设置batch size=10000时,它变成了:
TFRecordDataset:76万样本/秒 hdf5 reader + feed_dict 到占位符:210 万样本/秒
这是我阅读 tfrecord 的代码
def parse_tfrecord_batch(record_batch):
FEATURE_LEN = 29
dics = {
'label': tf.FixedLenFeature(shape=(), dtype=tf.int64),
'feature_id': tf.FixedLenFeature(shape=(FEATURE_LEN,), dtype=tf.int64),
'feature_val': tf.FixedLenFeature(shape=(FEATURE_LEN,), dtype=tf.float32)
}
parsed_example = tf.parse_example(record_batch, dics)
return parsed_example['feature_id'], parsed_example['feature_val'], parsed_example['label']
class fakeModel:
def __init__(self, train_filenames):
self.graph = tf.Graph()
with self.graph.as_default():
dataset = tf.data.TFRecordDataset(train_filenames)
dataset = dataset.repeat()
dataset = dataset.batch(1000)
dataset = dataset.map(parse_tfrecord_batch, num_parallel_calls=1)
dataset = dataset.prefetch(1000)
self.iterator = dataset.make_initializable_iterator()
self.id, self.wt, self.label = self.iterator.get_next()
self.train_preds = tf.identity(self.lbl_hldr)
我已将其num_parallel_calls
调至 2、10。无法正常工作。
我还将prefetch(n)
从 1 调整到 1000,这几乎没有改进。
我的问题是:
有什么方法可以改善我的 tfrecord 数据管道?我的代码中是否缺少某些内容?
感谢它的任何帮助。
解决方案
推荐阅读
- java - 是否有任何选项可用于使用 tomcat 限制休息 API
- cakephp - 无法判断是否执行了 Cake\ORM\Query
- java - Http POST 失败,状态码:406,状态:不可接受
- joi - ArangoDB Joi Foxx 映射到 Swagger 不正确
- buildfire - 插件“ChatBot”中的白屏
- javascript - 在 ES6 中从一个类访问对象到另一个类
- r - 从 R 到 Excel 的日期转换(有时会偏移一天)
- python - go 和 python 的 gprc 演示
- javascript - 访问 .jsx 元素内的状态
- python - 致命的 Python 错误:Ubuntum16.04 上的分段错误