-
Notifications
You must be signed in to change notification settings - Fork 657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug in MultiSimilarityMiner? #723
Comments
Can you paste in the embeddings tensor here? I'd like to reproduce the bug. |
It seems to happen with any embedding tensor. I think i have traced the problem to here
after this, for some reason mat_pos_sorting looks like this
ie it has neg_ignore filled into the negative cells instead of pos_ignore. I don't think this is an overflow issue because if i change pos_ignore and neg_ignore to 10 and -10, the issue still persists. |
to make things even more strange, if i do
everything works fine and the tensors contain the expected results |
Hmm, I'm not able to reproduce it yet. Can you paste in the minimal code for reproducing it? Also what OS are you running this on and what versions of pytorch and pytorch-metric-learning are you using? |
torch 2.2.1 Can confirm this seems to be a Mac problem. Can't reproduce on linux. |
I don't think I'm able to reproduce it on my macbook. I'm using:
Here's the code I'm using: import torch
from pytorch_metric_learning.miners import MultiSimilarityMiner
device = "mps:0"
embeddings = torch.randn(8, 32, device=device)
labels = torch.tensor([ 15, 15, 15, 15, 169, 169, 169, 169], device=device)
miner = MultiSimilarityMiner()
pos_mask = torch.zeros(8,8, device=device)
a1, p, a2, n = miner(embeddings, labels)
pos_mask[a1,p]=1
print(pos_mask) The output is: tensor([[0., 1., 1., 1., 0., 0., 0., 0.],
[1., 0., 1., 1., 0., 0., 0., 0.],
[1., 1., 0., 1., 0., 0., 0., 0.],
[1., 1., 1., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 1., 1., 1.],
[0., 0., 0., 0., 1., 0., 1., 1.],
[0., 0., 0., 0., 1., 1., 0., 1.],
[0., 0., 0., 0., 1., 1., 1., 0.]], device='mps:0') |
Hi,
is it expected that the MultiSimilarityMiner will produce positive pairs that don't actually have the same label?
For example one of my batches has items with the following labels (this is with a small batch size of only 8 just to illustrate the problem):
tensor([ 15, 15, 15, 15, 169, 169, 169, 169], device='mps:0')
I use the MultiSimilarityMiner to mine pairs for MultiSimilarityLoss. If i print out the values of mat, pos_mask, and neg_mask in the compute_loss function of MultiSimilarityLoss, they are
This is right at the beginning of training so the similarity scores in mat are total garbage, but the pos_mask looks wrong to me. It has selected every pair as positive, including those that don't share the same ID. Is that expected for some reason?
The text was updated successfully, but these errors were encountered: