gunz_ml.metrics.classification package

Submodules

gunz_ml.metrics.classification.adacos module

class gunz_ml.metrics.classification.adacos.AdaCos(num_features, num_classes, m=0.5)[source]

Bases: Module

AdaCos: Adaptively Scaling Cosine Logits for Effectively Learning Deep Face Representations.

Reference:

Zhang, X., Zhao, R., Qiao, Y., Wang, X., & Li, H. (2019). AdaCos: Adaptively Scaling Cosine Logits for Effectively Learning Deep Face Representations. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR).

Parameters:
  • num_features (int) – Number of input features (dimension of the embedding).

  • num_classes (int) – Number of classes for classification.

  • m (float, optional) – Margin parameter. Defaults to 0.50.

forward(input, label=None)[source]

Forward pass of AdaCos.

Parameters:
  • input (torch.Tensor) – Input features with shape (batch_size, num_features).

  • label (torch.Tensor, optional) – Ground truth labels with shape (batch_size,). If None, returns raw logits.

Returns:

Scaled logits with shape (batch_size, num_classes).

Return type:

torch.Tensor

gunz_ml.metrics.classification.arcface module

class gunz_ml.metrics.classification.arcface.ArcFace(num_features, num_classes, s=30.0, m=0.5)[source]

Bases: Module

ArcFace: Additive Angular Margin Loss for Deep Face Recognition.

Reference:

Deng, J., Guo, J., Xue, N., & Zafeiriou, S. (2019). ArcFace: Additive Angular Margin Loss for Deep Face Recognition. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR).

Parameters:
  • num_features (int) – Number of input features (dimension of the embedding).

  • num_classes (int) – Number of classes for classification.

  • s (float, optional) – Scaling factor. Defaults to 30.0.

  • m (float, optional) – Angular margin penalty. Defaults to 0.50.

forward(input, label=None)[source]

Forward pass of ArcFace.

Parameters:
  • input (torch.Tensor) – Input features with shape (batch_size, num_features).

  • label (torch.Tensor, optional) – Ground truth labels with shape (batch_size,). If None, returns raw logits.

Returns:

Scaled logits with shape (batch_size, num_classes).

Return type:

torch.Tensor

gunz_ml.metrics.classification.cosface module

class gunz_ml.metrics.classification.cosface.CosFace(num_features, num_classes, s=30.0, m=0.35)[source]

Bases: Module

CosFace: Large Margin Cosine Loss for Deep Face Recognition.

Reference:

Wang, H., Wang, Y., Zhou, Z., Ji, X., Gong, D., Zhou, J., … & Liu, W. (2018). CosFace: Large Margin Cosine Loss for Deep Face Recognition. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR).

Parameters:
  • num_features (int) – Number of input features (dimension of the embedding).

  • num_classes (int) – Number of classes for classification.

  • s (float, optional) – Scaling factor. Defaults to 30.0.

  • m (float, optional) – Cosine margin penalty. Defaults to 0.35.

forward(input, label=None)[source]

Forward pass of CosFace.

Parameters:
  • input (torch.Tensor) – Input features with shape (batch_size, num_features).

  • label (torch.Tensor, optional) – Ground truth labels with shape (batch_size,). If None, returns raw logits.

Returns:

Scaled logits with shape (batch_size, num_classes).

Return type:

torch.Tensor

gunz_ml.metrics.classification.sphereface module

class gunz_ml.metrics.classification.sphereface.SphereFace(num_features, num_classes, s=30.0, m=1.35)[source]

Bases: Module

SphereFace: Deep Hypersphere Embedding for Face Recognition.

Reference:

Liu, W., Wen, Y., Yu, Z., Li, M., Raj, B., & Song, L. (2017). SphereFace: Deep Hypersphere Embedding for Face Recognition. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR).

Parameters:
  • num_features (int) – Number of input features (dimension of the embedding).

  • num_classes (int) – Number of classes for classification.

  • s (float, optional) – Scaling factor. Defaults to 30.0.

  • m (float, optional) – Angular margin multiplicative factor. Defaults to 1.35.

forward(input, label=None)[source]

Forward pass of SphereFace.

Parameters:
  • input (torch.Tensor) – Input features with shape (batch_size, num_features).

  • label (torch.Tensor, optional) – Ground truth labels with shape (batch_size,). If None, returns raw logits.

Returns:

Scaled logits with shape (batch_size, num_classes).

Return type:

torch.Tensor