I would like to add a TensorFlow dataset to TFDS which contains a bunch of rank 2 tensors with unknown shapes. To define the features I use the following feature tfds.features.Tensor(shape=[None, None], dtype=tf.float32). However, when I try to load the dataset it fails with the error:
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)
A minimal example to reproduce the error (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')
Are tensors with unknown dimensions not supported in TensorFlow Datasets? Or do I have an an error in my code?