Technically there should be no difference but it looks like in code 1, you are doing the concatenation at dim=0. This could cause issues,
Say two image dims are,
x1 -> 32x32x3
x2 -> 32x32x3

Doing code 1 will provide the following dims,
images -> 64x32x3

You need to unsqueeze it first at dim=0. This would make the dims as follows,
x1 -> 1x32x32x3
x2 -> 1x32x32x3
images -> 2x32x32x3

This wont be an issue in code 2 as the images are handled individually. Let me know if that’s the case.