How should my folder structure be for multilabel multiclass output using torchvision.datasets.ImageFolder
?
ImageFolder
cannot be used for a multi-label classification, since each subfolder will get a single class index. For this use case you would have to implement a custom Dataset
and create or read the targets in it.
Yes just as i thought. Thank You.
I have one ore issue. How to skip if an image is not available and fetch another image
Here is my code
def __getitem__(self, index):
imagePath = self.listImagePaths[index]
imageData = Image.open(imagePath).convert('RGB')
imageLabel= torch.FloatTensor(self.listImageLabels[index])
if self.transform != None: imageData = self.transform(imageData)
return imageData, imageLabel`
some image names in csv are not available which rises error.
The “clean” solution would be to iterate the dataset once before the training, store all invalid indices in a list
or any other container and remove these invalid samples afterwards.
During training you could sample another index randomly inside __getitem__
, but this would yield these randomly samples multiple times during training, which might not be desirable.