Import dataset using datasets.ImageFolder

Hi guys,
When I use:
torchvision.datasets.ImageFolder
to import train dataset I get this Error:

RuntimeError: Found 0 images in subfolders of: /data/train/
Supported image extensions are: .jpg,.jpeg,.png,.ppm,.bmp,.pgm,.tif,.tiff,webp

Any help!?

1 Like

Did you check if there are images in /data/train? Maybe your training set is elsewhere.

Thank you for replying, I made sure that the folder contains the images

Are you maybe passing an absolute path accidentally instead of a relative one?
I.e. /data/train/ instead of ./data/train/?

I got the same issue. Is there any other solution for that? @@

Hi! @tjwang888,
Welcome to the PyTorch Community :confetti_ball:

Coming to your question, please make sure that the

  • image types are of supported formats
  • there are images in the directory
  • And that you are passing the path correctly.

If you have checked these 3 and still facing an error.

Show us your StackTrace and output of the ls command for that same path.
Please wrap your code in ```

Thanks :man_technologist:

I think those 3 items you list is OK, but it still showed the error message below:

Traceback (most recent call last):
File “cnn-poc-01.py”, line 37, in
trainloader, testloader = load_split_train_test(data_dir, .2)
File “cnn-poc-01.py”, line 18, in load_split_train_test
train_data = datasets.ImageFolder(datadir, transform=train_transforms)
File “C:\Anaconda3\lib\site-packages\torchvision\datasets\folder.py”, line 209, in init
is_valid_file=is_valid_file)
File “C:\Anaconda3\lib\site-packages\torchvision\datasets\folder.py”, line 97, in init
"Supported extensions are: " + “,”.join(extensions)))
RuntimeError: Found 0 files in subfolders of: …/dataset/wafer_defect/test
Supported extensions are: .jpg,.jpeg,.png,.ppm,.bmp,.pgm,.tif,.tiff,.webp

Thank you for your kindly help. ^^

1 Like

Hi @tjwang888 @Abdelrahman_Mohamed ,
I had the same problem as you. Then I found out you have to set your directory one step before.
For example, you want to read an image /yourfolder/yourcode/yourimage/image.png
You should set at /yourfolder/yourcode/ rather than /yourfolder/yourcode/yourimage. I think that can help you :))

1 Like

This helped me solve my error - thanks!