How to load image dataset in pytorch for CNN classification

I want to use CNN to classify images into 5 classes with my dataset. Each class have 5000 images in separate folder. How to load this dataset into pytorch ? I am stuck here from past few days. plz help.

1 Like

You could use torchvision.dataset.ImageFolder or create a custom Dataset to load your images.

1 Like

Imagine that you have a folder called my_directory, in this folder you have 2 folders (cat - dog) that contains images of cat and dogs.

you can load theses images like this :

train_data = datasets.ImageFolder('my_directory', transform=transform)

And ImageFolder will automatically assigne the label cat and dog to the right images.