How to interpret the miner output? #435
Answered
by
KevinMusgrave
celsofranssa
asked this question in
Q&A
-
How to interpret the following miner output: import torch
from pytorch_metric_learning import miners, losses
# miner and loss function
miner = miners.MultiSimilarityMiner()
loss_func = losses.TripletMarginLoss()
# embeddings and labels
embeddings = torch.tensor([
[.91, .70, .82],
[.89, .71, .79],
[.09, .07, .09],
[.05, .03, .08],
])
labels = torch.tensor([1,1,0,0])
miner_outs = miner(embeddings,labels)
# (tensor([0, 1, 2, 3]),
# tensor([1, 0, 3, 2]),
# tensor([0, 0, 1, 1, 2, 2, 3, 3]),
# tensor([3, 2, 3, 2, 1, 0, 1, 0]))
loss_func(embeddings, labels, miner_outs)
# tensor(0.1183) |
Beta Was this translation helpful? Give feedback.
Answered by
KevinMusgrave
Feb 28, 2022
Replies: 1 comment 1 reply
-
In your case:
So there are 4 positive pairs and 8 negative pairs. For example: The 1st positive pair is The 5th negative pair is |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
celsofranssa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MultiSimilarityMiner
returns pairs, so the output format is (a1, p, a2, n).In your case:
tensor([0, 1, 2, 3])
tensor([1, 0, 3, 2])
tensor([0, 0, 1, 1, 2, 2, 3, 3])
tensor([3, 2, 3, 2, 1, 0, 1, 0]))
So there are 4 positive pairs and 8 negative pairs.
For example:
The 1st positive pair is
(a1[0], p[0])
, which is (0, 1), which corresponds with(embeddings[0], embeddings[1])
.The 5th negative pair is
(a2[4], n[4])
, which is (2, 1), which corresponds with(embeddings[2], embeddings[1])
.