Diffusers 文档

DDPM

Hugging Face's logo
加入 Hugging Face 社区

并获取增强的文档体验

开始使用

DDPM

Denoising Diffusion Probabilistic Models (DDPM) 由 Jonathan Ho、Ajay Jain 和 Pieter Abbeel 提出了一种同名的基于扩散的模型。在 🤗 Diffusers 库中,DDPM 指的是论文中的*离散去噪 scheduler* 以及 pipeline。

论文摘要如下:

我们展示了使用扩散概率模型合成高质量图像的结果,扩散概率模型是一类受非平衡热力学考虑启发的隐变量模型。我们的最佳结果是通过在加权变分界上训练获得的,该变分界根据扩散概率模型和使用 Langevin 动力学的去噪分数匹配之间的新颖联系而设计,并且我们的模型自然地允许一种渐进的、有损的解压缩方案,该方案可以被解释为自回归解码的推广。在无条件 CIFAR10 数据集上,我们获得了 9.46 的 Inception 分数和 3.17 的最先进 FID 分数。在 256x256 LSUN 上,我们获得了与 ProgressiveGAN 相似的样本质量。

原始代码库可以在以下位置找到: hohonathanho/diffusion.

请务必查看 Schedulers 指南,了解如何探索 scheduler 速度和质量之间的权衡,并查看跨 pipelines 重用组件 部分,了解如何有效地将相同的组件加载到多个 pipelines 中。

DDPMPipeline

class diffusers.DDPMPipeline

< >

( unet scheduler )

参数

用于图像生成的 Pipeline。

此模型继承自 DiffusionPipeline。 查看超类文档以获取所有 pipeline 通用的方法(下载、保存、在特定设备上运行等)。

__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 而不是普通 tuple。

返回

ImagePipelineOutputtuple

如果 return_dictTrue,则返回 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

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 数组。

图像 pipeline 的输出类。

< > Update on GitHub