ImageFolder- get the same random image from the folder for two datasets

Hi,

I am currently using a concatenated dataset containing rgb images and depth images. So, I use something like

class ConcatDataset(torch.utils.data.Dataset):
    def __init__(self, *datasets):
        self.datasets = datasets

    def __getitem__(self, i):
            return tuple(d[i] for d in self.datasets)

    def __len__(self):
        return min(len(d) for d in self.datasets)

I am using the ImageFolder for getting them. The rgb and depth image that I get are not corresponding ones(i.e) it is different and random from the folder.
What is the best way to get corresponding images? Kindly help me with this.

Thanks!!!

So I found that the ImageFolder sorts the file names. Hence I made sure that my names of the rgb and depth images in the folder are corresponding and same. Now I pick the same rgb and depth image from the folder using ImageFolder.

2 Likes