How to access all the labels at once from dataloader?

I have the dataloaders as such

train_dl=, batch_size=32, sampler=train_sampler)
val_dl =, batch_size=32, sampler=valid_sampler)

I finished training the model and now I want to get the entire list of labels from val_dl to calculate
confusion_matrix(val_labels, y_pred_tag) . How do I do that ?
Please help !

You could store the labels with the predictions while iterating the val_dl.

1 Like