espnet2.spk.loss.aamsoftmax.AAMSoftmax
Less than 1 minute
espnet2.spk.loss.aamsoftmax.AAMSoftmax
class espnet2.spk.loss.aamsoftmax.AAMSoftmax(nout: int, nclasses: int, margin: float = 0.3, scale: int = 15, easy_margin: bool = False, **kwargs)
Bases: AbsLoss
Additive angular margin softmax.
Reference: ArcFace: Additive Angular Margin Loss for Deep Face Recognition https://arxiv.org/pdf/1801.07698
- Parameters:
- nout – Dimension of input features (embedding size)
- nclasses – Number of output classes
- margin – Angular margin for positive samples
- scale – Feature scaling factor
- easy_margin – Whether to use easy margin variant
Initializes internal Module state, shared by both nn.Module and ScriptModule.
forward(input: Tensor, label: Tensor | None = None) → Tuple[Tensor | None, Tensor | None, Tensor]
Forward pass of AAMSoftmax loss.
- Parameters:
- input – Input embeddings, shape (batch_size, embedding_dim)
- label – Ground truth labels, shape (batch_size,)
- Returns: Cross-entropy loss with angular margins accuracy: Classification accuracy preds: Predicted class indices
- Return type: loss