Shortcuts

UnBatcher

class torchdata.datapipes.iter.UnBatcher(datapipe: IterDataPipe, unbatch_level: int = 1)

Undoes batching of data (functional name: unbatch). In other words, it flattens the data up to the specified level within a batched DataPipe.

Parameters:
  • datapipe – Iterable DataPipe being un-batched

  • unbatch_level – Defaults to 1 (only flattening the top level). If set to 2, it will flatten the top two levels, and -1 will flatten the entire DataPipe.

Example

>>> # xdoctest: +SKIP
>>> from torchdata.datapipes.iter import IterableWrapper
>>> source_dp = IterableWrapper([[[0, 1], [2]], [[3, 4], [5]], [[6]]])
>>> dp1 = source_dp.unbatch()
>>> list(dp1)
[[0, 1], [2], [3, 4], [5], [6]]
>>> dp2 = source_dp.unbatch(unbatch_level=2)
>>> list(dp2)
[0, 1, 2, 3, 4, 5, 6]

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