Tensorflow tf.data.Dataset API,数据集解压函数?

Tensorflow tf.data.Dataset API,数据集解压函数?,tensorflow,tensorflow-datasets,Tensorflow,Tensorflow Datasets,在tensorflow 1.12中,有一个Dataset.zip函数:记录在案 但是,我想知道是否有一个数据集解压函数可以返回原来的两个数据集 # NOTE: The following examples use `{ ... }` to represent the # contents of a dataset. a = { 1, 2, 3 } b = { 4, 5, 6 } c = { (7, 8), (9, 10), (11, 12) } d = { 13, 14 } # The nes

在tensorflow 1.12中,有一个
Dataset.zip
函数:记录在案

但是,我想知道是否有一个数据集解压函数可以返回原来的两个数据集

# NOTE: The following examples use `{ ... }` to represent the
# contents of a dataset.
a = { 1, 2, 3 }
b = { 4, 5, 6 }
c = { (7, 8), (9, 10), (11, 12) }
d = { 13, 14 }

# The nested structure of the `datasets` argument determines the
# structure of elements in the resulting dataset.
Dataset.zip((a, b)) == { (1, 4), (2, 5), (3, 6) }
Dataset.zip((b, a)) == { (4, 1), (5, 2), (6, 3) }

# The `datasets` argument may contain an arbitrary number of
# datasets.
Dataset.zip((a, b, c)) == { (1, 4, (7, 8)),
                            (2, 5, (9, 10)),
                            (3, 6, (11, 12)) }

# The number of elements in the resulting dataset is the same as
# the size of the smallest dataset in `datasets`.
Dataset.zip((a, d)) == { (1, 13), (2, 14) }
我想要以下的

dataset = Dataset.zip((a, d)) == { (1, 13), (2, 14) }
a, d = dataset.unzip()

我的解决方法是只使用map,不确定稍后是否会对
解压的语法糖函数感兴趣

a = dataset.map(lambda a, b: a)
b = dataset.map(lambda a, b: b)

基于Ouwen Huang的回答,此函数似乎适用于任意数据集:

def split_datasets(dataset):
    tensors = {}
    names = list(dataset.element_spec.keys())
    for name in names:
        tensors[name] = dataset.map(lambda x: x[name])

    return tensors

在github上仍然有一个悬而未决的问题:不幸的是,不能保证a和b的顺序相同(共享相同的索引)。@random\u dsp\u guy你是什么意思?除非在映射调用中洗牌其中一个数据集或使用
deterministic=False
,否则它们将具有相同的顺序。