Buckets:
| # AutoencoderRAE | |
| Model Representation Autoencoder (RAE) yang diperkenalkan dalam [Diffusion Transformers with Representation Autoencoders](https://huggingface.co/papers/2510.11690) oleh Boyang Zheng, Nanye Ma, Shengbang Tong, Saining Xie dari NYU VISIONx. | |
| RAE menggabungkan encoder visual pretrained yang dibekukan (DINOv2, SigLIP2, atau MAE) dengan decoder bergaya ViT-MAE yang dapat dilatih. Dalam resep pelatihan RAE dua tahap, autoencoder dilatih pada tahap 1 (rekonstruksi), kemudian model difusi dilatih pada ruang laten yang dihasilkan pada tahap 2 (generasi). | |
| Model-model RAE berikut telah dirilis dan didukung di Diffusers: | |
| | Model | Encoder | Bentuk laten (input 224px) | | |
| |:------|:--------|:---------------------------| | |
| | [`nyu-visionx/RAE-dinov2-wReg-base-ViTXL-n08`](https://huggingface.co/nyu-visionx/RAE-dinov2-wReg-base-ViTXL-n08) | DINOv2-base | 768 x 16 x 16 | | |
| | [`nyu-visionx/RAE-dinov2-wReg-base-ViTXL-n08-i512`](https://huggingface.co/nyu-visionx/RAE-dinov2-wReg-base-ViTXL-n08-i512) | DINOv2-base (512px) | 768 x 32 x 32 | | |
| | [`nyu-visionx/RAE-dinov2-wReg-small-ViTXL-n08`](https://huggingface.co/nyu-visionx/RAE-dinov2-wReg-small-ViTXL-n08) | DINOv2-small | 384 x 16 x 16 | | |
| | [`nyu-visionx/RAE-dinov2-wReg-large-ViTXL-n08`](https://huggingface.co/nyu-visionx/RAE-dinov2-wReg-large-ViTXL-n08) | DINOv2-large | 1024 x 16 x 16 | | |
| | [`nyu-visionx/RAE-siglip2-base-p16-i256-ViTXL-n08`](https://huggingface.co/nyu-visionx/RAE-siglip2-base-p16-i256-ViTXL-n08) | SigLIP2-base | 768 x 16 x 16 | | |
| | [`nyu-visionx/RAE-mae-base-p16-ViTXL-n08`](https://huggingface.co/nyu-visionx/RAE-mae-base-p16-ViTXL-n08) | MAE-base | 768 x 16 x 16 | | |
| ## Memuat model terlatih | |
| ```python | |
| from diffusers import AutoencoderRAE | |
| model = AutoencoderRAE.from_pretrained( | |
| "nyu-visionx/RAE-dinov2-wReg-base-ViTXL-n08" | |
| ).to("cuda").eval() # or "mps", "xpu", "cpu" | |
| ``` | |
| ## Enkoding dan dekoding gambar nyata | |
| ```python | |
| import torch | |
| from diffusers import AutoencoderRAE | |
| from diffusers.utils import load_image | |
| from torchvision.transforms.functional import to_tensor, to_pil_image | |
| model = AutoencoderRAE.from_pretrained( | |
| "nyu-visionx/RAE-dinov2-wReg-base-ViTXL-n08" | |
| ).to("cuda").eval() # or "mps", "xpu", "cpu" | |
| image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") | |
| image = image.convert("RGB").resize((224, 224)) | |
| x = to_tensor(image).unsqueeze(0).to("cuda") # (1, 3, 224, 224), values in [0, 1] | |
| with torch.no_grad(): | |
| latents = model.encode(x).latent # (1, 768, 16, 16) | |
| recon = model.decode(latents).sample # (1, 3, 256, 256) | |
| recon_image = to_pil_image(recon[0].clamp(0, 1).cpu()) | |
| recon_image.save("recon.png") | |
| ``` | |
| ## Normalisasi laten | |
| Beberapa checkpoint pretrained menyertakan statistik `latents_mean` dan `latents_std` per-channel untuk menormalisasi ruang laten. Jika ada, `encode` dan `decode` secara otomatis menerapkan normalisasi dan denormalisasi, masing-masing. | |
| ```python | |
| model = AutoencoderRAE.from_pretrained( | |
| "nyu-visionx/RAE-dinov2-wReg-base-ViTXL-n08" | |
| ).to("cuda").eval() # or "mps", "xpu", "cpu" | |
| # Latent normalization is handled automatically inside encode/decode | |
| # when the checkpoint config includes latents_mean/latents_std. | |
| with torch.no_grad(): | |
| latents = model.encode(x).latent # normalized latents | |
| recon = model.decode(latents).sample | |
| ``` | |
| ## AutoencoderRAE[[diffusers.AutoencoderRAE]] | |
| #### diffusers.AutoencoderRAE[[diffusers.AutoencoderRAE]] | |
| ```python | |
| diffusers.AutoencoderRAE(encoder_type: str = 'dinov2', encoder_hidden_size: int = 768, encoder_patch_size: int = 14, encoder_num_hidden_layers: int = 12, decoder_hidden_size: int = 512, decoder_num_hidden_layers: int = 8, decoder_num_attention_heads: int = 16, decoder_intermediate_size: int = 2048, patch_size: int = 16, encoder_input_size: int = 224, image_size: int | None = None, num_channels: int = 3, encoder_norm_mean: list | None = None, encoder_norm_std: list | None = None, latents_mean: typing.Union[list, tuple, torch.Tensor, NoneType] = None, latents_std: typing.Union[list, tuple, torch.Tensor, NoneType] = None, noise_tau: float = 0.0, reshape_to_2d: bool = True, use_encoder_loss: bool = False, scaling_factor: float = 1.0) | |
| ``` | |
| [Sumber](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/autoencoder_rae.py#L393) | |
| **Parameter:** | |
| encoder_type (`str`, *opsional*, defaultnya `"dinov2"`) : Jenis encoder beku yang akan digunakan. Salah satu dari `"dinov2"`, `"siglip2"`, atau `"mae"`. | |
| encoder_hidden_size (`int`, *opsional*, defaultnya `768`) : Ukuran tersembunyi dari model encoder. | |
| encoder_patch_size (`int`, *opsional*, defaultnya `14`) : Ukuran patch dari model encoder. | |
| encoder_num_hidden_layers (`int`, *opsional*, defaultnya `12`) : Jumlah lapisan tersembunyi dalam model encoder. | |
| patch_size (`int`, *opsional*, defaultnya `16`) : Ukuran patch decoder (digunakan untuk unpatchify dan kepala decoder). | |
| encoder_input_size (`int`, *opsional*, defaultnya `224`) : Ukuran input yang diharapkan oleh encoder. | |
| image_size (`int`, *opsional*) : Ukuran gambar output decoder. Jika `None`, nilainya diturunkan dari jumlah token encoder dan `patch_size` seperti RAE-main: `image_size = patch_size * sqrt(num_patches)`, di mana `num_patches = (encoder_input_size // encoder_patch_size) ** 2`. | |
| num_channels (`int`, *opsional*, defaultnya `3`) : Jumlah saluran input/output. | |
| encoder_norm_mean (`list`, *opsional*, default `[0.485, 0.456, 0.406]`) : Rata-rata per kanal untuk normalisasi input encoder (default ImageNet). | |
| encoder_norm_std (`list`, *opsional*, default `[0.229, 0.224, 0.225]`) : std per channel untuk normalisasi input encoder (default ImageNet). | |
| latents_mean (`list` atau `tuple`, *opsional*) : Rata-rata opsional untuk normalisasi laten. Input Tensor diterima dan dikonversi menjadi daftar yang dapat diserialisasi ke config. | |
| latents_std (`list` atau `tuple`, *opsional*) : Standar deviasi opsional untuk normalisasi laten. Input Tensor diterima dan dikonversi menjadi daftar yang dapat diserialisasi ke config. | |
| noise_tau (`float`, *opsional*, default `0.0`) : Tingkat noise untuk pelatihan (menambahkan noise ke latents selama pelatihan). | |
| reshape_to_2d (`bool`, *opsional*, defaultnya `True`) : Apakah akan mengubah bentuk latents ke format 2D (B, C, H, W). | |
| use_encoder_loss (`bool`, *opsional*, defaultnya `False`) : Apakah akan menggunakan hidden states encoder dalam loss (untuk pelatihan lanjutan). | |
| Model Representation Autoencoder (RAE) untuk mengkodekan gambar menjadi latents dan mendekode latents menjadi gambar. | |
| Model ini menggunakan encoder pretrained yang dibekukan (DINOv2, SigLIP2, atau MAE) dengan decoder ViT yang dapat dilatih untuk merekonstruksi gambar dari representasi yang dipelajari. | |
| Model ini mewarisi dari [ModelMixin](/docs/diffusers/main/id/api/models/overview#diffusers.ModelMixin). Periksa dokumentasi kelas induk untuk metode generiknya yang diimplementasikan untuk semua model (seperti mengunduh atau menyimpan). | |
| #### encode[[diffusers.AutoencoderRAE.encode]] | |
| ```python | |
| encode(x: Tensor, return_dict: bool = True, generator: typing.Optional[torch.Generator] = None) | |
| ``` | |
| [Sumber](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/autoencoder_rae.py#L640) | |
| #### decode[[diffusers.AutoencoderRAE.decode]] | |
| ```python | |
| decode(z: Tensor, return_dict: bool = True) | |
| ``` | |
| [Sumber](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/autoencoder_rae.py#L671) | |
| #### forward[[diffusers.AutoencoderRAE.forward]] | |
| ```python | |
| forward(sample: Tensor, return_dict: bool = True, generator: typing.Optional[torch.Generator] = None) | |
| ``` | |
| [Sumber](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/autoencoder_rae.py#L682) | |
| **Parameter:** | |
| sample (`torch.Tensor`) : Sampel input. | |
| return_dict (`bool`, *opsional*, defaultnya `True`) : Apakah akan mengembalikan `DecoderOutput` alih-alih tuple biasa. | |
| generator (`torch.Generator`, *opsional*) : Sebuah [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) untuk membuat sampling menjadi deterministik. | |
| **Mengembalikan:** `DecoderOutput` atau `tuple` | |
| Jika `return_dict` bernilai True, sebuah `DecoderOutput` akan dikembalikan, selain itu sebuah `tuple` biasa akan dikembalikan. | |
| ## DecoderOutput[[diffusers.models.autoencoders.vae.DecoderOutput]] | |
| #### diffusers.models.autoencoders.vae.DecoderOutput[[diffusers.models.autoencoders.vae.DecoderOutput]] | |
| ```python | |
| diffusers.models.autoencoders.vae.DecoderOutput(sample: Tensor, commit_loss: typing.Optional[torch.FloatTensor] = None) | |
| ``` | |
| [Sumber](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/vae.py#L49) | |
| **Parameter:** | |
| sample (`torch.Tensor` dengan bentuk `(batch_size, num_channels, height, width)`) : Sampel output yang didekodekan dari lapisan terakhir model. | |
| Output dari metode decoding. | |
Xet Storage Details
- Size:
- 8.94 kB
- Xet hash:
- 9eee22d23cd2260210d71840b84b24e0cdcba037543115617e7aa3564da57318
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.