lorenmt / reco

The implementation of "Bootstrapping Semantic Segmentation with Regional Contrast" [ICLR 2022].
https://shikun.io/projects/regional-contrast
Other
162 stars 25 forks source link

understanding of the loss #22

Closed pyedog1976 closed 2 years ago

pyedog1976 commented 2 years ago

Dear Author,

Thanks a lot for providing the code.

In your reco loss computation,

reco_loss = reco_loss + F.cross_entropy(seg_logits / temp, torch.zeros(num_queries).long().to(device))

I think the cross entropy part is equivalent with the nll loss and manually picks the positive index from the softmax outputs, as shown below:

-torch.log_softmax(seg_logits/temp, dim=1)[:, 0].mean()

However, I've found there always be slight different between those two computation ways, for example:

1). cross entropy way: 5.081362724304199
2). nll way: 5.081363677978516

My question is, do you think such different is caused by the floating point error? Am I misunderstand something?

Thanks.

Regards

lorenmt commented 2 years ago

Hello!

Yes, using log-softmax and cross-entropy should be mathematically the same. The difference here is very minimal and indeed can be caused by floating error, or implementation difference.

pyedog1976 commented 2 years ago

Thanks for your reply, and I'm tending to say the floating error can be the reason.