dset.ImageFolder Error: Found 0 files in subfolders of: /pathLocation Supported extensions are: .jpg,.jpeg,.png,.ppm,.bmp,.pgm,.tif

I downloaded the jpg images for DCGAN pytorch tutorial (DCGAN Tutorial — PyTorch Tutorials 2.2.0+cu121 documentation) and the ipynb cannot find the files.

pathLocation

I made sure the path location is in the right location

# Root directory for dataset
dataroot = "/home/paperspace/Label_YT_Videos/code/img_align_celeba/"
dataset = dset.ImageFolder(root=dataroot,
                           transform=transforms.Compose([
                               transforms.Resize(image_size),
                               transforms.CenterCrop(image_size),
                               transforms.ToTensor(),
                               transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
                           ]))

yet I get the following error

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-6-e26dc739e9e3> in <module>()
      7                                transforms.CenterCrop(image_size),
      8                                transforms.ToTensor(),
----> 9                                transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
     10                            ]))
     11 

~/anaconda3/envs/fastai/lib/python3.6/site-packages/torchvision/datasets/folder.py in __init__(self, root, transform, target_transform, loader)
    176         super(ImageFolder, self).__init__(root, loader, IMG_EXTENSIONS,
    177                                           transform=transform,
--> 178                                           target_transform=target_transform)
    179         self.imgs = self.samples

~/anaconda3/envs/fastai/lib/python3.6/site-packages/torchvision/datasets/folder.py in __init__(self, root, loader, extensions, transform, target_transform)
     77         if len(samples) == 0:
     78             raise(RuntimeError("Found 0 files in subfolders of: " + root + "\n"
---> 79                                "Supported extensions are: " + ",".join(extensions)))
     80 
     81         self.root = root

RuntimeError: Found 0 files in subfolders of: /home/paperspace/Label_YT_Videos/code/img_align_celeba/
Supported extensions are: .jpg,.jpeg,.png,.ppm,.bmp,.pgm,.tif

From the tutorial:

This is an important step because we will be using the ImageFolder dataset class, which requires there to be subdirectories in the dataset’s root folder. Now, we can create the dataset, create the dataloader, set the device to run on, and finally visualize some of the training data.

try setting the dataroot as "/home/paperspace/Label_YT_Videos/code/"

1 Like

But how will the program find the path for img_align_celeba?

ImageFolder ought to try and read from all the subfolders from root

What if the directory I’m on has other data irrelevant to the tutorial? Honestly I’ll probaby have a folder within the data folder since the concept is a bit convoluted in my opinion. Your explanation worked tho. Thanks!

I have created an extra folder, too. But I also would be interested in why it is solved that way? @rchavezj’s question is also what I am wondering about…

1 Like