Diffusers documentation

DDPM

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

DDPM

Jonathan Ho、Ajay Jain 和 Pieter Abbeel 提出的 Denoising Diffusion Probabilistic Models(DDPM)提出了一种同名的基于扩散的模型。在 🤗 Diffusers 库中,DDPM 既指代论文中的离散去噪调度器,也指代相应的 pipeline。

该论文的摘要如下:

我们展示了使用扩散概率模型(一类受非平衡热力学启发的隐变量模型)进行高质量图像合成的结果。我们的最佳结果是通过在加权变分下界上训练获得的,该下界是根据扩散概率模型与基于朗之万动力学的去噪分数匹配之间的新颖联系而设计的;此外,我们的模型天然支持一种渐进式有损解压方案,可将其视为自回归解码的推广。在无条件的 CIFAR10 数据集上,我们获得了 9.46 的 Inception 分数和 3.17 的 FID 分数(达到当前最优水平)。在 256x256 的 LSUN 数据集上,我们获得了与 ProgressiveGAN 相似的样本质量。

原始代码库可在 hohonathanho/diffusion 中找到。

请务必参阅 调度器指南,了解如何探索调度器速度与质量之间的权衡,并查看 跨流水线复用组件 部分,了解如何高效地将相同组件加载到多个流水线中。

DDPMPipeline

class diffusers.DDPMPipeline

< >

( unet: UNet2DModelscheduler: DDPMScheduler )

参数

用于图像生成的 Pipeline。

该模型继承自 DiffusionPipeline。有关为所有 pipeline 实现的通用方法(下载、保存、在特定设备上运行等),请参阅父类文档。

__call__

< >

( batch_size: int = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonenum_inference_steps: int = 1000output_type: str | None = 'pil'return_dict: bool = True ) → ImagePipelineOutput or tuple

参数

  • batch_size (int,可选,默认为 1) — 要生成的图像数量。
  • generator (torch.Generator,可选) — 用于使生成过程确定性的 torch.Generator。
  • num_inference_steps (int,可选,默认值为 1000) — 去噪步数。更多的去噪步数通常能生成更高质量的图像,但代价是推理速度变慢。
  • output_type (str, 可选,默认为 "pil") — 生成图像的输出格式。可选 "pil" (PIL.Image)、"np" (np.array) 或 "pt" (torch.Tensor)。
  • return_dict (bool,可选,默认为 True) — 是否返回 ImagePipelineOutput 而不是普通元组。

返回值

ImagePipelineOutput 或 tuple

如果 return_dict 为 True,则返回 ImagePipelineOutput;否则返回一个 tuple,其中第一个元素是包含生成图像的列表

用于生成的 pipeline 的调用函数。

示例:

>>> from diffusers import DDPMPipeline

>>> # load model and scheduler
>>> pipe = DDPMPipeline.from_pretrained("google/ddpm-cat-256")

>>> # run pipeline in inference (sample random noise and denoise)
>>> image = pipe().images[0]

>>> # save image
>>> image.save("ddpm_generated_image.png")

ImagePipelineOutput

类 diffusers.ImagePipelineOutput

< >

( images: list[PIL.Image.Image] | numpy.ndarray )

参数

  • images (List[PIL.Image.Image] 或 np.ndarray) — 长度为 batch_size 的去噪 PIL 图像列表,或形状为 (batch_size, height, width, num_channels) 的 NumPy 数组。

图像流水线输出类。

Update on GitHub