Reputation: 490
I'm loading images to pytorch using:
train_data = torchvision.datasets.ImageFolder(train_dir, transform=transform)
Which has some samples I want to omit.
Can i remove certain images from the loader? (by index? by name?) Thx
Upvotes: 1
Views: 3538
Reputation: 2493
You can modify the imgs
attribute of an ImageFolder
as follows:
train_data.imgs.remove((PATH, INDEX))
where you should replace PATH
with the path to the image you wish to remove and INDEX
should be replaced with the respective class index (starting from 0 to the number of classes you have).
In case you are not sure about the INDEX
you can print train_data.imgs
to obtain the list of all image paths with their classes in tuples.
Upvotes: 1