How to sample through a small dataset for more iterations than data size?
I have one small and one large dataset and they signify two separate classes. The network I am training is style transfer, so I need one image of each class in order to keep training. The training stops though, as soon as the smaller dataset runs out. How can I keep sampling from the small dataset randomly beyond its size? 

I tried RandomSampler() but that didn't work. Here's my code for the small dataset :

sampler = RandomSampler(self)
dataloader = DataLoader(self, batch_size=26, shuffle=False, sampler=sampler)
while True:
    for data in dataloader:
        yield data


I also tried iterator.cycle but that didn't help either.

loader = iter(cycle(self.dataset.gen(attribute_id, True)))
A, y_A = next(loader)
B, y_B = next(self.dataset.gen(attribute_id, False))


Your idea with the RandomSampler was not far off. There is a sampler called SubsetRandomSampler. While a subset typically is smaller than the whole set, this has not to be the case. 

Lets say your smaller dataset has A entries and your second dataset has B. You could define your indices:

indices = np.random.randint(0, A, B)   
sampler = torch.utils.data.sampler.SubsetRandomSampler(indices)


This generates B indices in a range valid for the smaller dataset.

Test:

loader = torch.utils.data.DataLoader(set_A, batch_size=1, sampler=sampler)
print(len(loader)) # B

