Since the error might occur inside your dataloader, it would be interesting what kind of data you read and maybe to see your dataset code.
I’ve skimmed through your train code and it looks fine to me.