Questions about ImageFolder

I figured it out:
dataset.class_to_idx
from: https://pytorch.org/docs/stable/_modules/torchvision/datasets/folder.html#ImageFolder

Im new to Pytorch so excuse the amateur question: I have a number of .pmg images that are located within my ImageFolde.@ncullen93 When I try to follow your steps to iterate through the image I get the following error " OSError : cannot identify image file <_io.BufferedReader name=β€˜C:/…/faces\abc\abc_left_angry_open.pgm’>". Is this because of the pmg format? Majority of support is around jpeg so Im wondering if this is the issue. Thanks in advance.

Hello, Actually, there are two folder on kaggle on path β€œβ€™β€¦/input/aptos2019-blindness-detection/”, train_images and test_images, and imageFolder is loading the all images from both folder but i want dataset from train folder only, please help how can i achieve this?
if i give path to tain_images, it gives error i.e:

RuntimeError: Found 0 files in subfolders of: …/input/aptos2019-blindness-detection/train_images
Supported extensions are: .jpg,.jpeg,.png,.ppm,.bmp,.pgm,.tif,.tiff,.webp

but if i give path: β€œβ€¦/input/aptos2019-blindness-detection/”, it reads images from both folder.

i can’t even create a new folder because data is read only in kaggle

Hi, I have a dataset with following format -
Root_Folder
Class_1
Sub_class1
img1.tiff
img2.tiff
…
Sub_class2
img3.tiff
…
Sub_class3
.
.
.
class2
Sub_class1
.
.
And so on. When I use ImageFolder, I can get the label of parent classes.
How do I get labels for subclasses as well?
Do I need to build by own Custom Dataset?

Yes, this would be the best approach, since ImageFolder creates labels for the subfolders only (not their subfolders).
To do so you could reuse the source code of ImageFolder if possible.

1 Like

Hi,
I was using Image folder to create the basic cat versus dog data set from kaggle for classification but in my case the function is assigning a class for β€œ1” to both cat and dog. I believe I have followed the convention correctly attaching the code for reference.

train_dataset = torchvision.datasets.ImageFolder('./drive/My Drive/DDP/catvdog/Data/n_train', transform=transform_train)
test_dataset = torchvision.datasets.ImageFolder('./drive/My Drive/DDP/catvdog/Data/n_test', transform=transform_test)
train_loader = DataLoader(train_dataset, batch_size=4,
                        shuffle=True, num_workers=0)
test_loader = DataLoader(test_dataset, batch_size=4,
                        shuffle=False, num_workers=0)

image
Above is my directory path.
I don’t know what the issue is. ?

1 Like

Could you print(train_dataset.class_to_idx) and check the output?
The paths look correct and ImageFolder so I’m unsure why both folders get the same class index.