In your datasets you are flattening the tensors via:
data = data.view(1, -1)

which seems wrong, as the expected shape of a color image tensor would be [3, height, width].
Could you check the shape of X_train etc. before passing them to the dataset and make sure the image shape is correct?