Content of dataloader?

Hi could someone explain the content of dataloader?

Example from Google Colab notebook, they use

for image_batch, _ in train_dataloader:

What is “_” here? If I print it, it shows

tensor([4, 5, 3, 9, 0, 4, 4, 1, 1, 3, 8, 7, 4, 9, 4, 1, 0, 0, 0, 0, 7, 1, 1, 6,
        4, 9, 1, 6, 6, 2, 3, 3, 8, 4, 6, 3, 1, 8, 1, 7, 7, 2, 4, 5, 3, 4, 9, 7,
        1, 0, 1, 4, 7, 5, 1, 0, 5, 0, 7, 9, 5, 4, 0, 8, 5, 6, 1, 1, 3, 1, 7, 2,
        4, 4, 0, 2, 6, 8, 4, 6, 2, 4, 5, 5, 3, 7, 7, 6, 2, 7, 4, 6, 6, 0, 6, 0,
        0, 7, 1, 9, 7, 6, 3, 8, 2, 0, 5, 9, 3, 5, 7, 5, 1, 6, 7, 8, 2, 7, 2, 5,
        9, 8, 8, 6, 6, 2, 1, 2])

Hi @arcoyk,

the train_dataloader iterates over the MNIST dataset, so it returns pairs composed of image_batch and label_batch.

For further details, look here.

@fpozzi Thank you for quick rep!

Follow up memo to someone who wondered this line.

Why

train_dataloader[0]

isn’t allowed though

for image_batch, _ in train_dataloader

is allowed.

This is because train_dataloader uses custom iterator torch.utils.data.dataloader._SingleProcessDataLoaderIter.

You can get an element (though not recommended)

t = train_dataloader.__iter__()
a, b = t.next()