Error on enumerate(dataloader)

Hello, this my code yet when I run it I have this error appear.
def train_step(model: torch.nn.Module,
loss_fn: torch.nn.Module,
optimizer: torch.optim.Optimizer):
# Put model in train mode
model =

# Setup train loss and train accuracy values
train_loss= 0

# Loop through data loader data batches
for i, data in enumerate(dataloader):
    img, patches, _ = data

    patches = patches.cuda()

    # 1. Forward pass
    pat_pred = model(patches)

    # 2. Calculate  and accumulate loss
    loss = loss_fn(pat_pred, patches)
    train_loss += loss.item() 

    # 3. Optimizer zero grad

    # 4. Loss backward

    # 5. Optimizer step

# Adjust metrics to get average loss  per batch 
train_loss = train_loss / len(dataloader)
return train_loss

the Error:
img, patches, _ = data
18 patches = patches.cuda()
20 # 1. Forward pass

ValueError: too many values to unpack (expected 3)

Based on the error message and the stacktrace it seems data does not contain 3 values so check its len and make sure the unwraping is using the expected number of internally stored objects.

1 Like

Thank you for your response, it did help me overcome the error.