Hi everyone! I’m working on a classification problem where I have a folder with images and the label is the folder name. I am using the following script to generate loaders but when I iterate through any of the two loaders, I do not get random samples. Rather, its all samples from the first class (observed by printing the labels).  The pytorch version is 0.4.1.post2 (Ubuntu).
def get_dataloaders(data_path, val_split, batch_size, shuffle=True):
    t = transforms.Compose([transforms.Resize((150,150)), 
                            transforms.ToTensor()])
    dataset = torchvision.datasets.ImageFolder(root=data_path,transform=t)

    dataset_size = len(dataset)
    indices = list(range(dataset_size))
    split = int(np.floor(val_split * dataset_size))
    
    if shuffle:
        np.random.seed(42)
        np.random.shuffle(indices)
      
    train_indices, val_indices = indices[split:], indices[:split]
    train_sampler = SubsetRandomSampler(train_indices)
    val_sampler = SubsetRandomSampler(val_indices)
        
    train_loader = DataLoader(dataset, batch_size=batch_size, sampler=train_sampler)
    val_loader = DataLoader(dataset, batch_size=batch_size, sampler=val_sampler)
    return train_loader, val_loader

train_loader, val_loader = get_dataloaders(data_path, val_split, batch_size,shuffle=True)
images, labels = next(iter(train_loader))

Am I doing this incorrectly? Strangely, on my Windows machine with pytorch version 0.4.1 all is fine and I see random samples when I print the labels.
Btw, the folder structure looks like this:
root
|_ class1
       |_ patient1
                 |_ img1.jpg  etc
|_ class2
       |_ patient1
                  |_ img1.jpg