Targets in DataLoader, ImageFolder is empty

Hi,
I use this line of code for looping over my dataset
for batch_idx, (inputs,targets) in enumerate(trainloader)
My dataset is part of imagenet, and I loaded with ImageFolder, but target in here is zero.
Why my labels are not loaded in target?

And here is how I filled it:

    train_dataset = datasets.ImageFolder(
        traindir,
        transforms.Compose([
            transforms.Resize(size=(224, 224)),
            transforms.RandomHorizontalFlip(),
            transforms.ToTensor(),
            normalize,
        ]))

trainloader=torch.utils.data.DataLoader(train_dataset,batch_size=100)

trainloader=torch.utils.data.DataLoader(train_dataset,batch_size=100, shuffle=True)
shuffle=True

1 Like

Thanks, it worked. Could you please tell me why shuffle was important here?

by default, the data is sorted by absolute file name, so the first 1000 images all have label 0

1 Like