vis4d.op.loss.embedding_distance

Embedding distance loss.

Classes

EmbeddingDistanceLoss([reducer, neg_pos_ub, ...])

Embedding distance loss for learning appearance similarity.

class EmbeddingDistanceLoss(reducer=<function identity_loss>, neg_pos_ub=3.0, pos_margin=0.0, neg_margin=0.3, hard_mining=True)[source]

Embedding distance loss for learning appearance similarity.

Computes the difference between the target distances and the predicted distances of two sets of embedding vectors. Uses hard negative mining based on the loss values to select pairs for overall loss computation.

Creates an instance of the class.

forward(pred, target, weight=None)[source]

Forward function.

Parameters:
  • pred (torch.Tensor) – The predicted distances between two sets of predictions. Shape [N, M].

  • target (torch.Tensor) – The corresponding target distances. Either zero (different identity) or one (same identity).

  • weight (torch.Tensor, optional) – The weight of loss for each prediction. Defaults to None.

Returns:

embedding distance loss.

Return type:

loss_bbox (torch.Tensor)

update_weight(pred, target, weight)[source]

Update element-wise loss weights.

Exclude negatives according to maximum fraction of samples and/or hard negative mining.

Return type:

tuple[Tensor, Tensor, Tensor]