Diffusers 文档

DDPM

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

DDPM

去噪扩散概率模型 (DDPM) 由 Jonathan Ho、Ajay Jain 和 Pieter Abbeel 提出,该模型是一个基于扩散的模型,名称与论文相同。在 🤗 Diffusers 库中,DDPM 指的是论文中的*离散去噪调度器*以及相应的管道。

论文摘要如下:

我们利用扩散概率模型(一种受非平衡热力学启发而建立的潜变量模型)取得了高质量图像合成结果。我们通过根据扩散概率模型与 Langevin 动力学去噪分数匹配之间的新颖联系设计的加权变分下界进行训练,获得了最佳结果。我们的模型自然支持渐进式有损解压方案,该方案可解释为自回归解码的推广。在无条件 CIFAR10 数据集上,我们获得了 9.46 的 Inception 分数和 3.17 的最先进 FID 分数。在 256x256 LSUN 上,我们获得了与 ProgressiveGAN 相似的样本质量。

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

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

DDPMPipeline

class diffusers.DDPMPipeline

< >

( unet: UNet2DModel scheduler: DDPMScheduler )

参数

图像生成管道。

此模型继承自 DiffusionPipeline。请查阅超类文档,了解所有管道实现的通用方法(下载、保存、在特定设备上运行等)。

__call__

< >

( batch_size: int = 1 generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None num_inference_steps: int = 1000 output_type: typing.Optional[str] = 'pil' return_dict: bool = True ) ImagePipelineOutputtuple

参数

  • batch_size (int, 可选, 默认为 1) — 要生成的图像数量。
  • generator (torch.Generator, 可选) — 一个 torch.Generator 用于使生成具有确定性。
  • num_inference_steps (int, 可选, 默认为 1000) — 去噪步数。更多的去噪步数通常会产生更高质量的图像,但推理速度会变慢。
  • output_type (str, 可选, 默认为 "pil") — 生成图像的输出格式。在 PIL.Imagenp.array 之间选择。
  • return_dict (bool, 可选, 默认为 True) — 是否返回 ImagePipelineOutput 而不是普通元组。

返回

ImagePipelineOutputtuple

如果 return_dictTrue,则返回 ImagePipelineOutput,否则返回一个 tuple,其中第一个元素是生成的图像列表

用于生成的管道的调用函数。

示例

>>> 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

class diffusers.ImagePipelineOutput

< >

( images: typing.Union[typing.List[PIL.Image.Image], numpy.ndarray] )

参数

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

图像流水线的输出类。

< > 在 GitHub 上更新