MCPcopy Create free account
hub / github.com/294coder/Dif-PAN / q_sample

Method q_sample

diffusion/diffusion_ddpm_pan.py:668–690  ·  view source on GitHub ↗
(self, x_start, t, noise=None)

Source from the content-addressed store, hash-verified

666 return img
667
668 def q_sample(self, x_start, t, noise=None):
669 noise = default(noise, lambda: torch.randn_like(x_start))
670
671 # fix gama
672 # \sqrt{\bar {\alpha_t}} \times x_0 + \sqrt{1 - \bar {\alpha_t}} * \epsilon
673 # also call VP schedule
674
675 # SNR: self.sqrt_alphas_cumprod / self.sqrt_one_minus_alphas_cumprod
676 # SNR weighting: max(self.sqrt_alphas_cumprod **2 / self.sqrt_one_minus_alphas_cumprod**2, 1)
677 # or (1 + self.sqrt_alphas_cumprod **2 / self.sqrt_one_minus_alphas_cumprod**2)
678 return (
679 extract(self.sqrt_alphas_cumprod, t, x_start.shape) * x_start
680 + extract(self.sqrt_one_minus_alphas_cumprod, t, x_start.shape) * noise
681 )
682 # random gama
683 # x_shape = x_start.shape
684 # l = self.alphas_cumprod .gather(-1, t)
685 # r = self.alphas_cumprod .gather(-1, t+1)
686 # gama = (r - l) * torch.rand(0, 1) + l
687 # gama = gama.reshape(t.shape[0], *((1,) * (len(x_shape) - 1)))
688 # return (
689 # nq.sqrt(gama) * x_start + nq.sqrt(1-gama)* noise
690 # )
691
692 def p_losses(self, x_start, noise=None, cond=None):
693 [b, c, h, w] = x_start.shape

Callers 2

interpolateMethod · 0.95
p_lossesMethod · 0.95

Calls 2

extractFunction · 0.85
defaultFunction · 0.70

Tested by

no test coverage detected