Shortcuts

TarArchiveLoader

class torchdata.datapipes.iter.TarArchiveLoader(datapipe: Iterable[Tuple[str, BufferedIOBase]], mode: str = 'r:*', length: int = -1)

Opens/decompresses tar binary streams from an Iterable DataPipe which contains tuples of path name and tar binary stream, and yields a tuple of path name and extracted binary stream (functional name: load_from_tar).

Parameters:
  • datapipe – Iterable DataPipe that provides tuples of path name and tar binary stream

  • mode – File mode used by tarfile.open to read file object. Mode has to be a string of the form ‘filemode[:compression]’

  • length – a nominal length of the DataPipe

Note

The opened file handles will be closed automatically if the default DecoderDataPipe is attached. Otherwise, user should be responsible to close file handles explicitly or let Python’s GC close them periodically.

Example

>>> from torchdata.datapipes.iter import FileLister, FileOpener
>>> datapipe1 = FileLister(".", "*.tar")
>>> datapipe2 = FileOpener(datapipe1, mode="b")
>>> tar_loader_dp = datapipe2.load_from_tar()
>>> for _, stream in tar_loader_dp:
>>>     print(stream.read())
b'0123456789abcdef'

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources