yang-song / score_sde_pytorch

PyTorch implementation for Score-Based Generative Modeling through Stochastic Differential Equations (ICLR 2021, Oral)
https://arxiv.org/abs/2011.13456
Apache License 2.0
1.58k stars 295 forks source link

Question about reporting likelihoods in bits per dim #51

Open Mattias421 opened 6 months ago

Mattias421 commented 6 months ago

Hi all,

Thank you for providing this code, it's very educational :)

I am interested in reporting likelihoods but I don't fully understand how bits per dim are calculated. In the code this is

bpd = -(prior_logp + delta_logp) / np.log(2)
N = np.prod(shape[1:])
bpd = bpd / N
# A hack to convert log-likelihoods to bits/dim
offset = 7. - inverse_scaler(-1.)
bpd = bpd + offset

Would you be able to elaborate on how this hack works and if it applies to other image dimensions?

Best, Matt

zen-d commented 5 months ago

same question here.

mareikethies commented 5 months ago

same question here as well Edit: I think this hack applies to images which originally have discrete pixel intensities from 0 to 255. See, e.g., equations 3 to 5 in Danihelka et al. (https://arxiv.org/pdf/1705.05263.pdf).

zen-d commented 3 months ago

@mareikethies Thanks a lot! I got it.

Mattias421 commented 3 months ago

@mareikethies Thank you, it looks like this offset doesn't apply to other data types :0