示例#1
0
def builder_cls(name: str) -> Type[dataset_builder.DatasetBuilder]:
    """Fetches a `tfds.core.DatasetBuilder` class by string name.

  Args:
    name: `str`, the registered name of the `DatasetBuilder` (the class name
      as camel or snake case: `MyDataset` or `my_dataset`).

  Returns:
    A `tfds.core.DatasetBuilder` class.

  Raises:
    DatasetNotFoundError: if `name` is unrecognized.
  """
    ds_name, kwargs = naming.parse_builder_name_kwargs(name)
    if kwargs:
        raise ValueError(
            '`builder_cls` only accept the `dataset_name` without config, '
            f"version or arguments. Got: name='{name}', kwargs={kwargs}")
    try:
        if ds_name.namespace:
            # `namespace:dataset` are loaded from the community register
            if visibility.DatasetType.COMMUNITY_PUBLIC.is_available():
                return community.community_register.builder_cls(ds_name)
            else:
                raise ValueError(
                    f'Cannot load {ds_name} when community datasets are disabled'
                )
        else:
            cls = registered.imported_builder_cls(str(ds_name))
            cls = typing.cast(Type[dataset_builder.DatasetBuilder], cls)
        return cls
    except registered.DatasetNotFoundError as e:
        _reraise_with_list_builders(e, name=ds_name)  # pytype: disable=bad-return-type
示例#2
0
def builder_cls(name: str) -> Type[dataset_builder.DatasetBuilder]:
    """Fetches a `tfds.core.DatasetBuilder` class by string name.

  Args:
    name: `str`, the registered name of the `DatasetBuilder` (the class name
      as camel or snake case: `MyDataset` or `my_dataset`).

  Returns:
    A `tfds.core.DatasetBuilder` class.

  Raises:
    DatasetNotFoundError: if `name` is unrecognized.
  """
    ns_name, builder_name, kwargs = naming.parse_builder_name_kwargs(name)
    if kwargs:
        raise ValueError(
            '`builder_cls` only accept the `dataset_name` without config, '
            f"version or arguments. Got: name='{name}', kwargs={kwargs}")
    if ns_name:
        raise ValueError(
            f'Namespaces not supported for `builder_cls`. Got: {ns_name}')
    # Imported datasets
    try:
        cls = registered.imported_builder_cls(builder_name)
        cls = typing.cast(Type[dataset_builder.DatasetBuilder], cls)
        return cls
    except registered.DatasetNotFoundError as e:
        _reraise_with_list_builders(e,
                                    ns_name=ns_name,
                                    builder_name=builder_name)
示例#3
0
def _get_default_config_name(name: str) -> Optional[str]:
    """Returns the default config of the given dataset, None if not found."""
    # Search for the DatasetBuilder generation code
    try:
        cls = registered.imported_builder_cls(name)
        cls = typing.cast(Type[dataset_builder.DatasetBuilder], cls)
    except registered.DatasetNotFoundError:
        return None

    # If code found, return the default config
    if cls.BUILDER_CONFIGS:
        return cls.BUILDER_CONFIGS[0].name
    return None
def _get_default_config_name(builder_dir: str, name: str) -> Optional[str]:
    """Returns the default config of the given dataset, None if not found."""
    # Search for the DatasetBuilder generation code
    try:
        cls = registered.imported_builder_cls(name)
        cls = typing.cast(Type[dataset_builder.DatasetBuilder], cls)
    except registered.DatasetNotFoundError:
        pass
    else:
        # If code found, return the default config
        if cls.BUILDER_CONFIGS:
            return cls.BUILDER_CONFIGS[0].name

    # Otherwise, try to load default config from common metadata
    return dataset_builder.load_default_config_name(utils.as_path(builder_dir))
示例#5
0
def _get_default_config_name(builder_dir: str, name: str) -> Optional[str]:
    """Returns the default config of the given dataset, None if not found."""
    # Search for the DatasetBuilder generation code
    try:
        # Warning: The registered dataset may not match the files (e.g. if
        # the imported datasets has the same name as the generated files while
        # being 2 differents datasets)
        cls = registered.imported_builder_cls(name)
        cls = typing.cast(Type[dataset_builder.DatasetBuilder], cls)
    except (registered.DatasetNotFoundError, PermissionError):
        pass
    else:
        # If code found, return the default config
        if cls.BUILDER_CONFIGS:
            return cls.BUILDER_CONFIGS[0].name

    # Otherwise, try to load default config from common metadata
    return dataset_builder.load_default_config_name(utils.as_path(builder_dir))