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=True,
denoised_fn=None,
cond_fn=None,
model_kwargs=None,
device=None,
progress=False,
)
| 440 | return {"sample": sample, "pred_xstart": out["pred_xstart"]} |
| 441 | |
| 442 | def p_sample_loop( |
| 443 | self, |
| 444 | model, |
| 445 | shape, |
| 446 | noise=None, |
| 447 | clip_denoised=True, |
| 448 | denoised_fn=None, |
| 449 | cond_fn=None, |
| 450 | model_kwargs=None, |
| 451 | device=None, |
| 452 | progress=False, |
| 453 | ): |
| 454 | """ |
| 455 | Generate samples from the model. |
| 456 | |
| 457 | :param model: the model module. |
| 458 | :param shape: the shape of the samples, (N, C, H, W). |
| 459 | :param noise: if specified, the noise from the encoder to sample. |
| 460 | Should be of the same shape as `shape`. |
| 461 | :param clip_denoised: if True, clip x_start predictions to [-1, 1]. |
| 462 | :param denoised_fn: if not None, a function which applies to the |
| 463 | x_start prediction before it is used to sample. |
| 464 | :param cond_fn: if not None, this is a gradient function that acts |
| 465 | similarly to the model. |
| 466 | :param model_kwargs: if not None, a dict of extra keyword arguments to |
| 467 | pass to the model. This can be used for conditioning. |
| 468 | :param device: if specified, the device to create the samples on. |
| 469 | If not specified, use a model parameter's device. |
| 470 | :param progress: if True, show a tqdm progress bar. |
| 471 | :return: a non-differentiable batch of samples. |
| 472 | """ |
| 473 | final = None |
| 474 | for sample in self.p_sample_loop_progressive( |
| 475 | model, |
| 476 | shape, |
| 477 | noise=noise, |
| 478 | clip_denoised=clip_denoised, |
| 479 | denoised_fn=denoised_fn, |
| 480 | cond_fn=cond_fn, |
| 481 | model_kwargs=model_kwargs, |
| 482 | device=device, |
| 483 | progress=progress, |
| 484 | ): |
| 485 | final = sample |
| 486 | return final["sample"] |
| 487 | |
| 488 | def p_sample_loop_progressive( |
| 489 | self, |
no test coverage detected