0

I just recently posted a question about a file path error in which I thought I resolved... the folder that I have contains .jpg files. For some reason, i'm getting a new error:

RuntimeError: Found 0 files in subfolders of: C:\Users\Lyn\Desktop\UTKFaceDataSet\Train_Set Supported extensions are: .jpg,.jpeg,.png,.ppm,.bmp,.pgm,.tif,.tiff,.webp

Here is my modified code:

data_dir = "C:\\Users\\Lyn\\Desktop\\UTKFaceDataSet"
train_dir = data_dir + '\\Train_Set'
test_dir = data_dir + '\\Test_Set'

training_transforms = transforms.Compose([transforms.Resize(100),
                                          transforms.ToTensor()])
testing_transforms = transforms.Compose([transforms.Resize(256),
                                         transforms.ToTensor()])

#Load the datasets with ImageFolder
training_dataset = datasets.ImageFolder(train_dir, transform=training_transforms)
testing_dataset = datasets.ImageFolder(test_dir, transform=testing_transforms)
desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • Could you try this: `import os; os.path.isdir(train_dir)` and see if it returns `True`? – Ivan Dec 04 '20 at 22:04
  • @Ivan I'll give it a try! Thanks for responding! – Callyn Villanueva Dec 04 '20 at 22:12
  • (^ this was not a solution, just to check your directory actually exists). You can also print out `os.listdir(train_dir)` and tell us what you find. – Ivan Dec 04 '20 at 22:19
  • @Ivan it returns true – Callyn Villanueva Dec 04 '20 at 22:33
  • ok, and what about `listdir`? – Ivan Dec 04 '20 at 22:39
  • @Ivan yes! it prints out all JPG files ex: ['s3.jpg', 's32.jpg', 's34.jpg', 's35.jpg', 's38.jpg', 's4.jpg', 's40.jpg', 's5.jpg', 's6.jpg', 's7.jpg'] – Callyn Villanueva Dec 04 '20 at 22:44
  • Now we need to check that those are actual jpg files. You can do that with `import imghdr; imghdr.what() == jpg`. – Ivan Dec 04 '20 at 22:53
  • @Ivan, im getting an error - [Errno 13] Permission denied: 'C:\\Users\\Lyn\\Desktop\\UTKFaceDataSet\\Test_Set' – Callyn Villanueva Dec 04 '20 at 23:07
  • Have a look here, this might help: https://stackoverflow.com/questions/23870808/oserror-errno-13-permission-denied – Ivan Dec 04 '20 at 23:09
  • As your [previous question](https://stackoverflow.com/questions/65133426/importing-jpg-files-from-a-folder-for-pytorch-transformation) (where I had also edited the tags), this one is about a file/folder access from Python issue, and it has actually nothing to do with `machine-learning` or `deep-learning`; kindly avoid using these tags in similar cases (the ones left here are more than enough). – desertnaut Dec 04 '20 at 23:14

1 Answers1

1

You need your directory structure in the following format to use the datasets.ImageFolder():

dataset
   train_dataset
      dogs
         a.png, b.png
      cats
         c.png, d.png
   valid_dataset
      dogs
         e.png, f.png
      cats
         g.png, h.png
train_dir = 'dataset/train_dataset/'
training_dataset = datasets.ImageFolder(train_dir, transform=training_transforms)

I used two categories (dogs and cats), but it could be one also.

Ivan
  • 34,531
  • 8
  • 55
  • 100
planet_pluto
  • 742
  • 4
  • 15