Diffusers documentation
AutoencoderKLKVAE
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
< source >( 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
< source >( z: FloatTensorreturn_dict: bool = Truegenerator = None ) → ~models.vae.DecoderOutput or tuple
解码一批图像。
encode
< source >( x: Tensorreturn_dict: bool = True )
将一批图像编码为潜在表示。
forward
< source >( 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
< source >( z: Tensorreturn_dict: bool = True ) → ~models.vae.DecoderOutput or tuple
使用分块解码器解码一批图像。