Shortcuts

TFRecordLoader

class torchdata.datapipes.iter.TFRecordLoader(datapipe: Iterable[Tuple[str, BufferedIOBase]], spec: Optional[Dict[str, Tuple[Tuple[int, ...], dtype]]] = None, length: int = - 1)

Opens/decompresses tfrecord binary streams from an Iterable DataPipe which contains tuples of path name and tfrecord binary stream, and yields the stored records (functional name: load_from_tfrecord).

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

  • 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(".", "*.tfrecord")
>>> datapipe2 = FileOpener(datapipe1, mode="b")
>>> tfrecord_loader_dp = datapipe2.load_from_tfrecord()
>>> for example in tfrecord_loader_dp:
>>>     print(example)

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