【发布时间】:2018-11-08 13:42:25
【问题描述】:
我是 TensorFlow 新手,我想知道使用 tfdata 设置数据集的特定顺序。例如:
data_files = tf.gfile.Glob("%s%s%s" % ("./data/cifar-100-binary/", self.data_key, ".bin"))
data = tf.data.FixedLengthRecordDataset(data_files, record_bytes=3074)
data = data.map(self.load_transform)
if self.shuffle_key:
data = data.shuffle(5000)
data = data.batch(self.batch_size).repeat(100)
iterator = data.make_one_shot_iterator()
img, label = iterator.get_next()
# label = tf.one_hot(label, depth=100)
print('img_shape:', img.shape)
在这种情况下,我读取数据,然后对数据进行洗牌,然后是批量和重复规范。使用这种方法,我的电脑内存增加了 2%
然后我又尝试了一种方法:
data_files = tf.gfile.Glob("%s%s%s" % ("./data/cifar-100-binary/", self.data_key, ".bin"))
data = tf.data.FixedLengthRecordDataset(data_files, record_bytes=3074)
data = data.map(self.load_transform)
data = data.batch(self.batch_size).repeat(100)
if self.shuffle_key:
data = data.shuffle(5000)
iterator = data.make_one_shot_iterator()
img, label = iterator.get_next()
# label = tf.one_hot(label, depth=100)
print('img_shape:', img.shape)
所以在这种情况下,当我第一次指定批量大小时,重复然后随机播放 RAM 利用率会增加 40%(我不知道为什么),如果有人能帮我解决这个问题,那就太好了。 那么是否有一个我应该始终遵循的顺序来使用 tf.data 在 tensorflow 中定义数据集?
【问题讨论】:
-
查看input pipeline performance guide,了解更多设计优化数据管道的背景知识!
-
@kvish aah 非常感谢您提供有用的链接。
标签: python tensorflow deep-learning tensorflow-datasets