Diffusers documentation

AutoencoderKLPH3Image

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

AutoencoderKLPH3Image

VAE gambar dari P-H3-Image oleh Pruna AI. Model ini menggunakan encoder dan ruang laten dari VAE video MiniMax-H3, dengan decoder ViT yang mendekode satu frame laten menjadi gambar.

Mengikuti konvensi dari AutoencoderKLMiniMaxH3:

  • Gambar diteruskan sebagai video satu bingkai, (batch_size, channels, 1, height, width), dengan kompresi spasial 16x.
  • Latents dinormalisasi per channel dengan latents_mean / latents_std alih-alih scaling_factor.
  • Pixel adalah RGB yang dinormalisasi dengan ImageNet di atas [0, 1]: encode mengharapkan (pixel - imagenet_mean) / imagenet_std dan decode mengembalikan ruang tersebut.
  • Penyusunan ubin spasial diaktifkan secara bawaan, dengan ubin berukuran 256 piksel dan tumpang tindih minimal 64 piksel.
import torch
from diffusers import AutoencoderKLPH3Image

vae = AutoencoderKLPH3Image.from_pretrained("PrunaAI/P-H3-Image", subfolder="vae", dtype=torch.bfloat16).to(
    "cuda"
)  # or "mps", "xpu", "cpu"

Output proyeksi dari encoder dan decoder tetap dalam float32 apa pun dtype yang digunakan saat model dimuat.

AutoencoderKLPH3Image

kelas diffusers.AutoencoderKLPH3Image

< >

( in_channels: int = 3out_channels: int = 3latent_channels: int = 24block_out_channels: tuple[int, ...] = (128, 256, 256, 512, 512, 1024)layers_per_block: int = 2spatial_downsample_factors: tuple[int, ...] = (2, 2, 2, 2, 1, 1)temporal_downsample_factors: tuple[int, ...] = (1, 2, 2, 1, 1, 1)norm_num_groups: int = 32norm_eps: float = 1e-06spatial_padding_mode: str = 'reflect'decoder_num_layers: int = 36decoder_num_attention_heads: int = 32decoder_attention_head_dim: int = 64decoder_num_register_tokens: int = 4decoder_ffn_mult: int = 4decoder_rope_theta: float = 100.0decoder_rope_dim_ratio: float = 0.75decoder_norm_eps: float = 1e-05latents_mean: tuple[float, ...] = (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)latents_std: tuple[float, ...] = (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0) )

VAE gambar dari P-H3-Image: encoder VAE dan ruang laten MiniMax-H3, dengan PH3ImageViTDecoder yang mendekode satu frame laten.

Gambar diteruskan sebagai video satu bingkai, (batch_size, channels, 1, height, width). Seperti pada AutoencoderKLMiniMaxH3, piksel adalah RGB yang dinormalisasi ImageNet di atas [0, 1] (rata-rata (0.485, 0.456, 0.406), simpangan baku (0.229, 0.224, 0.225)) dan penataan ubin spasial aktif secara bawaan.

encode

< >

( x: Tensorreturn_dict: bool = True )

Parameter

  • x (torch.Tensor) — Batch input gambar sebagai video satu frame, bentuk (batch_size, in_channels, 1, height, width).
  • return_dict (bool, opsional, default True) — Apakah akan mengembalikan AutoencoderKLOutput alih-alih tuple biasa.

Enkodekan batch gambar menjadi latents.

decode

< >

( z: Tensorreturn_dict: bool = True ) → DecoderOutput or tuple

Parameter

  • z (torch.Tensor) — Batch input latents, bentuk (batch_size, latent_channels, 1, height, width).
  • return_dict (bool, opsional, default True) — Apakah akan mengembalikan DecoderOutput alih-alih tuple biasa.

Mengembalikan

DecoderOutput atau tuple

Gambar yang didekode, bentuk (batch_size, out_channels, 1, height, width).

Decode batch of latent images.

enable_tiling

< >

( tile_sample_min_height: int | None = Nonetile_sample_min_width: int | None = Nonetile_sample_min_overlap_height: int | None = Nonetile_sample_min_overlap_width: int | None = None )

Parameter

  • tile_sample_min_height (int, opsional) — Tinggi tile dalam ruang piksel. Frame yang lebih tinggi dari nilai ini akan dipecah sepanjang dimensi tinggi.
  • tile_sample_min_width (int, opsional) — Lebar tile dalam ruang piksel. Frame yang lebih lebar dari nilai ini akan dipecah sepanjang dimensi lebar.
  • tile_sample_min_overlap_height (int, opsional) — Tumpang tindih minimum, dalam piksel, antara dua tile vertikal yang berurutan.
  • tile_sample_min_overlap_width (int, opsional) — Tumpang tindih minimum, dalam piksel, antara dua tile horizontal yang berurutan.

Aktifkan encoding/decoding VAE bertile. Ketika opsi ini diaktifkan, VAE membagi frame menjadi tile, meng-encode atau meng-decode setiap tile secara terpisah, dan mencampur kembali bagian yang tumpang tindih secara linear. Hal ini menurunkan kebutuhan memori dan memungkinkan pemrosesan frame yang lebih besar.

forward

< >

( sample: Tensorsample_posterior: bool = Falsegenerator: typing.Optional[torch.Generator] = Nonereturn_dict: bool = True ) → DecoderOutput or tuple

Parameter

  • sample (torch.Tensor) — Batch input gambar sebagai video satu frame, bentuk (batch_size, in_channels, 1, height, width).
  • sample_posterior (bool, opsional, default False) — Apakah akan mengambil sampel posterior alih-alih mengambil modusnya.
  • generator (torch.Generator, opsional) — Generator yang digunakan saat sample_posterior=True.
  • return_dict (bool, opsional, default True) — Apakah akan mengembalikan DecoderOutput alih-alih tuple biasa.

Mengembalikan

DecoderOutput atau tuple

Gambar yang telah diproses bolak-balik, bentuk (batch_size, out_channels, 1, height, width).

Encode lalu decode sebuah batch gambar.

Update on GitHub