Could you print the shape of outputs and targets?
outputs should have the dimensions [batch_size, n_classes, w, h]
while targets this one [batch_size, w, h].
You are indexing it with targets[:, 0], so maybe this yields to the error.