Weakly supervised metric learning? #482
-
Hello! Thanks for the great library. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
If you mean training on triplets alone instead of labels, then yes. Any tuple-based loss function takes in an argument For triplets, the format of import torch
from pytorch_metric_learning.losses import TripletMarginLoss
loss_fn = TripletMarginLoss()
embeddings = torch.randn(32, 128)
# Two triplets. The first triplet has
# anchor: embeddings[0]
# positive: embeddings[1]
# negative: embeddings[5]
triplet_indices = [(0, 1, 5), (2, 3, 18)]
# "a" is all anchors, "p" is all positives, and "n" is all negatives
a, p, n = [torch.tensor(x) for x in list(zip(*triplet_indices))]
labels = torch.arange(len(embeddings)) # dummy labels
loss = loss_fn(embeddings, labels, indices_tuple = (a, p, n)) The dummy labels won't be used. I will make labels optional in a future version (see #412) |
Beta Was this translation helpful? Give feedback.
If you mean training on triplets alone instead of labels, then yes. Any tuple-based loss function takes in an argument
indices_tuple
which describes the pairs or triplets you want to train on.For triplets, the format of
indices_tuple
is(a, p, n)
, wherea
,p
, andn
are integer tensors: