peal.training.criterions.cross_entropy_criterion

peal.training.criterions.cross_entropy_criterion(model, y_pred, y_target, latent_code=None)[source]

Cross-entropy for hard or soft targets.

If y_pred and y_target have the same shape the target is taken as a distribution and OnehotCrossEntropyLoss is used. Otherwise the logits are flattened to [N * ..., C] (a tuple output is reduced to its first element), the targets to int64 class indices, and nn.CrossEntropyLoss is applied.

Returns:

Scalar loss.

Return type:

torch.Tensor