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_predandy_targethave the same shape the target is taken as a distribution andOnehotCrossEntropyLossis used. Otherwise the logits are flattened to[N * ..., C](a tuple output is reduced to its first element), the targets toint64class indices, andnn.CrossEntropyLossis applied.- Returns:
Scalar loss.
- Return type: