Diffusers documentation

AsymmetricAutoencoderKL

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

AsymmetricAutoencoderKL

KL損失を用いたインペインティングタスク向けの改良された大規模な変分オートエンコーダ(VAE)モデル: Zixin Zhu, Xuelu Feng, Dongdong Chen, Jianmin Bao, Le Wang, Yinpeng Chen, Lu Yuan, Gang Hua による Designing a Better Asymmetric VQGAN for StableDiffusion

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

StableDiffusion は、画像生成・編集の世界で大きな注目を集めている革新的なテキストから画像を生成するモデルです。ピクセル空間で拡散モデルを学習する従来の手法とは異なり、StableDiffusion は VQGAN を介して潜在空間で拡散モデルを学習することで、効率性と品質の両立を実現しています。画像生成タスクをサポートするだけでなく、インペインティングや局所編集など、実画像に対する画像編集も可能にします。しかしながら、StableDiffusion で使用されているバニラ VQGAN は、編集されていない画像領域でも歪みアーティファクトを引き起こすほどの重大な情報損失を招くことが観察されています。この問題を解決するため、2 つのシンプルな設計を持つ新しい非対称 VQGAN を提案します。まず、エンコーダーからの入力に加えて、デコーダーにはインペインティングにおけるマスクされていない画像領域などのタスク固有の事前情報を取り込む条件分岐が含まれます。次に、デコーダーはエンコーダーよりもはるかに重く設計されており、推論コストの増加をわずかに抑えつつ、より詳細な復元を可能にします。この非対称 VQGAN の学習コストは低く、バニラ VQGAN のエンコーダーと StableDiffusion を変更せずに、新しい非対称デコーダーのみを再学習すれば済みます。提案する非対称 VQGAN は、StableDiffusion ベースのインペインティングや局所編集手法に広く適用できます。広範な実験により、元のテキストから画像を生成する能力を維持しながら、インペインティングや編集の性能を大幅に向上させることが示されています。コードは https://github.com/buxiangzhiren/Asymmetric_VQGAN で利用できます。

評価結果は、元の論文のセクション4.1に記載されています。

利用可能なチェックポイント

使用例

from diffusers import AsymmetricAutoencoderKL, StableDiffusionInpaintPipeline
from diffusers.utils import load_image, make_image_grid


prompt = "a photo of a person with beard"
img_url = "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/repaint/celeba_hq_256.png"
mask_url = "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/repaint/mask_256.png"

original_image = load_image(img_url).resize((512, 512))
mask_image = load_image(mask_url).resize((512, 512))

pipe = StableDiffusionInpaintPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-inpainting")
pipe.vae = AsymmetricAutoencoderKL.from_pretrained("cross-attention/asymmetric-autoencoder-kl-x-1-5")
pipe.to("cuda")  # or "mps", "xpu", "cpu"

image = pipe(prompt=prompt, image=original_image, mask_image=mask_image).images[0]
make_image_grid([original_image, mask_image, image], rows=1, cols=3)

AsymmetricAutoencoderKL

class diffusers.AsymmetricAutoencoderKL

< >

( in_channels: int = 3out_channels: int = 3down_block_types: tuple = ('DownEncoderBlock2D',)down_block_out_channels: tuple = (64,)layers_per_down_block: int = 1up_block_types: tuple = ('UpDecoderBlock2D',)up_block_out_channels: tuple = (64,)layers_per_up_block: int = 1act_fn: str = 'silu'latent_channels: int = 4norm_num_groups: int = 32sample_size: int = 32scaling_factor: float = 0.18215 )

パラメータ

  • in_channels (int, 任意、デフォルトは 3) — 入力画像のチャネル数。
  • out_channels (int, 任意, デフォルトは 3) — 出力のチャネル数。
  • down_block_types (tuple[str]、任意、デフォルトは("DownEncoderBlock2D",)) — ダウンサンプルブロックのタイプのタプルです。
  • down_block_out_channels (tuple[int]、省略可能、デフォルトは (64,)) — ダウンブロックの出力チャネルのタプルです。
  • layers_per_down_block (int、任意、デフォルトは 1) — ダウンブロックのレイヤー数。
  • up_block_types (tuple[str]、任意、デフォルトは("UpDecoderBlock2D",)) — アップサンプリングブロックのタイプのタプルです。
  • up_block_out_channels (tuple[int]、任意、デフォルトは (64,)) — アップブロックの出力チャネルのタプル。
  • layers_per_up_block (int、省略可、デフォルトは 1) — アップブロックのレイヤー数。
  • act_fn (str、任意、デフォルトは "silu") — 使用する活性化関数。
  • latent_channels (int、任意、デフォルトは 4)— 潜在空間のチャネル数。
  • sample_size (int、任意、デフォルトは 32) — サンプルの入力サイズ。
  • norm_num_groups (int、任意、デフォルトは 32) — ResNet ブロック内の最初の正規化層で使用するグループ数。
  • scaling_factor (float, 任意、デフォルト値は 0.18215) — 学習済み潜在空間の要素ごとの標準偏差です。これは、学習セットの最初のバッチを使用して計算されます。拡散モデルの学習時に、潜在空間を単位分散にスケーリングするために使用されます。潜在変数は、拡散モデルに渡される前に、式 z = z * scaling_factor によってスケーリングされます。デコード時には、式 z = 1 / scaling_factor * z によって、潜在変数は元のスケールに戻されます。詳細については、High-Resolution Image Synthesis with Latent Diffusion Models 論文のセクション 4.3.2 と D.1 を参照してください。

StableDiffusion 向けにより優れた非対称 VQGAN の設計 https://huggingface.co/papers/2306.04632 。KL 損失を用いて画像を潜在変数にエンコードし、潜在表現を画像にデコードする VAE モデルです。

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

forward

< >

( sample: Tensormask: typing.Optional[torch.Tensor] = Nonesample_posterior: bool = Falsereturn_dict: bool = Truegenerator: typing.Optional[torch.Generator] = None ) → DecoderOutput or tuple

パラメータ

  • sample (torch.Tensor) — 入力サンプル。
  • mask (torch.Tensor、任意、デフォルトはNone) — 任意のインペインティングマスク。
  • sample_posterior (bool、省略可能、デフォルトはFalse) — 後方分布からサンプリングするかどうか。
  • return_dict (bool、省略可、デフォルトは True) — DecoderOutput を返すか、プレーンなタプルを返すかを指定します。
  • generator (torch.Generator、省略可) — サンプリングを決定論的に行うためのtorch.Generator。

戻り値

DecoderOutput または tuple

return_dict が True の場合、DecoderOutput が返され、それ以外の場合は通常の tuple が返されます。

AutoencoderKLOutput

class diffusers.models.modeling_outputs.AutoencoderKLOutput

< >

( latent_dist: DiagonalGaussianDistribution )

パラメータ

  • latent_dist (DiagonalGaussianDistribution) — Encoder のエンコード出力を、DiagonalGaussianDistribution の平均と logvar として表したものです。 DiagonalGaussianDistribution を使用すると、この分布から潜在変数をサンプリングできます。

AutoencoderKLのエンコードメソッドの出力。

DecoderOutput

class diffusers.models.autoencoders.vae.DecoderOutput

< >

( sample: Tensorcommit_loss: typing.Optional[torch.FloatTensor] = None )

パラメータ

  • sample (torch.Tensor、形状 (batch_size, num_channels, height, width)) — モデルの最終層からのデコード済み出力サンプルです。

デコードメソッドの出力。

Update on GitHub