Custom dataset has no attribute "data"

Hello,

I have created a custom dataset using the ImageFolder:

dataset_fake = datasets.ImageFolder(root=dataroot_fake,
                           transform=transforms.Compose([
                               transforms.Resize(image_size),
                               transforms.CenterCrop(image_size),
                               transforms.ToTensor(),
                               transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
                           ]))

And when I try to access its data field by doing

dataset_fake.data

It gives me the error

AttributeError:
'ImageFolder' object has no attribute 'data'

Any help would be appreciated. Thank you so much!

If you want to access a specific image you can do it so

img, lbl = dataset_fake[position_you_want]

If you only want to print the summary then you can use

print(dataset_fake)

Or if you want the name of the image you are using you can do something like

print(dataset_fake.samples)

Thank you very much! This solved my problem!

1 Like