Hi everyone,
I have the following problem:
I have 2 different dataset of images, targets; in principle the 2 dataset may have different number of samples, I need to:


Mantain divided the element of the 2 dataset, i.e. inside a generic batch only element of a single dataset has to appear


iterate on both dataset in the same time, i.e. at each step select one batch for each dataset, perform some operations, and then pass to the next couple of batches


The solution that I found so far is the following:
using torch.utils.data.TensorDataset to wrap both the dataset and torch.utils.data.DataLoader to itarete throught them
        x0, y0 = [], []
        for x, y in train_data0:
            
            x0.append(x)
            y0.append(y)
        x1, y1 = [], []
        for x, y in train_data1:
            
            x1.append(x)
            y1.append(y)
        
        
        totdataset =  torch.utils.data.TensorDataset(torch.stack(x0), torch.tensor(y0), torch.stack(x1), torch.tensor(y1))
        dataloader = torch.utils.data.DataLoader(totdataset, batch_size=10, shuffle = True, num_workers = 1)
for index, (a, b, c, d) in enumerate(dataloader):
#here some operation on the 2 datasets' batches

the problem now is that if train_data0 and train_data1 has different number of elements, since the batch size is the same for each tensor (10 in the above example) I’ll have different number of batches for the 2 dataset ending in a Size mismatch between tensors entering in the for cycle  (last line)
How can I solve this problem?
Is there a way to fix the number of batches instead of the batch sizes for the dataloader input tensors?
Is there a different (easy) way to solve my initial problem?