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
Initialize 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
