Reputation: 1186
I am trying to load data after downloading it through kaggle cli. This exercise is from this course on Udacity.
!kaggle competitions download -c dogs-vs-cats
!unzip {content}/competitions/dogs-vs-cats/train.zip -d {content}/competitions/dogs-vs-cats/
!unzip {content}/competitions/dogs-vs-cats/test1.zip -d {content}/competitions/dogs-vs-cats/
Counting the number of images
!ls '{content}/competitions/dogs-vs-cats/train/' | wc -l
# 25000
Then I try to load the data
data_dir = '{content}/competitions/dogs-vs-cats/train/'
transform = transforms.Compose([transforms.Resize(255),
transforms.CenterCrop(224),
transforms.ToTensor()]) # TODO: compose transforms here
dataset = datasets.ImageFolder(data_dir, transform=transform) # TODO: create the ImageFolder
dataloader = torch.utils.data.DataLoader(dataset,batch_size=32,shuffle=True) # TODO: use the ImageFolder dataset to create the DataLoader
Error
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-70-9c49d0bdcdb0> in <module>()
4 transforms.CenterCrop(224),
5 transforms.ToTensor()]) # TODO: compose transforms here
----> 6 dataset = datasets.ImageFolder(data_dir, transform=transform) # TODO: create the ImageFolder
7 dataloader = torch.utils.data.DataLoader(dataset,batch_size=32,shuffle=True) # TODO: use the ImageFolder dataset to create the DataLoader
1 frames
/usr/local/lib/python3.6/dist-packages/torchvision/datasets/folder.py in __init__(self, root, transform, target_transform, loader, is_valid_file)
207 transform=transform,
208 target_transform=target_transform,
--> 209 is_valid_file=is_valid_file)
210 self.imgs = self.samples
/usr/local/lib/python3.6/dist-packages/torchvision/datasets/folder.py in __init__(self, root, loader, extensions, transform, target_transform, is_valid_file)
95 if len(samples) == 0:
96 raise (RuntimeError("Found 0 files in subfolders of: " + self.root + "\n"
---> 97 "Supported extensions are: " + ",".join(extensions)))
98
99 self.loader = loader
RuntimeError: Found 0 files in subfolders of: {content}/competitions/dogs-vs-cats/train/
Supported extensions are: .jpg,.jpeg,.png,.ppm,.bmp,.pgm,.tif,.tiff,.webp
Upvotes: 0
Views: 1090
Reputation: 8981
Looks like you are using f-strings in a wrong way. Simply add f
here:
data_dir = f'{content}/competitions/dogs-vs-cats/train/'
to include content
value to the path; without f
you are just using {content}/competitions...
string as a path, as you can see in your error message.
Upvotes: 1