How to use datasets.ImageFolder() for custom datasets?

uppose I have to design a 3 class classifier with following things in mind:

I have 3 folders as datasets such as:

  • …/data/cat/ …/data/dog/ …/data/man/

Each folder has images for that particular class only.

We divide the images into train,test,val using the following:

train_data = datasets.ImageFolder(train_dir, transform=data_transforms[‘train’])

test_data = datasets.ImageFolder(test_dir, transform=data_transforms[‘test’])

My question is how will ImageFolder() divide the images into train,test from EACH class folder as given above??

Also,

img,target = netx(iter(…))

gives the target or label. How is this generated? like how will ImageFolder() assign target=1 when taking image from …/data/cat/ and target=1 when taking from …/data/dog/ etc