Modules

Li-ArcFace

class torchflare.modules.LiArcFace(*args: Any, **kwargs: Any)[source]

Implementation of Li-ArcFace.

Parameters
  • in_features – Size of the input features

  • out_features – The size of output features(usually number of num_classes)

  • s – The norm for input features.

  • m – margin

forward(features: torch.Tensor, targets: Optional[torch.Tensor] = None) torch.Tensor[source]

Forward Pass.

Parameters
  • features – The input features of shape (BS x F) where BS is batch size and F is input feature dimension.

  • targets – The targets with shape BS , where BS is batch size

Returns

Logits with shape (BS x out_features)

Additive Margin Softmax

class torchflare.modules.AMSoftmax(*args: Any, **kwargs: Any)[source]

Implementation of Additive Margin Softmax.

Parameters
  • in_features – Size of the input features

  • out_features – The size of output features(usually number of num_classes)

  • s – The norm for input features.

  • m – margin

forward(features: torch.Tensor, targets: Optional[torch.Tensor] = None) torch.Tensor[source]

Forward Pass.

Parameters
  • features – The input features of shape (BS x F) where BS is batch size and F is input feature dimension.

  • targets – The targets with shape BS , where BS is batch size

Returns

Logits with shape (BS x out_features)

ArcFace

class torchflare.modules.ArcFace(*args: Any, **kwargs: Any)[source]

Implementation of ‘ArcFace Loss <https://arxiv.org/abs/1801.07698>`_.

Parameters
  • in_features – Size of the input features

  • out_features – The size of output features(usually number of num_classes)

  • s – The norm for input features.

  • m – margin

forward(features: torch.Tensor, targets: Optional[torch.Tensor] = None) torch.Tensor[source]

Forward Pass.

Parameters
  • features – The input features of shape (BS x F) where BS is batch size and F is input feature dimension.

  • targets – The targets with shape BS , where BS is batch size

Returns

Logits with shape (BS x out_features)

CosFace

class torchflare.modules.CosFace(*args: Any, **kwargs: Any)[source]

Implementation of CosFace Loss.

Parameters
  • in_features – Size of the input features

  • out_features – The size of output features(usually number of num_classes)

  • s – The norm for input features.

  • m – margin

forward(features: torch.Tensor, targets: Optional[torch.Tensor] = None) torch.Tensor[source]

Forward Pass.

Parameters
  • features – The input features of shape (BS x F) where BS is batch size and F is input feature dimension.

  • targets – The targets with shape BS , where BS is batch size

Returns

Logits with shape (BS x out_features)

Squeeze and Excitation - CSE

class torchflare.modules.CSE(*args: Any, **kwargs: Any)[source]

Implementation of Channel Wise Squeeze and Excitation Block.

Paper : https://arxiv.org/abs/1709.01507

Adapted from https://www.kaggle.com/c/tgs-salt-identification-challenge/discussion/65939 and https://www.kaggle.com/c/tgs-salt-identification-challenge/discussion/66178

__init__(in_channels: int, r: int = 16)[source]

Constructor for CSE class.

Parameters
  • in_channels (int) – The number of input channels in the feature map.

  • r (int) – The reduction ration (Default : 16)

forward(x: torch.Tensor) torch.Tensor[source]

Forward Method.

Parameters

x (torch.Tensor) – The input tensor of shape (batch, channels, height, width)

Returns

Tensor of same shape

Squeeze and Excitation - SSE

class torchflare.modules.SSE(*args: Any, **kwargs: Any)[source]

SSE : Channel Squeeze and Spatial Excitation block.

Paper : https://arxiv.org/abs/1803.02579

Adapted from https://www.kaggle.com/c/tgs-salt-identification-challenge/discussion/66178

__init__(in_channels)[source]

Constructor method for SSE class.

Parameters

in_channels (int) – The number of input channels in the feature map.

forward(x) torch.Tensor[source]

Forward Method.

Parameters

x (torch.Tensor) – The input tensor of shape (batch, channels, height, width)

Returns

Tensor of same shape

Squeeze and Excitation - SCSE

class torchflare.modules.SCSE(*args: Any, **kwargs: Any)[source]

Implementation of SCSE : Concurrent Spatial and Channel Squeeze and Channel Excitation block.

Paper : https://arxiv.org/abs/1803.02579

Adapted from https://www.kaggle.com/c/tgs-salt-identification-challenge/discussion/66178

__init__(in_channels, r=16)[source]

Constructor for SCSE class.

Parameters
  • in_channels (int) – The number of input channels in the feature map.

  • r (int) – The reduction ration (Default : 16)

forward(x) torch.Tensor[source]

Forward method.

Parameters

x (torch.Tensor) – The input tensor of shape (batch, channels, height, width)

Returns

Tensor of same shape