Наборы данных Tensorflow tfds FeatureConnector для данных NumPy (2-канальный звук) - PullRequest
0 голосов
/ 10 мая 2019

Задача

Я создаю набор данных для TensorFlow 2.0 на основе DatasetBuilder, используя tfds.core.GeneratorBasedBuilder. В def _info(self): вы должны указать свои функции через tfds.features.FeatureConnectors.

Данные

Мои данные существуют из строковых меток и пустых данных, представляющих 2-канальные аудиоданные, извлеченные из файла HDF5. Поэтому я не могу использовать tfds.features.Audio, потому что этот класс ожидает строковый путь к аудиофайлу.

Попытка

Глядя на страницу tfds.features , tfds.features.Tensor представляется наиболее перспективным, поэтому я попытался tfds.features.Tensor(tf.VarLenFeature(tf.float32)):

def _info(self):
    # TODO(my_dataset): Specifies the tfds.core.DatasetInfo object
    return tfds.core.DatasetInfo(
        builder=self,
        # This is the description that will appear on the datasets page.
        description=_DESCRIPTION,
        # tfds.features.FeatureConnectors
        features=tfds.features.FeaturesDict({
            # These are the features of your dataset like images, labels ...
            "audio_description": tfds.features.Text(),
            "audio": tfds.features.Tensor(tf.io.VarLenFeature(tf.float32)),  # EDIT 1  # tfds.features.Image(),
            # Here, labels can be of 5 distinct values.
            "label": tfds.features.ClassLabel(num_classes=2),  # M / F (testing)
        }),
        # If there's a common (input, target) tuple from the features,
        # specify them here. They'll be used if as_supervised=True in
        # builder.as_dataset.
        supervised_keys=('audio', 'label'),
        # Homepage of the dataset for documentation
        urls=[],
        citation=_CITATION,
    )

Error

Однако это приводит к: AttributeError: module 'tensorflow' has no attribute 'VarLenFeature'

Вопросы

  1. Является ли tfds.features.Tensor(tf.VarLenFeature(tf.float32)) действительно правильным выбором здесь?
  2. Поиск ошибки не приводит к результатам. tf.VarLenFeature удалено из tenorflow 2.0?

Примечания

return {
    'image': tf.VarLenFeature(tf.uint8):
    'height': tf.FixedLenFeature((), tf.int32),
    'width': tf.FixedLenFeature((), tf.int32),
}

  • Я не ищу tf.data.Dataset.from_generator(gen_func, (tf.float32, tf.str?)), потому что я ищу правильный способ определения набора данных для других пользователей. Не просто быстрое тестирование кода самостоятельно.

System

  • ОС хоста: Ubuntu 18.04
  • Контейнер Docker: docker run -it --runtime=nvidia --rm -v /home/notebooks:/tf/notebooks -p 8889:8888 tensorflow/tensorflow:2.0.0a0-gpu-py3-jupyter
  • Docker Python: 3,5
  • Docker Tensorflow: 2.0.0-alpha
  • Докер tensorflow_datasets.version.__version__: '1.0.2'

Редактировать 1

Что касается вопроса 2, он, очевидно, подпадает под tf.io.VarLenFeature. Однако появляется новая ошибка:

<ipython-input-17-0166e5b99a43> in _info(self)
     22             # These are the features of your dataset like images, labels ...
     23             "audio_description": tfds.features.Text(),
---> 24             "audio": tfds.features.Tensor(tf.io.VarLenFeature(tf.float32)),  # tfds.features.Image(),
     25             # Here, labels can be of 5 distinct values.
     26             "label": tfds.features.ClassLabel(num_classes=2),  # M / F (testing)

/usr/local/lib/python3.5/dist-packages/tensorflow_datasets/core/api_utils.py in disallow_positional_args_dec(fn, instance, args, kwargs)
     48   def disallow_positional_args_dec(fn, instance, args, kwargs):
     49     ismethod = instance is not None
---> 50     _check_no_positional(fn, args, ismethod, allowed=allowed)
     51     _check_required(fn, kwargs)
     52     return fn(*args, **kwargs)

/usr/local/lib/python3.5/dist-packages/tensorflow_datasets/core/api_utils.py in _check_no_positional(fn, args, is_method, allowed)
     62     if all([name in allowed for name in arg_names]):
     63       return
---> 64     raise ValueError(_POSITIONAL_ARG_ERR_MSG % (fn.__name__, str(arg_names)))
     65 
     66 

ValueError: Please use keyword arguments and not positional arguments. This enables more flexible API development. Thank you!
Positional arguments passed to fn __init__: ['shape'].
...