peal.training.criterions.latent_convexity_criterion

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

Mixup in the penultimate feature space (latent-convexity regulariser).

Pairs every latent code with a randomly permuted partner, interpolates the codes and the one-hot targets with a uniform lam per sample, pushes the mixed codes through model.get_last_layer() and scores the result with cross_entropy_criterion(). y_pred is unused; latent_code must be the [N, D] activations the trainer extracted for the batch.

Returns:

Scalar loss.

Return type:

torch.Tensor