Is there a way to stack two tensorflow datasets?

大城市里の小女人 提交于 2020-01-03 16:40:06

问题


I want to stack two datasets objects in Tensorflow (rbind function in R). I have created one dataset A from tfRecord files and one dataset B from numpy arrays. Both have same variables. Do you know if there is a way to stack these two datasets to create a bigger one ? Or to create an iterrator that will randomly read data from this two sources ?

Thanks


回答1:


The tf.data.Dataset.concatenate() method is the closest analog of tf.stack() when workind with datasets. If you have two datasets with the same structure (i.e. same types for each component, but possibly different shapes):

dataset_1 = tf.data.Dataset.range(10, 20)
dataset_2 = tf.data.Dataset.range(60, 70)

...you can concatenate them as follows:

combined_dataset = dataset_1.concatenate(dataset_2)


来源:https://stackoverflow.com/questions/48771502/is-there-a-way-to-stack-two-tensorflow-datasets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!