Diffusers documentation

DDIM

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.42.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

DDIM

Jiaming Song、Chenlin Meng、Stefano Ermon による Denoising Diffusion Implicit Models (DDIM)。

論文の抄録は以下の通りです:

デノイジング拡散確率モデル(DDPM)は、敵対的学習なしで高品質な画像生成を実現していますが、サンプルを生成するには多くのステップでマルコフ連鎖をシミュレートする必要があります。サンプリングを高速化するために、DDPMと同じ訓練手順を持つ、より効率的な反復型暗黙的確率モデルのクラスであるデノイジング拡散暗黙的モデル(DDIM)を提案します。DDPMでは、生成過程はマルコフ拡散過程の逆過程として定義されます。我々は、同じ訓練目的関数に導く非マルコフ拡散過程のクラスを構築し、その逆過程からのサンプリングを大幅に高速化します。実験により、DDIMはDDPMと比較して実時間ベースで10倍から50倍高速に高品質なサンプルを生成でき、計算量とサンプル品質のトレードオフが可能であり、潜在空間内で意味のある画像補間を直接実行できることを示しました。

元のコードベースはermongroup/ddimで確認できます。

DDIMPipeline

class diffusers.DDIMPipeline

< >

( unet: UNet2DModelscheduler: DDIMScheduler )

パラメータ

  • unet (UNet2DModel) — エンコードされた画像の潜在変数からノイズを除去するためのUNet2DModel。
  • scheduler (SchedulerMixin) — unet と組み合わせて、エンコードされた画像のノイズ除去に使用するスケジューラ。DDPMScheduler または DDIMScheduler のいずれかです。

画像生成用のPipeline。

このモデルは DiffusionPipeline を継承しています。すべてのパイプラインに実装されている汎用的なメソッド(ダウンロード、保存、特定のデバイスでの実行など)については、スーパークラスのドキュメントを参照してください。

__call__

< >

( batch_size: int = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Noneeta: float = 0.0num_inference_steps: int = 50use_clipped_model_output: bool | None = Noneoutput_type: str | None = 'pil'return_dict: bool = True ) → ImagePipelineOutput or tuple

パラメータ

  • 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) — True または False の場合、DDIMScheduler.step() のドキュメントを参照してください。None の場合、スケジューラに何も渡されません(この引数に対応していないスケジューラには None を使用してください)。
  • output_type (str, 任意、デフォルトは "pil") — 生成された画像の出力形式です。"pil" (PIL.Image)、"np" (np.array)、または "pt" (torch.Tensor) から選択します。
  • return_dict (bool, optional, defaults to True) — Whether or not to return a ImagePipelineOutput instead of a plain tuple.

戻り値

ImagePipelineOutput または tuple

return_dict が True の場合、ImagePipelineOutput が返され、それ以外の場合は tuple が返されます。このとき、最初の要素は生成された画像のリストです。

生成用の pipeline への呼び出し関数。

例:

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

class 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