Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageFolder throws false error by loading from nested PATH #669

Closed
weisurya opened this issue Nov 23, 2018 · 1 comment
Closed

ImageFolder throws false error by loading from nested PATH #669

weisurya opened this issue Nov 23, 2018 · 1 comment

Comments

@weisurya
Copy link

weisurya commented Nov 23, 2018

Environment
OS: Windows 10 64-bit
torch: 0.4.1
torchvision: 0.2.1

Code_1
`
import torch
from torchvision import datasets, transforms

data_dir = "PetImages/Dog"

transform = transforms.Compose([transforms.Resize(255), transforms.CenterCrop(224), transforms.ToTensor()])

dataset = datasets.ImageFolder(root=data_dir, transform=transform)

dataloader = torch.utils.data.DataLoader(dataset, batch_size=32, shuffle=True)
`

Output_1
`

RuntimeError Traceback (most recent call last)
in
5 transforms.ToTensor()])
6
----> 7 dataset = datasets.ImageFolder(root=data_dir, transform=transform)
8
9 dataloader = torch.utils.data.DataLoader(dataset, batch_size=32, shuffle=True)

d:\programs\anaconda3\envs\deep-learning\lib\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

d:\programs\anaconda3\envs\deep-learning\lib\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: PetImages/Dog
Supported extensions are: .jpg,.jpeg,.png,.ppm,.bmp,.pgm,.tif
`

However, when I tried to read the image file, it works

Code_2
`

Test data loader

images, labels = next(iter(dataloader))
plt.imshow(images[0].numpy().transpose((1, 2, 0)))
`

Output_2
https://drive.google.com/file/d/109-Uw5YYXJ0Nij2RIhFAdEorOKgqcXHM/view?usp=sharing

Directory
petImages/
___Cat/
______0.jpg
______1.jpg
______2.jpg

@fmassa
Copy link
Member

fmassa commented Nov 23, 2018

You should put as a path to data_dir PetImages.

If you only want to have a single class even though PetImages have many folders, you can create a symlink pointing to the single folder you want.

@fmassa fmassa closed this as completed Nov 23, 2018
Cam2337 added a commit to Cam2337/RecycleNet-DCGAN that referenced this issue Jun 6, 2020
Note that, since we perform synthesis on a single directory at a time,
the PyTorch ImageFolder expects a directory structure like the
following:
```
+ metal-root/
  |-+ metal/
```

Making these alterations to trashnet/data/dataset-resized, however,
would require additional modifications to the trashnet source code to
account for the new directory structure during trashnet
training/validation/test. As such, we opt for the suggested fix as
mentioned by: pytorch/vision#669.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants