FileNotFoundError: Couldn't find any class folder

Hello,

I’m trying to follow the DCGAN tutorial on PyTroch on Google Colab however I keep coming across this FileNotFoundError. I’m loading in data like so:

# Loading in data

dataroot = "/content/drive/MyDrive/Colab_Notebooks/celeba"
!cd /content/drive/MyDrive/Colab_Notebooks/celeba 

!unzip -q /content/drive/MyDrive/Colab_Notebooks/celeba/img_align_celeba.zip -d 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)),                    
                           ]))

I’m unzipping the zip that I downloaded into my G-Drive. I understand that ImageFolder expects subdirectories in the data’s root folder as stated here however I’m still unsure whether it can handle zip file formats or requires them to be unzipped first? Furthermore, what if my dataset images do not have a particular like in my example where they are just facial images.

ImageFolder expects to find valid image files in each subfolder and won’t unzip nested folders first.

I assume you are asking about a use case which doesn’t provide image files in each subfolder?
If so, you could write a custom Dataset as explained here.

Hi @ptrblck - thanks for replying.

ImageFolder expects to find valid image files in each subfolder and won’t unzip nested folders first.

Does it expect subfolders to be labelled such as test, train etc or is the requirement that images only exist in a subfolder? If I unzip the file provided in this PyTroch demo (DCGAN Tutorial — PyTorch Tutorials 2.1.1+cu121 documentation) it produces a folder with all images inside - i.e. not separate into subfolders. The confusion occurs when it states the …ImageFolder dataset class, which requires there to be subdirectories in the dataset’s root folder.

ImageFolder will assign a class index to each subfolder. Usually you would thus have subfolders in the train and test folders. If you pass the root folder of train and test to ImageFolder these two folders will have a target value of 0 and 1, respectively.

As you can see in the tutorial, the target is never used and the input sample is used via data[0].
If you don’t want to use the targets, ImageFolder would still be a valid approach as it would still load all samples in the subfolder(s).

The folder doesn’t have any folder except the folder ’ img_align_celeba’

dataroot = "/content/drive/MyDrive/Colab_Notebooks"