BatchNorm2d, ValueError: expected 4D input (got 2D input)

It means the images in your dataset do not have same sizes but I can see you are using transforms.Resize(256). I really cannot figure out, maybe some of your images are not in same mode such as RGB?

I think it would be much easier if you define your own custom dataset loader. You will have full control over data loading. dataloading tutorial

This is a post for similar case: Custom Dataset with some preprocessing

1 Like