Dataloader usage

I am struggling to wrap my head around using the data loader.

Currently I have a data loader which returns a dictionary for x1, x2 objects.

I can call x1, x2 = next(iter(dataloader), which returns the two dictionary objects.

However, my train script it is set up to run the following.

for x1, x2 in dataloader:
x1 = x1[‘image’].cuda()

With this however I get a none type error when reading in the image from the dataset class. I am quite confused why this happens, as i know the dataloader is working from the above example?

I have added

for x1, x2 in next(iter(train_dataloader)):
x1 = x1[‘image’].cuda()
x2 = x2[‘image’].cuda()

Which solves, this first issue, however I now get a

ValueError: not enough values to unpack (expected 2, got 1)

That doesn’t look right and you should iterate the DataLoader directly:

dataset = TensorDataset(torch.randn(10, 1), torch.randn(10, 1))
loader = DataLoader(dataset, batch_size=1)

for x, y in loader:
    print(x, y)

Could you post the Dataset definition, please?