The stack trace and the posted code don’t show the valid ranges, but nn.CrossEntropyLoss expects a model output of the shape [batch_size, nb_classes, height, width] and a target of [batch_size, height, width] containing the class indices in the range [0, nb_classes-1] for a multi-class segmentation use case.