Reputation: 586
I'm trying to experiment on Google Colab with CNNs and GANs using the CelebA dataset. I'm trying to load in the data in PyTorch using ImageFolder
like so:
# Loading in data
dataroot = "/content/drive/MyDrive/Colab_Notebooks/celeba/img_align_celeba.zip"
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)),
]))
Bear in mind, I've fully mounted my drive and have the celeba.zip file on my G-Drive. However, when trying to execute the above, I get the following error:
---------------------------------------------------------------------------
NotADirectoryError Traceback (most recent call last)
<ipython-input-13-ebc6bb8ab4bd> in <module>()
10 transforms.CenterCrop(image_size),
11 transforms.ToTensor(),
---> 12 transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
13 ]))
3 frames
/usr/local/lib/python3.7/dist-packages/torchvision/datasets/folder.py in find_classes(directory)
38 See :class:`DatasetFolder` for details.
39 """
---> 40 classes = sorted(entry.name for entry in os.scandir(directory) if entry.is_dir())
41 if not classes:
42 raise FileNotFoundError(f"Couldn't find any class folder in {directory}.")
NotADirectoryError: [Errno 20] Not a directory: '/content/drive/MyDrive/Colab_Notebooks/celeba/img_align_celeba.zip'
Unless I'm missing something, my dataroot
variable is the correct directory as it's the correct path to the zip containing the images. I've attempted to unzip the files by doing:
!cp "{dataroot}" .
!yes|unzip -q img_align_celeba.zip
but I still get the same error - am I missing something?
Upvotes: 0
Views: 8412
Reputation: 6567
Zip files aren't folders. Try unzipping first although you'll need to cd to the folder first - so something like this.
!cd /content/drive/MyDrive/Colab_Notebooks/celeba
Then unzip
!yes|unzip -q img_align_celeba.zip -d img_align_celeba
Then this should work.
dataroot = '/content/drive/MyDrive/Colab_Notebooks/celeba/img_align_celeba'
dataset = ImageFolder(root = dataroot, transform=transform)
Upvotes: 1