I would like to change a member variable of the dataset class every time the dataloader iterates trough my data again (Once per epoch). Since the Sampler gets called once per epoch when calling iter()
I though of the following:
class MySampler(object):
def __init__(self, dataset):
self.dataset = dataset
self.sampler = RandomSampler(self.dataset)
self.first_epoch = True
self.rng = default_rng()
def __iter__(self):
if not self.first_epoch:
self.dataset.other_data_indices = np.concatenate([self.rng.choice(len(100), size=len(100), replace=False))
self.first_epoch = False
return self.sampler
However, it doesn’t work because probably the dataset passed in the creation of the Sampler class is not shared with the dataset that my dataloader is using. Does anyone know how could I change self.dataset.other_data_indices
from my Dataset or from any class/function passed to the dataloader once per epoch? (I can’t change the Dataloader itself because is a custom version of a private repo)