Based on the error message I guess your model output is a 4D tensor in the shape [batch_size, nb_classes, height, width] while the target has the shape [batch_size] and would thus indicate a multi-class classification use case.
In case that’s indeed the use case, make sure your model returns an output in the shape [batch_size, nb_classes] e.g. by using an nn.Linear layer as the last layer in the model.