Shortcuts

torchtnt.utils.data.InOrderIterator

class torchtnt.utils.data.InOrderIterator(individual_dataloaders: Mapping[str, Union[DataLoader, Iterable]], iteration_strategy: InOrder)

InOrderIterator returns all batches from a single dataset till it is exhausted and then moves to the next one.

By default, the order is same as the keys of the input dataloader dict. This can be overridden to provide custom order. Repetition is supported.

Returns batches of the format: {dataloader_name: batch_from_dataloader}

Parameters:
  • individual_dataloaders (Mapping[str, Union[DataLoader, Iterable]]) – A mapping of DataLoaders or Iterables with dataloader name as key
  • value. (and dataloader/iterable object as) –
  • iteration_strategy (RandomizedBatchSampler) – A RandomizedBatchSampler dataclass indicating how the dataloaders are iterated over.

Examples

>>> loaders = {'a': torch.utils.data.DataLoader(range(4), batch_size=4),
    'b': torch.utils.data.DataLoader(range(15), batch_size=5)}
>>> in_order_strategy = InOrder()
>>> combined_iterator = RandomizedBatchSamplerIterator(loaders, in_order_strategy)
>>> for item in combined_iterator:
        print(item)
{'a': tensor([0, 1, 2, 3])}
{'b': tensor([0, 1, 2, 3, 4])}
{'b': tensor([5, 6, 7, 8, 9])}
{'b': tensor([10, 11, 12, 13, 14])}
__init__(individual_dataloaders: Mapping[str, Union[DataLoader, Iterable]], iteration_strategy: InOrder) None

Methods

__init__(individual_dataloaders, ...)

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