Either the model output or the target tensor seem to be a scalar tensor (0-dim tensor), so you would have to make sure the model output has the shape [batch_size, nb_classes], while the target has the shape [batch_size] and contains the class indices in [0, nb_classes-1].