quaterion.loss.cos_face_loss module¶
- class CosFaceLoss(embedding_size: int, num_groups: int, margin: float | None = 0.35, scale: float | None = 64.0)[source]¶
Bases:
GroupLoss
Large Margin Cosine Loss as defined in https://arxiv.org/pdf/1801.09414.pdf
- Parameters:
embedding_size – Output dimension of the encoder.
num_groups – Number of groups in the dataset.
scale – Scaling value to make cross entropy work.
margin – Margin value to push groups apart.
- forward(embeddings: Tensor, groups: LongTensor) Tensor [source]¶
Compute loss value :param embeddings: shape: (batch_size, vector_length) - Output embeddings from the
encoder.
- Parameters:
groups – shape: (batch_size,) - Group ids associated with embeddings.
- Returns:
Tensor – loss value.
- training: bool¶