The code looks generally alright.
I would suggest to loop once over the complete dataset and check, if the returned batches are indeed tensors or if at some index a str object might be returned.
If this works, then you should check, if you are reassigning input somewhere in your code to a str.