无法加载数据Google Colab

时间:2019-08-23 17:00:56

标签: pytorch google-colaboratory

我正在尝试通过kaggle cli下载数据后加载数据。该练习来自有关Udacity的this course

!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/

计算图像数量

!ls '{content}/competitions/dogs-vs-cats/train/' | wc -l
# 25000

然后我尝试加载数据

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

错误

---------------------------------------------------------------------------
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

1 个答案:

答案 0 :(得分:0)

好像您在以错误的方式使用f字符串。只需在此处添加app.get('/links', (req, res) => { Axios.get('http://apiurl') .then((response) => { const { data } = response; const linksStylesheet = new ServerStyleSheet(); const applicationHTML = renderToStaticMarkup(linksStylesheet.collectStyles(<LinkListApp data = {data} />)); res.send(applicationHTML); }) .catch((err) => { }) });

f

data_dir = f'{content}/competitions/dogs-vs-cats/train/' 的值包括在路径中;如果没有content,则仅使用f字符串作为路径,如错误消息所示。