Generate samples from the model. :param model: the model module. :param shape: the shape of the samples, (N, C, H, W). :param noise: if specified, the noise from the encoder to sample. Should be of the same shape as `shape`. :param clip
(
self,
model,
shape,
noise=None,
clip_denoised=False,
denoised_fn=None,
cond_fn=None,
model_kwargs=None,
device=None,
progress=False,
temp=1.0,
)
| 497 | return {"sample": sample, "pred_xstart": out["pred_xstart"]} |
| 498 | |
| 499 | def p_sample_loop( |
| 500 | self, |
| 501 | model, |
| 502 | shape, |
| 503 | noise=None, |
| 504 | clip_denoised=False, |
| 505 | denoised_fn=None, |
| 506 | cond_fn=None, |
| 507 | model_kwargs=None, |
| 508 | device=None, |
| 509 | progress=False, |
| 510 | temp=1.0, |
| 511 | ): |
| 512 | """ |
| 513 | Generate samples from the model. |
| 514 | |
| 515 | :param model: the model module. |
| 516 | :param shape: the shape of the samples, (N, C, H, W). |
| 517 | :param noise: if specified, the noise from the encoder to sample. |
| 518 | Should be of the same shape as `shape`. |
| 519 | :param clip_denoised: if True, clip x_start predictions to [-1, 1]. |
| 520 | :param denoised_fn: if not None, a function which applies to the |
| 521 | x_start prediction before it is used to sample. |
| 522 | :param cond_fn: if not None, this is a gradient function that acts |
| 523 | similarly to the model. |
| 524 | :param model_kwargs: if not None, a dict of extra keyword arguments to |
| 525 | pass to the model. This can be used for conditioning. |
| 526 | :param device: if specified, the device to create the samples on. |
| 527 | If not specified, use a model parameter's device. |
| 528 | :param progress: if True, show a tqdm progress bar. |
| 529 | :return: a non-differentiable batch of samples. |
| 530 | """ |
| 531 | final = None |
| 532 | for sample in self.p_sample_loop_progressive( |
| 533 | model, |
| 534 | shape, |
| 535 | noise=noise, |
| 536 | clip_denoised=clip_denoised, |
| 537 | denoised_fn=denoised_fn, |
| 538 | cond_fn=cond_fn, |
| 539 | model_kwargs=model_kwargs, |
| 540 | device=device, |
| 541 | progress=progress, |
| 542 | temp=temp, |
| 543 | ): |
| 544 | final = sample |
| 545 | return final["sample"] |
| 546 | |
| 547 | def p_sample_loop_progressive( |
| 548 | self, |
no test coverage detected