MCPcopy Create free account
hub / github.com/CompVis/diff2flow / p_sample

Method p_sample

diff2flow/ddpm.py:336–348  ·  view source on GitHub ↗

Sample x_{t-1} from the model at the given timestep.

(self, model, x_t, t, clip_denoised=True, model_kwargs=None)

Source from the content-addressed store, hash-verified

334 }
335
336 def p_sample(self, model, x_t, t, clip_denoised=True, model_kwargs=None):
337 """
338 Sample x_{t-1} from the model at the given timestep.
339 """
340 model_kwargs = model_kwargs or {}
341 noise = torch.randn_like(x_t)
342 # get mean and variance of p(x_{t-1} | x_t), as well as a prediction of x_0
343 out = self.p_mean_variance(model, x_t, t, clip_denoised=clip_denoised, model_kwargs=model_kwargs)
344 nonzero_mask = (
345 (t != 0).float().view(-1, *([1] * (len(x_t.shape) - 1)))
346 ) # no noise when t == 0
347 sample = out["mean"] + nonzero_mask * (0.5 * out["log_variance"]).exp() * noise
348 return {'sample': sample, 'pred_xstart': out['pred_xstart']}
349
350 def p_sample_loop(
351 self,

Callers 1

p_sample_loopMethod · 0.95

Calls 1

p_mean_varianceMethod · 0.95

Tested by

no test coverage detected