peal.data.dataloaders.DataStack

class peal.data.dataloaders.DataStack[source]

Bases: object

Per-class FIFO buffer of samples drawn from a dataset or dataloader.

data[c] holds [X, y] pairs of class c. The stack is refilled from the source whenever some class runs empty, so pop(c) always returns a sample of class c; it is used to assemble class-ordered batches for visualizations.

Parameters:
  • datasource (torch.utils.data.Dataset or DataLoader or DataloaderMixer) – Where samples come from. A dataset is walked sequentially and cyclically via current_idx; a dataloader is drawn from with next(iter(...)).

  • num_classes (int) – Number of classes, i.e. number of per-class lists.

  • transform (callable, optional) – Transform temporarily swapped into dataset.transform while the stack is being filled.

Methods

fill_stack

Draw samples from the source until every class list is non-empty.

pop

Remove and return the oldest buffered sample of one class.

reset

Empty all class lists, reset a DataloaderMixer source and refill.

__init__(datasource, num_classes, transform=None)[source]

Create the per-class lists and fill them once.

fill_stack()[source]

Draw samples from the source until every class list is non-empty.

With hints or indices enabled the label is a tuple and its first element is used as the class index.

pop(class_idx)[source]

Remove and return the oldest buffered sample of one class.

Parameters:

class_idx (int) – Class whose sample is popped.

Returns:

[X, y] of the sample; the stack is refilled afterwards.

Return type:

list

reset()[source]

Empty all class lists, reset a DataloaderMixer source and refill.