在 TensorFlow 中加载数据点对

问题描述

问题描述

在 Tensorflow 1 中,我有一个标签的 TFRecord 数据集,其中包含 20,000 张图像,每个图像属于 500 个类别之一。

dataset = [(im1,1),(im2,...,(im20000,500)]

(每个元组中的第一个元素表示图像,第二个元素表示标签。)

在训练期间的每一步,我想从同一类中随机加载一对图像,即像 (im89,3),(im95,3)(im5046,127),(im5063,127) 之类的图像。

最有效的方法是什么?我当然可以创建所有可能的图像对的数据集,但这需要大量的磁盘空间。

非常感谢您的帮助!

到目前为止我尝试了什么

我已阅读 TensorFlow 文档 https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/data/TFRecordDataset 并浏览了 https://www.tensorflow.org/guide/data 上的教程。 我怀疑 tf.data.TFRecordDataset.interleave 可能会有所帮助,因此我查看了与 interleave (Is there a way to use tf.data.Dataset inside of another Dataset in Tensorflow?,Interleaving multiple TensorFlow datasets together,How to use tf.data.Dataset.interleave() in TF 2 with a custom function?,How exactly does tf.data.Dataset.interleave() differ from map() and flat_map()?,Build tensorflow dataset iterator that produce batches with special structure).

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)