Combine serveral datasets

Hi,
we want to train a DNN on a dataset, which consists of multiple datasets. Each dataset is a folder and has it’s own label. Now we have to combine these datasets, but don’t know, how to do this.
Folder structure:
root consists of -> multiple subfolders always consists of -> multiple sub-subfolders always consists of -> pictures
Our idea (example with two datasets):
We load two datasets as trochvision.ImageFolder and combinde them with ConcatDataset.

datadir = “…/data/dir1…”
datadir2= “…/data/dir2…:”
train_transforms = transforms.Compose([transforms.Resize(224),
transforms.ToTensor(), ])
train_data = datasets.ImageFolder(datadir,
transform=train_transforms)
trainloader = torch.utils.data.DataLoader(train_data,
batch_size=64)
train_data = ConcatDataset((datasets.ImageFolder(datadir2),datasets.ImageFolder(datadir)))

But now, we are not able to get the labels via “print(trainloader.dataset.classes)” or
“for values,labels in trainloader:
print(labels)”
Is there a way to combine multiple datasets while keeping the labels?

We would be very greatful for an answer!
Thanks!!

(this maybe helps to understand our folder structure):