zoubohao / DenoisingDiffusionProbabilityModel-ddpm-

This may be the simplest implement of DDPM. You can directly run Main.py to train the UNet on CIFAR-10 dataset and see the amazing process of denoising.
MIT License
1.48k stars 156 forks source link

Question about variance calculation in sampling step #18

Open HIT-LiuChen opened 1 year ago

HIT-LiuChen commented 1 year ago

In Diffusion.py line 66, posterior_var is calculated. Why do you use torch.cat([self.posterior_var[1:2], self.betas[1:]]) in line 77 to extract variance instead of posterior_var.

    def p_mean_variance(self, x_t, t):
        # below: only log_variance is used in the KL computations
        var = torch.cat([self.posterior_var[1:2], self.betas[1:]])    # i think var should be equal to self.posterior_var
        var = extract(var, t, x_t.shape)

        eps = self.model(x_t, t)
        xt_prev_mean = self.predict_xt_prev_mean_from_eps(x_t, t, eps=eps)

        return xt_prev_mean, var
ljw919 commented 1 year ago

I have the same doubt, what's the reason for doing this ?

kache1995 commented 1 year ago

俺也有这个疑问,方差不是应该是self.posterior_var吗

tsWen0309 commented 1 year ago

Have you solved the problem? Can you fill me in?

MetaInsight7 commented 8 months ago

@zoubohao Could you answer this issue? Thank you!

chenchen278 commented 4 months ago

In the paper DDPM, it seems that var is equal to posterior_var or betas. And I don't know why they were concatenated here?