Your code works as expected:
idx, x, y = next(iter(train_loader))
print(x.shape)
# > torch.Size([10, 1, 224, 224])

idx, x, y = next(iter(test_loader))
print(x.shape)
# > torch.Size([10, 1, 224, 224])