Diffusers 文档

DDIM

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

DDIM

去噪扩散隐式模型 (DDIM),作者:Jiaming Song、Chenlin Meng 和 Stefano Ermon。

论文摘要如下:

去噪扩散概率模型 (DDPMs) 实现了高质量图像生成而无需对抗训练,但它们需要模拟马尔可夫链多步才能生成样本。为了加速采样,我们提出了去噪扩散隐式模型 (DDIMs),这是一类更有效的迭代隐式概率模型,其训练过程与 DDPMs 相同。在 DDPMs 中,生成过程被定义为马尔可夫扩散过程的逆过程。我们构建了一类非马尔可夫扩散过程,它们导致相同的训练目标,但其逆过程的采样速度要快得多。我们通过实验证明,与 DDPMs 相比,DDIMs 在实际时间上可以快 10 到 50 倍生成高质量样本,允许我们权衡计算量与样本质量,并且可以直接在潜在空间中执行语义上有意义的图像插值。

原始代码库可在 ermongroup/ddim 找到。

DDIMPipeline

diffusers.DDIMPipeline

< >

( unet: UNet2DModel 调度器: DDIMScheduler )

参数

用于图像生成的管道。

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

__call__

< >

( 批大小: int = 1 生成器: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None eta: float = 0.0 推理步数: int = 50 使用裁剪模型输出: typing.Optional[bool] = None 输出类型: typing.Optional[str] = 'pil' 返回字典: bool = True ) ImagePipelineOutputtuple

参数

  • batch_size (int, 可选, 默认为 1) — 要生成的图像数量。
  • generator (torch.Generator, 可选) — 用于使生成具有确定性的 torch.Generator
  • eta (float, 可选, 默认为 0.0) — 对应于 DDIM 论文中的参数 eta (η)。仅适用于 DDIMScheduler,在其他调度器中将被忽略。值为 0 对应于 DDIM,1 对应于 DDPM。
  • num_inference_steps (int, 可选, 默认为 50) — 去噪步数。更多去噪步数通常会带来更高质量的图像,但推理速度会变慢。
  • use_clipped_model_output (bool, 可选, 默认为 None) — 如果为 TrueFalse,请参阅 DDIMScheduler.step() 的文档。如果为 None,则不会将任何内容传递给下游调度器(对于不支持此参数的调度器,请使用 None)。
  • output_type (str, 可选, 默认为 "pil") — 生成图像的输出格式。在 PIL.Imagenp.array 之间选择。
  • return_dict (bool, 可选, 默认为 True) — 是否返回 ImagePipelineOutput 而不是普通的元组。

返回

ImagePipelineOutputtuple

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

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

示例

>>> from diffusers import DDIMPipeline
>>> import PIL.Image
>>> import numpy as np

>>> # load model and scheduler
>>> pipe = DDIMPipeline.from_pretrained("fusing/ddim-lsun-bedroom")

>>> # run pipeline in inference (sample random noise and denoise)
>>> image = pipe(eta=0.0, num_inference_steps=50)

>>> # process image to PIL
>>> image_processed = image.cpu().permute(0, 2, 3, 1)
>>> image_processed = (image_processed + 1.0) * 127.5
>>> image_processed = image_processed.numpy().astype(np.uint8)
>>> image_pil = PIL.Image.fromarray(image_processed[0])

>>> # save image
>>> image_pil.save("test.png")

ImagePipelineOutput

diffusers.ImagePipelineOutput

< >

( 图像: 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 上更新