Attention
June 2024 Status Update: Removing DataPipes and DataLoader V2
We are re-focusing the torchdata repo to be an iterative enhancement of torch.utils.data.DataLoader. We do not plan on continuing development or maintaining the [DataPipes] and [DataLoaderV2] solutions, and they will be removed from the torchdata repo. We’ll also be revisiting the DataPipes references in pytorch/pytorch. In release torchdata==0.8.0 (July 2024) they will be marked as deprecated, and in 0.9.0 (Oct 2024) they will be deleted. Existing users are advised to pin to torchdata==0.8.0 or an older version until they are able to migrate away. Subsequent releases will not include DataPipes or DataLoaderV2. Please reach out if you suggestions or comments (please use this issue for feedback)
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)