# AutoencoderKLPH3Image

VAE gambar dari [P-H3-Image](https://huggingface.co/PrunaAI/P-H3-Image) oleh Pruna AI. Model ini menggunakan encoder dan ruang laten dari [VAE video](./autoencoderkl_minimax_h3) MiniMax-H3, dengan decoder ViT yang mendekode satu frame laten menjadi gambar.

Mengikuti konvensi dari [AutoencoderKLMiniMaxH3](/docs/diffusers/main/id/api/models/autoencoderkl_minimax_h3#diffusers.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.

```python
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[[diffusers.AutoencoderKLPH3Image]]

#### diffusers.AutoencoderKLPH3Image[[diffusers.AutoencoderKLPH3Image]]

```python
diffusers.AutoencoderKLPH3Image(in_channels: int = 3, out_channels: int = 3, latent_channels: int = 24, block_out_channels: tuple[int, ...] = (128, 256, 256, 512, 512, 1024), layers_per_block: int = 2, spatial_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 = 32, norm_eps: float = 1e-06, spatial_padding_mode: str = 'reflect', decoder_num_layers: int = 36, decoder_num_attention_heads: int = 32, decoder_attention_head_dim: int = 64, decoder_num_register_tokens: int = 4, decoder_ffn_mult: int = 4, decoder_rope_theta: float = 100.0, decoder_rope_dim_ratio: float = 0.75, decoder_norm_eps: float = 1e-05, latents_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))
```

[Sumber](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/autoencoder_kl_p_h3_image.py#L493)

VAE gambar dari [P-H3-Image](https://huggingface.co/PrunaAI/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](/docs/diffusers/main/id/api/models/autoencoderkl_minimax_h3#diffusers.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[[diffusers.AutoencoderKLPH3Image.encode]]

```python
encode(x: Tensor, return_dict: bool = True)
```

[Sumber](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/autoencoder_kl_p_h3_image.py#L728)

**Parameter:**

x (`torch.Tensor`) : Batch input gambar sebagai video satu-frame, bentuk `(batch_size, in_channels, 1, height, width)`.

return_dict (`bool`, *opsional*, defaultnya `True`) : Apakah akan mengembalikan [AutoencoderKLOutput](/docs/diffusers/main/id/api/models/autoencoderkl_qwenimage#diffusers.models.modeling_outputs.AutoencoderKLOutput) alih-alih tuple biasa.

**Mengembalikan:**

Distribusi laten dari gambar yang dikodekan. Perhatikan bahwa latennya dinormalisasi dengan `latents_mean` / `latents_std` setelahnya.

Enkodekan batch gambar menjadi latents.

#### decode[[diffusers.AutoencoderKLPH3Image.decode]]

```python
decode(z: Tensor, return_dict: bool = True)
```

[Sumber](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/autoencoder_kl_p_h3_image.py#L757)

**Parameter:**

z (`torch.Tensor`) : Batch input latents, bentuk `(batch_size, latent_channels, 1, height, width)`.

return_dict (`bool`, *opsional*, defaultnya `True`) : Apakah akan mengembalikan [DecoderOutput](/docs/diffusers/main/id/api/models/autoencoderkl_qwenimage#diffusers.models.autoencoders.vae.DecoderOutput) alih-alih tuple biasa.

**Mengembalikan:** [DecoderOutput](/docs/diffusers/main/id/api/models/autoencoderkl_qwenimage#diffusers.models.autoencoders.vae.DecoderOutput) atau `tuple`

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

Decode batch of latent images.

#### enable_tiling[[diffusers.AutoencoderKLPH3Image.enable_tiling]]

```python
enable_tiling(tile_sample_min_height: int | None = None, tile_sample_min_width: int | None = None, tile_sample_min_overlap_height: int | None = None, tile_sample_min_overlap_width: int | None = None)
```

[Sumber](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/autoencoder_kl_p_h3_image.py#L575)

**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 ini akan dipecah sepanjang dimensi lebar.

tile_sample_min_overlap_height (`int`, *opsional*) : Tumpang tindih minimum, dalam piksel, antara dua ubin vertikal yang berurutan.

tile_sample_min_overlap_width (`int`, *opsional*) : Tumpang tindih minimum, dalam piksel, antara dua ubin 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, lalu mencampur kembali bagian yang tumpang tindih secara linear. Hal ini menurunkan kebutuhan memori dan memungkinkan pemrosesan frame yang lebih besar.

#### forward[[diffusers.AutoencoderKLPH3Image.forward]]

```python
forward(sample: Tensor, sample_posterior: bool = False, generator: typing.Optional[torch.Generator] = None, return_dict: bool = True)
```

[Sumber](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/autoencoder_kl_p_h3_image.py#L784)

**Parameter:**

sample (`torch.Tensor`) : Batch input gambar sebagai video satu-frame, bentuk `(batch_size, in_channels, 1, height, width)`.

sample_posterior (`bool`, *opsional*, defaultnya `False`) : Apakah akan melakukan sampling posterior alih-alih mengambil modusnya.

generator (`torch.Generator`, *opsional*) : Generator yang digunakan saat `sample_posterior=True`.

return_dict (`bool`, *opsional*, defaultnya `True`) : Apakah akan mengembalikan [DecoderOutput](/docs/diffusers/main/id/api/models/autoencoderkl_qwenimage#diffusers.models.autoencoders.vae.DecoderOutput) alih-alih tuple biasa.

**Mengembalikan:** [DecoderOutput](/docs/diffusers/main/id/api/models/autoencoderkl_qwenimage#diffusers.models.autoencoders.vae.DecoderOutput) atau `tuple`

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

Encode lalu decode sebuah batch gambar.

