SupContrast icon indicating copy to clipboard operation
SupContrast copied to clipboard

Why use logits without exp() and log() - torch.log(exp_logits)

Open Zhen-Zohn-WANG opened this issue 3 years ago • 3 comments

    # compute log_prob
    exp_logits = torch.exp(logits) * logits_mask
    log_prob = logits - torch.log(exp_logits.sum(1, keepdim=True))

In the code of loss, the logits without exp() and log(), why it can minus a log_exp_logit? It is different with Eq.(2) of SupContrast paper.

Thank you for your help.

Zhen-Zohn-WANG avatar Feb 23 '22 09:02 Zhen-Zohn-WANG

Because if you take the log over the exp, it gives the original value of logits.

thomascong121 avatar Feb 24 '22 06:02 thomascong121

I still did not understand the calculation of loss. Did you figure it out? Can anyone explain a little bit more?

QishengL avatar May 07 '22 18:05 QishengL

I still did not understand the calculation of loss. Did you figure it out? Can anyone explain a little bit more?

log(a/b) = log(a)-log(b)

xfreppihs avatar Apr 21 '23 02:04 xfreppihs