【发布时间】:2020-02-27 14:51:20
【问题描述】:
我想向 TFDS 添加一个 TensorFlow 数据集,其中包含一堆形状未知的 2 阶张量。要定义功能,我使用以下功能tfds.features.Tensor(shape=[None, None], dtype=tf.float32)。但是,当我尝试加载数据集时,它失败并出现错误:
NotImplementedError: Specification error for feature k (TensorInfo(shape=[None, None], dtype=tf.float32)): Tensor with a unknown dimension not at the first position not supported: TensorInfo(shape=[None, None], dtype=tf.float32)
重现错误的最小示例 (Real example on Github):
import numpy as np
import tensorflow as tf
import tensorflow_datasets as tfds
class RandomTensors(tfds.core.GeneratorBasedBuilder):
VERSION = tfds.core.Version('0.1.0')
def _info(self):
return tfds.core.DatasetInfo(
builder=self,
description="",
features=tfds.features.FeaturesDict({
'k':
tfds.features.Tensor(shape=[None, None], dtype=tf.float32)
}),
homepage="",
citation="",
)
def _split_generators(self, dl_manager: tfds.download.DownloadManager):
return [
tfds.core.SplitGenerator(
name=tfds.Split.TEST,
gen_kwargs={},
),
]
def _generate_examples(self):
for idx in range(100):
size = np.random.uniform(10, 20, size=(2, )).astype(np.int32)
k = np.random.normal(size=size).astype(np.float32)
yield idx, {'k': k}
if __name__ == '__main__':
d = tfds.load('random_tensors', split='test')
TensorFlow 数据集中是否不支持维度未知的张量?还是我的代码有错误?
【问题讨论】:
标签: python tensorflow tensorflow-datasets