How to iterate over two dataloaders simultaneously using pytorch?

后端 未结 5 616
星月不相逢
星月不相逢 2021-02-06 06:04

I am trying to implement a Siamese network that takes in two images. I load these images and create two separate dataloaders.

In my loop I want to go through both datalo

5条回答
  •  别那么骄傲
    2021-02-06 06:35

    If you want to iterate over two datasets simultaneously, there is no need to define your own dataset class just use TensorDataset like below:

    dataset = torch.utils.data.TensorDataset(dataset1, dataset2)
    dataloader = DataLoader(dataset, batch_size=128, shuffle=True)
    for index, (xb1, xb2) in enumerate(dataloader):
        ....
    

    If you want the labels or iterating over more than two datasets just feed them as an argument to the TensorDataset after dataset2.

提交回复
热议问题