Gets a data source from the named dataset. `tfds.data_source` is a convenience method that: 1. Fetches the `tfds.core.DatasetBuilder` by name: ```python builder = tfds.builder(name, data_dir=data_dir, **builder_kwargs) ``` 2. Generates the data (when `download=True`):
(
name: str,
*,
split: Tree[splits_lib.SplitArg] | None = None,
data_dir: epath.PathLike | None = None,
download: bool = True,
decoders: TreeDict[decode.partial_decode.DecoderArg] | None = None,
deserialize_method: decode.DeserializeMethod = decode.DeserializeMethod.DESERIALIZE_AND_DECODE,
builder_kwargs: dict[str, Any] | None = None,
download_and_prepare_kwargs: dict[str, Any] | None = None,
try_gcs: bool = False,
)
| 722 | |
| 723 | @tfds_logging.data_source() |
| 724 | def data_source( |
| 725 | name: str, |
| 726 | *, |
| 727 | split: Tree[splits_lib.SplitArg] | None = None, |
| 728 | data_dir: epath.PathLike | None = None, |
| 729 | download: bool = True, |
| 730 | decoders: TreeDict[decode.partial_decode.DecoderArg] | None = None, |
| 731 | deserialize_method: decode.DeserializeMethod = decode.DeserializeMethod.DESERIALIZE_AND_DECODE, |
| 732 | builder_kwargs: dict[str, Any] | None = None, |
| 733 | download_and_prepare_kwargs: dict[str, Any] | None = None, |
| 734 | try_gcs: bool = False, |
| 735 | ) -> type_utils.ListOrTreeOrElem[Sequence[Any]]: |
| 736 | """Gets a data source from the named dataset. |
| 737 | |
| 738 | `tfds.data_source` is a convenience method that: |
| 739 | |
| 740 | 1. Fetches the `tfds.core.DatasetBuilder` by name: |
| 741 | |
| 742 | ```python |
| 743 | builder = tfds.builder(name, data_dir=data_dir, **builder_kwargs) |
| 744 | ``` |
| 745 | |
| 746 | 2. Generates the data (when `download=True`): |
| 747 | |
| 748 | ```python |
| 749 | builder.download_and_prepare(**download_and_prepare_kwargs) |
| 750 | ``` |
| 751 | |
| 752 | 3. Gets the data source: |
| 753 | |
| 754 | ```python |
| 755 | ds = builder.as_data_source(split=split) |
| 756 | ``` |
| 757 | |
| 758 | You can consume data sources: |
| 759 | |
| 760 | - In Python by iterating over them: |
| 761 | |
| 762 | ```python |
| 763 | for example in ds['train']: |
| 764 | print(example) |
| 765 | ``` |
| 766 | |
| 767 | - With a DataLoader (e.g., with |
| 768 | [Pytorch](https://pytorch.org/docs/stable/data.html)). |
| 769 | |
| 770 | **Warning**: calling this function might potentially trigger the download |
| 771 | of hundreds of GiB to disk. Refer to the `download` argument. |
| 772 | |
| 773 | Args: |
| 774 | name: `str`, the registered name of the `DatasetBuilder` (the snake case |
| 775 | version of the class name). The config and version can also be specified |
| 776 | in the name as follows: `'dataset_name[/config_name][:version]'`. For |
| 777 | example, `'movielens/25m-ratings'` (for the latest version of |
| 778 | `'25m-ratings'`), `'movielens:0.1.0'` (for the default config and version |
| 779 | 0.1.0), or`'movielens/25m-ratings:0.1.0'`. Note that only the latest |
| 780 | version can be generated, but old versions can be read if they are present |
| 781 | on disk. For convenience, the `name` parameter can contain comma-separated |
nothing calls this directly
no test coverage detected