Criterion

BCEWithLogitsFlat

class torchflare.criterion.BCEWithLogitsFlat(x: torch.Tensor, y: torch.Tensor)[source]

Same as F.binary_cross_entropy_with_logits but flattens the input and target.

Parameters
  • x – logits

  • y – The corresponding targets.

Returns

The computed Loss

BCEFlat

class torchflare.criterion.BCEFlat(x: torch.Tensor, y: torch.Tensor)[source]

Same as F.binary_cross_entropy but flattens the input and target.

Parameters
  • x – logits

  • y – The corresponding targets.

Returns

The computed Loss

Label Smoothing CrossEntropy Loss

class torchflare.criterion.LabelSmoothingCrossEntropy(*args: Any, **kwargs: Any)[source]

NLL loss with targets smoothing.

Parameters

smoothing

targets smoothing factor

Raises:

ValueError: value error is raised if smoothing > 1.0.

forward(logits: torch.Tensor, target: torch.Tensor) torch.Tensor[source]

Forward method.

Parameters
  • logits – Raw logits from the net.

  • target – The targets.

Returns

The computed loss value.

Symmetric CrossEntropy Loss

class torchflare.criterion.SymmetricCE(*args: Any, **kwargs: Any)[source]

Pytorch Implementation of Symmetric Cross Entropy.

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

Parameters
  • alpha – The alpha value for symmetricCE.

  • beta – The beta value for symmetricCE.

  • num_classes – The number of classes.

forward(logits: torch.Tensor, targets: torch.Tensor) torch.Tensor[source]

Forward method.

Binary Focal Loss

class torchflare.criterion.BCEFocalLoss(*args: Any, **kwargs: Any)[source]

Implementation of Focal Loss for Binary Classification Problems.

Focal loss was proposed in Focal Loss for Dense Object Detection_..

forward(logits: torch.Tensor, targets: torch.Tensor) torch.Tensor[source]

Forward method.

Parameters
  • logits – The raw logits from the network of shape (N,k) where C = number of classes , k = extra dims

  • targets – The targets

Returns

The computed loss value

Focal Loss

class torchflare.criterion.FocalLoss(*args: Any, **kwargs: Any)[source]

Implementation of Focal Loss.

Focal loss was proposed in Focal Loss for Dense Object Detection_..

Parameters
  • gamma – The focal parameter. Defaults to 0.

  • eps – Constant for computational stability.

  • reduction – The reduction parameter for Cross Entropy Loss.

forward(logits: torch.Tensor, targets: torch.Tensor) torch.Tensor[source]

Forward method.

Parameters
  • logits – The raw logits from the network of shape (N,C,k) where C = number of classes and (k) = extra dims

  • targets – The targets of shape (N , k).

Returns

The computed loss value

Triplet Loss

class torchflare.criterion.TripletLoss(*args: Any, **kwargs: Any)[source]

Computes Triplet loss.

Parameters
  • normalize_features – Whether to normalize the features. Default = True

  • margin – The value for margin. Default = None.

  • hard_mining – Whether to use hard sample mining. Default = True.

forward(embedding: torch.Tensor, targets: torch.Tensor) torch.Tensor[source]

Forward Method.

Parameters
  • embedding – The output of the network.

  • targets – The targets.

Returns

The computed Triplet Loss.