Thanks for the code.
Your DataLoader returns a data and target batch, so either unwrap it in the loop:
for batch in train_dataset2:
    data = batch[0]
    target = batch[1]

or assign the two variables in the loop statement:
for data, target in train_dataset2:
    ...

Also, I would recommend to name the DataLoader something like train_loader so avoid confusion.