The batch contains the images, boxes and labels. When I change it like this, it works.
    img=batch[0]
    b=batch[1]
    labels=batch[2]
    return img,b,labels

But it changes the order of img, b, labels every time, so img is sometimes batch[0], sometimes batch[1]… and I don’t know really why.
Is that, because I have shuffle=True in the following line?
   train_data=torch.utils.data.DataLoader(train_dataset, batch_size, shuffle=True, collate_fn=my_collate)
So I have to change it in shuffle=False?