sketchgraphs_models.nn.data_util.MultiEpochSampler¶
-
class
sketchgraphs_models.nn.data_util.
MultiEpochSampler
(batch_sampler, num_epochs)¶ A sampler wrapper which creates multiple epochs of indices from one sampler.
Due to the way torch dataloaders function, they reset all workers when starting a new epoch. This is undesirable due to the high setup cost of starting workers.
This sampler thus wraps an existing batch sampler, and simply repeatedly samples several epochs from the wrapped sampler.
-
__init__
(batch_sampler, num_epochs)¶ Initializes a new instance of
MultiEpochSampler
.- Parameters
batch_sampler (torch.utils.data.Sampler) – A batch sampler to wrap
num_epochs (int) – The number of epochs for this sampler.
-
property
batches_per_epoch
¶ Get the number of batches per one single epoch of the original sampler.
-