Before the batch size was bigger than 1 yes!
I then changed for batch_size = 1 as you suggested!
For example, for batch_size = 2, for several iterations in the dataloader,  the shapes were as following:
image shape:  torch.Size([2, 3, 300, 300])
target shape:  torch.Size([2])