improved-diffusion icon indicating copy to clipboard operation
improved-diffusion copied to clipboard

How to calculate NLL (which is mentioned in the paper) ?

Open Josh00-Lu opened this issue 3 years ago • 9 comments

Are there any explanations?

Josh00-Lu avatar Aug 02 '22 07:08 Josh00-Lu

I found one related work https://github.com/baofff/Extended-Analytic-DPM the api of nll is https://github.com/baofff/Extended-Analytic-DPM/blob/main/interface/evaluators/dtdpm_evaluator.py#L78 Then it calls the function in https://github.com/baofff/Extended-Analytic-DPM/blob/main/core/diffusion/likelihood.py

But I'm not sure if its evaluation is the same as DDPM/iDDPM

sndnyang avatar Aug 04 '22 17:08 sndnyang

Another one is https://github.com/openai/guided-diffusion/blob/main/guided_diffusion/gaussian_diffusion.py#L709

sndnyang avatar Aug 04 '22 17:08 sndnyang

Another one is https://github.com/openai/guided-diffusion/blob/main/guided_diffusion/gaussian_diffusion.py#L709

It starts from guided_diffusion/scripts/image_nll.py

This is easy to follow and the result makes sense (close to the table reported)

sndnyang avatar Aug 04 '22 19:08 sndnyang

Another one is https://github.com/openai/guided-diffusion/blob/main/guided_diffusion/gaussian_diffusion.py#L709

It starts from guided_diffusion/scripts/image_nll.py

This is easy to follow and the result makes sense (close to the table reported)

Thanks a lot! It's a pity that the authors didn't explain in detail about how to implement the "NLL metric" in their paper. It's easy to get confused when directly follow others' PyTorch code.

As far as I know, to calculate NLL, we need to calculate the $\sum_i log(P_\theta (x_{real}^{i}))$, while I don't know how to get $P_\theta(x)$ (e.g. the PDF of the distribution of our model)? I'm new to this field.

Josh00-Lu avatar Aug 05 '22 04:08 Josh00-Lu

What if there is a "maths explanation" will be better! Whatever, thanks a lot!

Josh00-Lu avatar Aug 05 '22 04:08 Josh00-Lu

What if there is a "maths explanation" will be better! Whatever, thanks a lot!

A math explanation is in DDPM http://arxiv.org/abs/2006.11239, section 3.3 Data scaling, reverse process decoder, and

sndnyang avatar Oct 31 '22 04:10 sndnyang

Another one is https://github.com/openai/guided-diffusion/blob/main/guided_diffusion/gaussian_diffusion.py#L709

It starts from guided_diffusion/scripts/image_nll.py

This is easy to follow and the result makes sense (close to the table reported)

Thanks for the useful pointer. The function _vb_terms_bpd calculates the NLL only for one step. If the NLL of one sample is required, should I sum up the results of _vb_terms_bpd for all diffusion steps (t=0-T)?

YuanYuan98 avatar Dec 10 '22 13:12 YuanYuan98

Another one is https://github.com/openai/guided-diffusion/blob/main/guided_diffusion/gaussian_diffusion.py#L709

It starts from guided_diffusion/scripts/image_nll.py This is easy to follow and the result makes sense (close to the table reported)

Thanks for the useful pointer. The function _vb_terms_bpd calculates the NLL only for one step. If the NLL of one sample is required, should I sum up the results of _vb_terms_bpd for all diffusion steps (t=0-T)?

Maybe you can check my wrapper code based on OpenAI's implementation https://github.com/sndnyang/iDDPM

sndnyang avatar Dec 11 '22 04:12 sndnyang

Another one is https://github.com/openai/guided-diffusion/blob/main/guided_diffusion/gaussian_diffusion.py#L709

It starts from guided_diffusion/scripts/image_nll.py This is easy to follow and the result makes sense (close to the table reported)

Thanks for the useful pointer. The function _vb_terms_bpd calculates the NLL only for one step. If the NLL of one sample is required, should I sum up the results of _vb_terms_bpd for all diffusion steps (t=0-T)?

Maybe you can check my wrapper code based on OpenAI's implementation https://github.com/sndnyang/iDDPM

Thanks for your comprehensive guide! May I ask what is the relationship between nll and bpd? Do you have any explanations? Thx in advance.

luccachiang avatar Aug 31 '23 03:08 luccachiang