delu.data.IndexLoader#
- class delu.data.IndexLoader(size, *args, device='cpu', **kwargs)[source]#
[DEPRECATED | Instead, use
delu.data.IndexDataset
andDataLoader
] LikeDataLoader
, but over indices instead of data.The shuffling logic is delegated to the native PyTorch DataLoader, i.e. no custom logic is performed under the hood. The data loader which actually generates indices is available as
IndexLoader.loader
.Examples
Usage for training:
train_loader = delu.data.IndexLoader( len(train_dataset), batch_size, shuffle=True ) for epoch in range(n_epochs): for batch_idx in train_loader: ...
Other examples:
dataset_size = 10 # len(dataset) for batch_idx in delu.data.IndexLoader(dataset_size, batch_size=3): print(batch_idx)
tensor([0, 1, 2]) tensor([3, 4, 5]) tensor([6, 7, 8]) tensor([9])
dataset_size = 10 # len(dataset) for batch_idx in delu.data.IndexLoader(dataset_size, 3, drop_last=True): print(batch_idx)
tensor([0, 1, 2]) tensor([3, 4, 5]) tensor([6, 7, 8])
See also
Attributes
The underlying DataLoader.
Methods