"RuntimeError: Found 0 files in subfolders of ".. Error about subfolder in Pytorch

I met the same problem when using celebA, including 200,000 images. As we can see there are many images. But in a small sample situation (I tried 20 images), I checked, the error will not be raised, which means we can read images successfully. But when the number grows, we should use other methods.

I solved the problem according to this website. Thanks to QimingChen Github solution

Simply, adding another folder named 1 (/train/--->train/1/) in the original folder will enable our program to work, without changing the path. That's because when facing large datasets, images should be sorted in subfolders of different classes.

The Original answer on Github:

Let's say I am going to use ImageFolder("/train/") to read jpg files in folder train. The file structure is /train/ -- 1.jpg -- 2.jpg -- 3.jpg

I failed to load them, leading to errors: RuntimeError: Found 0 images in subfolders of: ./data Supported image extensions are: .jpg,.JPG,.jpeg,.JPEG,.png,.PNG,.ppm,.PPM,.bmp,.BMP

I read the solution above and tried tens of times. When I changed the structure to /train/1/

-- 1.jpg -- 2.jpg -- 3.jpg

But the read in code is still -- ImageFolder("/train/"), IT WORKS.

It seems like the program tends to recursively read in files, that is convenient in some cases.

Hope this would help!!


Can you post the structure of your files? In your case, it is supposed to be:

img_dir
|_class1
  |_a.jpg
  |_b.jpg
|_class2
  |_a.jpg
  |_b.jpg
...

According to the rules of the DataLoader in pytorch you should choose the the superior path of the image path. That means if your images locate in './Dataset/images/', the path of the data loader should be './Dataset' instead. I hope it can fix your bug.:)