有没有办法堆叠两个张量流数据集? [英] Is there a way to stack two tensorflow datasets?

查看:25
本文介绍了有没有办法堆叠两个张量流数据集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Tensorflow 中堆叠两个数据集对象(R 中的 rbind 函数).我从 tfRecord 文件创建了一个数据集 A,从 numpy 数组创建了一个数据集 B.两者都有相同的变量.您知道是否有办法将这两个数据集堆叠起来以创建更大的数据集?或者创建一个迭代器从这两个源随机读取数据?

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 ?

谢谢

推荐答案

tf.data.Dataset.concatenate() 方法是处理数据集时最接近 tf.stack() 的类似物.如果您有两个结构相同的数据集(即每个组件的类型相同,但形状可能不同):

The tf.data.Dataset.concatenate() method is the closest analog of tf.stack() when working 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)

然后您可以按如下方式连接它们:

then you can concatenate them as follows:

combined_dataset = dataset_1.concatenate(dataset_2)

这篇关于有没有办法堆叠两个张量流数据集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆