I have a custom dataset with images in specific classes. I have saved this dataset on my computer using folders and subfolders.
Train Dataset :
Where the subfolders(5_1, 5_2, etc.) are the classes of the images. I want to use semi-supervised training where both labeled and unlabeled images must be used. But I don’t know how to “categorize” my unlabeled images in order to load them to my CNN. For the labeled images I use datasets.ImageFolder() and DataLoader() so I can load them for training.
Thanks for the help!
PS: I thought to save them in a different folder named as “Unlabeled” but I am afraid that it is gonna use the name of the folder as a new class and this is something that it’s gonna ruin the predictions in training as well in testing
You are right that the ImageFolder would create a new class index for this Unlabeled folder, but you could also replace it with your desired “invalid class index” and remap the other class indices if needed.
This would allow you to use the plain ImageFolder dataset with a DataLoader without writing a custom Dataset.
I still can’t resolve my problem.
I tried to create a new Dataset but the main question remains. Even if I changed the name of the class as an empty string it still revognizes the classes giving them indices. Is there a way to “delete” classes and class indices, so when I try to print for example an image as:
No, there is no clean way of returning a valid target value for some samples and nothing for others since this would create inconsistent batches of targets.
You could thus completely ignore the unknown classes and remove them from the dataset or return a “placeholder” target and deal with these samples somehow during training.