Diffusers documentation

AutoencoderKLKVAE

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

AutoencoderKLKVAE

带有 KL 散度损失的二维变分自编码器(VAE)模型。

可以使用以下代码片段加载该模型。

import torch
from diffusers import AutoencoderKLKVAE

vae = AutoencoderKLKVAE.from_pretrained("kandinskylab/KVAE-2D-1.0", subfolder="diffusers", dtype=torch.bfloat16)

AutoencoderKLKVAE

class diffusers.AutoencoderKLKVAE

< >

( in_channels: int = 3channels: int = 128num_enc_blocks: int = 2num_dec_blocks: int = 2z_channels: int = 16double_z: bool = Truech_mult: typing.Tuple[int, ...] = (1, 2, 4, 8)sample_size: int = 1024 )

参数

  • in_channels(int,可选,默认为 3)— 输入图像的通道数。
  • channels (int, 可选,默认为 128) — 多分辨率块中的基础通道数。
  • num_enc_blocks (int, 可选,默认为 2) — 编码器多分辨率层中 Resnet 块的数量。
  • num_dec_blocks (int, 可选,默认为 2) — 解码器多分辨率层中 Resnet 块的数量。
  • z_channels(int,可选,默认为 16)— 潜在空间中的通道数。
  • double_z (bool,可选,默认为 True) — 是否将编码器的输出通道数加倍。
  • ch_mult (Tuple[int, ...],可选,默认为 (1, 2, 4, 8)) — 多分辨率块中的通道乘数。
  • sample_size(int,可选,默认为 1024)— 采样输入大小。

一个带有 KL 损失的 VAE 模型,用于将图像编码为潜在表示,并将潜在表示解码为图像。

该模型继承自 ModelMixin。有关为所有模型实现的通用方法(例如下载或保存),请参阅其父类文档。

decode

< >

( z: FloatTensorreturn_dict: bool = Truegenerator = None ) → ~models.vae.DecoderOutput or tuple

参数

  • z (torch.Tensor) — 输入批次的潜在向量。
  • return_dict (bool,可选,默认为 True) — 是否返回 ~models.vae.DecoderOutput 而不是普通元组。

返回值

~models.vae.DecoderOutput 或 tuple

如果 return_dict 为 True,则返回 ~models.vae.DecoderOutput,否则返回普通的 tuple。

解码一批图像。

encode

< >

( x: Tensorreturn_dict: bool = True )

参数

  • x (torch.Tensor) — 输入图像批次。
  • return_dict (bool,可选,默认为 True) — 是否返回 ~models.autoencoder_kl.AutoencoderKLOutput 而不是普通元组。

将一批图像编码为潜在表示。

forward

< >

( sample: Tensorsample_posterior: bool = Falsereturn_dict: bool = Truegenerator: typing.Optional[torch.Generator] = None ) → ~models.vae.DecoderOutput or tuple

参数

  • sample (torch.Tensor) — 输入样本。
  • sample_posterior (bool,可选,默认为 False) — 是否从后验分布中采样。
  • return_dict (bool,可选,默认为 True) — 是否返回 DecoderOutput 而不是普通元组。
  • generator (torch.Generator,可选) — 用于使采样过程确定性的 torch.Generator。

返回值

~models.vae.DecoderOutput 或 tuple

如果 return_dict 为 True,则返回 ~models.vae.DecoderOutput,否则返回普通的 tuple。

tiled_decode

< >

( z: Tensorreturn_dict: bool = True ) → ~models.vae.DecoderOutput or tuple

参数

  • z (torch.Tensor) — 输入批次的潜在向量。
  • return_dict (bool,可选,默认为 True) — 是否返回 ~models.vae.DecoderOutput 而不是普通元组。

返回值

~models.vae.DecoderOutput 或 tuple

如果 return_dict 为 True,则返回 ~models.vae.DecoderOutput,否则返回普通的 tuple。

使用分块解码器解码一批图像。

Update on GitHub