KevinMusgrave / pytorch-metric-learning

The easiest way to use deep metric learning in your application. Modular, flexible, and extensible. Written in PyTorch.
https://kevinmusgrave.github.io/pytorch-metric-learning/
MIT License
5.95k stars 658 forks source link

Are you not going to make a n-pairs loss miner? #109

Open ghost opened 4 years ago

ghost commented 4 years ago

image In the N-pairs loss paper, there is a "Hard negative class mining". But this is not implemented in this repository. Will you make this mining strategy? I just wonder it.

nmll commented 4 years ago

when use the N pair loss,it is increasing.may be which reason?

KevinMusgrave commented 4 years ago

@nmll Hard to say without more information. Perhaps your learning rate is too high?

nmll commented 4 years ago

Thanks,my learning rate is decaying.I do not use margin and miner,I use cos distance between the objects and then use the N pair loss,but the loss is increasing, I do not know why.the loss is increasing to 2.0 from 1,3

KevinMusgrave commented 4 years ago

@nmll What are you passing into the N-pairs loss?

nmll commented 4 years ago

@KevinMusgrave I pass into N-pairs loss the (anchors, labels,(anchor_index,pos_index,neg_index)),is the function required.

KevinMusgrave commented 4 years ago

@nmll Here are some other things you can try:

  1. Try passing in just "anchors" and "labels":

    loss_func(anchors, labels)
  2. See if the same thing happens with another loss function:

    
    from pytorch_metric_learning.losses import ContrastiveLoss
    from pytorch_metric_learning.reducers import MeanReducer

loss_func = ContrastiveLoss(reducer=MeanReducer())



3. Start with a lower learning rate.
nmll commented 4 years ago

Thanks a lot!