nntoolbox.vision.losses.metrics module

class nntoolbox.vision.losses.metrics.AngularLoss(alpha=45)[source]

Bases: torch.nn.modules.module.Module

Based on https://github.com/leeesangwon/PyTorch-Image-Retrieval/blob/public/losses.py

forward(data: Tuple[torch.Tensor, torch.Tensor]) → torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class nntoolbox.vision.losses.metrics.ContrastiveLoss(margin=1.0)[source]

Bases: torch.nn.modules.module.Module

Contrastive loss function.

Based on:

https://github.com/delijati/pytorch-siamese/blob/master/contrastive.py#L20

check_type_forward(in_types)[source]
dist(x_0, x_1, eps=1e-08, squared=False)[source]
forward(data: Tuple[torch.Tensor, ]) → torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class nntoolbox.vision.losses.metrics.NPairAngular(alpha=45, reg_lambda=0.002, angular_lambda=2)[source]

Bases: torch.nn.modules.module.Module

Combining N-Pair loss and Angular loss

forward(data: Tuple[torch.Tensor, torch.Tensor]) → torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class nntoolbox.vision.losses.metrics.NPairLoss(reg_lambda: float = 0.002)[source]

Bases: torch.nn.modules.module.Module

forward(data: Tuple[torch.Tensor, torch.Tensor]) → torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class nntoolbox.vision.losses.metrics.TripletMarginLossV2(margin=1.0, p=2.0, eps=1e-06, swap=False, size_average=None, reduce=None, reduction='mean')[source]

Bases: torch.nn.modules.loss.TripletMarginLoss

A quick wrapper for margin loss

eps: float
forward(data: Tuple[torch.Tensor, torch.Tensor, torch.Tensor]) → torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

margin: float
p: float
swap: bool
class nntoolbox.vision.losses.metrics.TripletSoftMarginLoss(p: float = 2.0)[source]

Bases: torch.nn.modules.module.Module

forward(data: Tuple[torch.Tensor, torch.Tensor, torch.Tensor]) → torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class nntoolbox.vision.losses.metrics.VerificationLoss(embedding_dim: int)[source]

Bases: torch.nn.modules.module.Module

Verify if two embeddings belong to the same class

forward(data: Tuple[torch.Tensor, ]) → torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

get_verifier()[source]
training: bool