Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Torchvision ImageFolder "Could not find any class folder"

The code below

plastic_train_image_folder = torchvision.datasets.ImageFolder(plastic_dir, transform=transforms)

throws the following error:

Could not find any any class folder in /Users/username/Documents/Jupyter/archive/Garbage classification/Garbage classification/plastic.

Yet, there are files there. The code below prints 482.

list_plastic = os.listdir(plastic_dir) 
number_files_plastic = len(list_plastic)
print(number_files_plastic)

Why is this error happening?

like image 604
Ali Fakhry Avatar asked Oct 28 '25 06:10

Ali Fakhry


1 Answers

As you can see in the documentation, the ImageFolder class expects images to be within directories, one for each class of interest:

A generic data loader where the images are arranged in this way:

root/dog/xxx.png
root/dog/xxy.png
root/dog/xxz.png

root/cat/123.png
root/cat/nsdf3.png
root/cat/asd932_.png

Your images are probably in the root directory, which is not the way it is expecting, hence the error.

like image 143
Berriel Avatar answered Oct 31 '25 12:10

Berriel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!