I got confused about the image index concept by using torch.utils.data.DataLoader. This index is the index of image for the entire training/testing dataset or just index of image for the mini_batch? If it’s for the mini_batch then it means in the next mini-batch, the image with index 1 is the same as the previous image with index 1?
The DataLoader uses a sampler (e.g. RandomSampler if you specify shuffle=True) to create indices in the range [0, len(dataset)]. These indices will be used to index the passed Dataset instance, which will call into its __getitem__(self, index) method.
So yes, if the DataLoader uses the same index in the next epoch, Dataset.__getitem__ will also see the same index.
No. The custom or internal sampler will create the indices and pass them to the Dataset. batch_idx is created by your enumerate call and will assign an increasing index to each batch, which usually contains more than a single sample.