quaterion.loss.center_loss module

class CenterLoss(embedding_size: int, num_groups: int, lambda_c: float | None = 0.5)[source]

Bases: GroupLoss

Center Loss as defined in the paper “A Discriminative Feature Learning Approach for Deep Face Recognition” ( It aims to minimize the intra-class variations while keeping the features of different classes separable.

  • embedding_size – Output dimension of the encoder.

  • num_groups – Number of groups (classes) in the dataset.

  • lambda_c – A regularization parameter that controls the contribution of the center loss.

forward(embeddings: Tensor, groups: LongTensor) Tensor[source]

Compute the Center Loss value.

  • embeddings – shape (batch_size, vector_length) - Output embeddings from the encoder.

  • groups – shape (batch_size,) - Group (class) ids associated with embeddings.


Tensor – loss value.

training: bool


Learn more about Qdrant vector search project and ecosystem

Discover Qdrant

Similarity Learning

Explore practical problem solving with Similarity Learning

Learn Similarity Learning


Find people dealing with similar problems and get answers to your questions

Join Community