Ah OK, I missed this and thought the code should reproduce the initial error.
The mismatch will most likely be created as you are transforming the data twice in your custom approach.
You are passing the transformations the first time when creating train_dataset and then another transformation to MyDataset, which will be applied again.