FileNotFoundError: torchvision.datasets.ImageFolder using WSL path

I am trying to run some python code in WSL but it seems like it’s unable to find the WSL path?

trainset = torchvision.datasets.ImageFolder(root='/mnt/d/Projects/Datasets/CUB_200_2011/train',
Traceback (most recent call last):
  File "", line 44, in <module>
    trainset = torchvision.datasets.ImageFolder(root='/mnt/d/Projects/Datasets/CUB_200_2011/train',
  File "/mnt/d/Projects/Papers/Mutual-Channel-Loss/cub-env/lib/python3.8/site-packages/torchvision/datasets/", line 310, in __init__
  File "/mnt/d/Projects/Papers/Mutual-Channel-Loss/cub-env/lib/python3.8/site-packages/torchvision/datasets/", line 145, in __init__
    classes, class_to_idx = self.find_classes(self.root)
  File "/mnt/d/Projects/Papers/Mutual-Channel-Loss/cub-env/lib/python3.8/site-packages/torchvision/datasets/", line 219, in find_classes
    return find_classes(directory)
  File "/mnt/d/Projects/Papers/Mutual-Channel-Loss/cub-env/lib/python3.8/site-packages/torchvision/datasets/", line 43, in find_classes
    raise FileNotFoundError(f"Couldn't find any class folder in {directory}.")
FileNotFoundError: Couldn't find any class folder in /mnt/d/Projects/Datasets/CUB_200_2011/train.

However, if I run a simple python console and os.listdir for the same path, it returns results.

>>> print(len(os.listdir('/mnt/d/Projects/Datasets/CUB_200_2011/train')))

I am not sure if this is a python issue not recognizing WSL file paths, or a pytorch issue - I have previously developed on WSL and not run into this issue.

System info -

Python 3.10
PyTorch 1.12.1
torch 1.12.1+cu116
torchaudio 0.12.1+cu116
torchvision 0.13.1+cu116

What exactly is stored in this path? ImageFolder expects subfolders for each class containing the images. Your test code shows that 5794 entries are detected, but in case these are not folders, ImageFolder would still fail.

1 Like

This is probably it! the entries are not folders, they are just raw images. On reading the error again, “couldn’t find any class folder” this error makes more sense. It’s looking for images split by folders per class.