# DDPM

Jonathan Ho、Ajay Jain、Pieter Abbeel による [Denoising Diffusion Probabilistic Models](https://huggingface.co/papers/2006.11239) (DDPM) は、同名の拡散ベースのモデルを提案しています。🤗 Diffusers ライブラリでは、DDPM は論文の *discrete denoising scheduler* およびパイプラインを指します。

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

*非平衡熱力学の考察に着想を得た潜在変数モデルの一種である拡散確率モデルを用いた、高品質な画像合成の結果を提示します。私たちの最良の結果は、拡散確率モデルと Langevin 動力学を用いたノイズ除去スコアマッチングとの間の新たな関連性に基づいて設計された加重変分境界で訓練することで得られ、私たちのモデルは、自己回帰デコーディングの一般化と解釈できる漸進的有圧縮スキームを自然に許容します。無条件 CIFAR10 データセットでは、Inception スコア 9.46 と、最先端の FID スコア 3.17 を達成しました。256x256 の LSUN では、ProgressiveGAN と同様のサンプル品質を得ました。*

元のコードベースは [hohonathanho/diffusion](https://github.com/hojonathanho/diffusion) で確認できます。

> [!TIP]
> スケジューラーのトレードオフ、すなわち速度と品質のバランスをどのように探求するかを学ぶには、[ガイド](../../using-diffusers/schedulers)を必ずご確認ください。また、同じコンポーネントを複数のパイプラインに効率的に読み込む方法については、[パイプライン間でコンポーネントを再利用する](../../using-diffusers/loading#reusing-models-in-multiple-pipelines)セクションを参照してください。

# DDPMPipeline[[diffusers.DDPMPipeline]]

#### diffusers.DDPMPipeline[[diffusers.DDPMPipeline]]

```python
diffusers.DDPMPipeline(unet: UNet2DModel, scheduler: DDPMScheduler)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/ddpm/pipeline_ddpm.py#L33)

**パラメータ:**

unet ([UNet2DModel](/docs/diffusers/main/ja/api/models/unet2d#diffusers.UNet2DModel)) : エンコードされた画像の潜在変数をノイズ除去するための`UNet2DModel`。

scheduler ([SchedulerMixin](/docs/diffusers/main/ja/api/schedulers/overview#diffusers.SchedulerMixin)) : `unet` と組み合わせて、エンコードされた画像のノイズ除去に使用するスケジューラ。[DDPMScheduler](/docs/diffusers/main/ja/api/schedulers/ddpm#diffusers.DDPMScheduler) または [DDIMScheduler](/docs/diffusers/main/ja/api/schedulers/ddim#diffusers.DDIMScheduler) のいずれかです。

画像生成用のPipeline。

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

#### __call__[[diffusers.DDPMPipeline.__call__]]

```python
__call__(batch_size: int = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, num_inference_steps: int = 1000, output_type: str | None = 'pil', return_dict: bool = True)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/ddpm/pipeline_ddpm.py#L54)

**パラメータ:**

batch_size (`int`、*任意*、デフォルトは 1) : 生成する画像の数。

generator (`torch.Generator`, *任意*) : 生成を決定論的にするための [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html)。

num_inference_steps (`int`、*optional*、デフォルト値は 1000) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。

output_type (`str`、*任意*、デフォルトは`"pil"`) : 生成された画像の出力形式。`"pil"` (`PIL.Image`)、`"np"` (`np.array`)、または`"pt"` (`torch.Tensor`) から選択します。

return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく、[ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#diffusers.ImagePipelineOutput)を返すかどうか。

**戻り値:** [ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#diffusers.ImagePipelineOutput) または `tuple`

`return_dict` が `True` の場合、[ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#diffusers.ImagePipelineOutput) が返され、それ以外の場合は、最初の要素が生成された画像のリストである `tuple` が返されます。

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

例:

```py
>>> 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]]

#### diffusers.ImagePipelineOutput[[diffusers.ImagePipelineOutput]]

```python
diffusers.ImagePipelineOutput(images: list[PIL.Image.Image] | numpy.ndarray)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L135)

**パラメータ:**

images (`List[PIL.Image.Image]` または `np.ndarray`) : 長さ `batch_size` のデノイズ済み PIL 画像のリスト、または形状 `(batch_size, height, width, num_channels)` の NumPy 配列。

画像パイプライン用の出力クラス。

