Are x_train, y_train, x_val, y_val batched inputs or only a single sample? That may explain the shape/batch error.
Also, is this is an image autoencoder? If it is, then:

Normalize your inputs
No need to pass targets as long.
Use MSELoss() as criterion