How to find data_index from ConcatDataset?

Here is my codes.

trains = []
trains.append(datasets.ImageFolder(Data1_path)
trains.append(datasets.ImageFolder(Data2_path)
datasets = torch.utils.data.ConcatDataset(trains)
train_loader = torchdata.DataLoader(datasets , batch_size=args.batch_size, shuffle=True, num_workers=args.workers, drop_last=True) # Shuffle here.
for i, 'data' in enumerate(train_loader):
    train with 'data'
-> I want to know where this 'data' comes from... 
-> Data1 or Data2 ? How can I know this?
...
Here is data structure.
Data1_path: 
/dataset/data1/cat
/dataset/data1/dog
, ...

Data2_path: 
/dataset/data2/cat
/dataset/data2/dog
, ...

I want to know where this ‘data’ comes from… Data1 or Data2 ? How can I know this?

As per the source code for ConcatDataSet, your datasets object has an attribute called cumulative_sizes that contains information which can help you figure this out. Try querying cumulative_sizes and see if it gives you something useful.