Thank you @ptrblck , my mistake was I was trying to print the shape by printing train_loader.dataset.data.shape which is different when you iterate through the for loop or next() because it calls getitem which involves the transforms.