I am not sure if I understand your question correctly or not but I’d like to mention few things that I think might be helpful.
- Basically, when you set shuffle equal to
Trueyour dataset indices will change every epoch and you won’t get the same instances in two consecutive epochs since you reshuffled at every epoch. Also, your dataloader should give you the correct (image, label) pairs and if it doesn’t seem right, please check the output of your dataset one more time. - If you need more than one instance for your calculation at each iteration, I would suggest changing the
__getitem__function of your dataset. (It is not a good idea if you are just trying to update the weights less frequently or training a GAN , …) - Here is another possible way but I cannot say if it’s the most efficient way for your case or not.
for curr_iter in range(num_iter):
i = 0
while i < number_of_iterations_you_need:
data_iter = next(iter(train_loader))
#do anything you want
i +=1