Buckets:

hf-doc-build/doc / diffusers /main /vi /api /models /autoencoder_tiny.md
mishig's picture
|
download
raw
8.81 kB
# Tiny AutoEncoder
Tiny AutoEncoder for Stable Diffusion (TAESD) được giới thiệu trong [madebyollin/taesd](https://github.com/madebyollin/taesd) bởi Ollin Boer Bohan. Đây là phiên bản VAE thu nhỏ, đã được chưng cất của Stable Diffusion, có khả năng giải mã các latent trong [StableDiffusionPipeline](/docs/diffusers/main/vi/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline) hoặc [StableDiffusionXLPipeline](/docs/diffusers/main/vi/api/pipelines/stable_diffusion/stable_diffusion_xl#diffusers.StableDiffusionXLPipeline) gần như tức thì.
Để sử dụng với Stable Diffusion v-2.1:
```python
import torch
from diffusers import DiffusionPipeline, AutoencoderTiny
pipe = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-2-1-base", dtype=torch.float16
)
pipe.vae = AutoencoderTiny.from_pretrained("madebyollin/taesd", dtype=torch.float16)
pipe = pipe.to("cuda") # or "mps", "xpu", "cpu"
prompt = "slice of delicious New York-style berry cheesecake"
image = pipe(prompt, num_inference_steps=25).images[0]
image
```
Để sử dụng với Stable Diffusion XL 1.0
```python
import torch
from diffusers import DiffusionPipeline, AutoencoderTiny
pipe = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16
)
pipe.vae = AutoencoderTiny.from_pretrained("madebyollin/taesdxl", dtype=torch.float16)
pipe = pipe.to("cuda") # or "mps", "xpu", "cpu"
prompt = "slice of delicious New York-style berry cheesecake"
image = pipe(prompt, num_inference_steps=25).images[0]
image
```
## AutoencoderTiny[[diffusers.AutoencoderTiny]]
#### diffusers.AutoencoderTiny[[diffusers.AutoencoderTiny]]
```python
diffusers.AutoencoderTiny(in_channels: int = 3, out_channels: int = 3, encoder_block_out_channels: tuple[int, ...] = (64, 64, 64, 64), decoder_block_out_channels: tuple[int, ...] = (64, 64, 64, 64), act_fn: str = 'relu', upsample_fn: str = 'nearest', latent_channels: int = 4, upsampling_scaling_factor: int = 2, num_encoder_blocks: tuple[int, ...] = (1, 3, 3, 3), num_decoder_blocks: tuple[int, ...] = (3, 3, 3, 1), latent_magnitude: int = 3, latent_shift: float = 0.5, force_upcast: bool = False, scaling_factor: float = 1.0, shift_factor: float = 0.0)
```
[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/autoencoder_tiny.py#L40)
**Tham số:**
in_channels (`int`, *tuỳ chọn*, mặc định là 3) : Số kênh trong ảnh đầu vào.
out_channels (`int`, *tùy chọn*, mặc định là 3) : Số kênh trong đầu ra.
encoder_block_out_channels (`tuple[int]`, *optional*, mặc định là `(64, 64, 64, 64)`) : bộ tuple các số nguyên đại diện cho số lượng kênh đầu ra của mỗi khối encoder. Độ dài của bộ tuple phải bằng với số lượng khối encoder.
decoder_block_out_channels (`tuple[int]`, *optional*, mặc định là `(64, 64, 64, 64)`) : bộ các số nguyên đại diện cho số kênh đầu ra của mỗi khối giải mã. Độ dài của bộ phải bằng với số lượng khối giải mã.
act_fn (`str`, *tùy chọn*, mặc định là `"relu"`) : Hàm kích hoạt được sử dụng xuyên suốt mô hình.
latent_channels (`int`, *optional*, mặc định là 4) : Số kênh trong biểu diễn ẩn. Không gian ẩn đóng vai trò là biểu diễn nén của ảnh đầu vào.
upsampling_scaling_factor (`int`, *tuỳ chọn*, mặc định là 2) : Hệ số tỷ lệ cho quá trình lấy mẫu lên trong bộ giải mã. Nó xác định kích thước của hình ảnh đầu ra trong quá trình lấy mẫu lên.
num_encoder_blocks (`tuple[int]`, *optional*, mặc định là `(1, 3, 3, 3)`) : bộ các số nguyên đại diện cho số lượng khối encoder ở mỗi giai đoạn của quá trình mã hóa. Độ dài của bộ phải bằng với số giai đoạn trong encoder. Mỗi giai đoạn có một số lượng khối encoder khác nhau.
num_decoder_blocks (`tuple[int]`, *optional*, mặc định là `(3, 3, 3, 1)`) : bộ các số nguyên đại diện cho số lượng khối giải mã ở mỗi giai đoạn của quá trình giải mã. Độ dài của bộ phải bằng với số lượng giai đoạn trong bộ giải mã. Mỗi giai đoạn có một số lượng khối giải mã khác nhau.
latent_magnitude (`float`, *optional*, mặc định là 3.0) : Độ lớn của biểu diễn ẩn. Tham số này điều chỉnh các giá trị của biểu diễn ẩn để kiểm soát mức độ bảo toàn thông tin.
latent_shift (float, *tuỳ chọn*, mặc định là 0.5) : Độ dịch được áp dụng cho biểu diễn ẩn. Tham số này kiểm soát tâm của không gian ẩn.
scaling_factor (`float`, *optional*, mặc định là 1.0) : Độ lệch chuẩn từng thành phần của không gian tiềm ẩn đã được huấn luyện, được tính toán bằng cách sử dụng lô đầu tiên của tập dữ liệu huấn luyện. Giá trị này được dùng để chuẩn hóa không gian tiềm ẩn sao cho có phương sai bằng đơn vị khi huấn luyện mô hình khuếch tán. Các biến tiềm ẩn được chuẩn hóa bằng công thức `z = z * scaling_factor` trước khi được truyền vào mô hình khuếch tán. Khi giải mã, các biến tiềm ẩn được đưa về thang đo ban đầu bằng công thức: `z = 1 / scaling_factor * z`. Để biết thêm chi tiết, hãy tham khảo các mục 4.3.2 và D.1 của bài báo [High-Resolution Image Synthesis with Latent Diffusion Models](https://huggingface.co/papers/2112.10752). Tuy nhiên, đối với Autoencoder này, không có hệ số chuẩn hóa nào được sử dụng, do đó giá trị mặc định là 1.0.
force_upcast (`bool`, *tuỳ chọn*, mặc định là `False`) : Nếu được bật, tham số này sẽ buộc VAE chạy ở float32 cho các pipeline có độ phân giải ảnh cao, chẳng hạn như SD-XL. VAE có thể được tinh chỉnh / huấn luyện ở dải giá trị thấp hơn mà không mất quá nhiều độ chính xác, trong trường hợp đó `force_upcast` có thể được đặt thành `False` (xem [AutoEncoder](https://huggingface.co/madebyollin/sdxl-vae-fp16-fix) thân thiện với fp16 này).
Một mô hình VAE được chưng cất nhỏ gọn để mã hóa ảnh thành các biến ẩn và giải mã các biểu diễn ẩn thành ảnh.
[AutoencoderTiny](/docs/diffusers/main/vi/api/models/autoencoder_tiny#diffusers.AutoencoderTiny) là một lớp bọc quanh bản triển khai gốc của `TAESD`.
Mô hình này kế thừa từ [ModelMixin](/docs/diffusers/main/vi/api/models/overview#diffusers.ModelMixin). Xem tài liệu của lớp cha để biết các phương thức chung được triển khai cho tất cả các mô hình (chẳng hạn như tải xuống hoặc lưu).
#### forward[[diffusers.AutoencoderTiny.forward]]
```python
forward(sample: Tensor, return_dict: bool = True)
```
[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/autoencoder_tiny.py#L291)
**Tham số:**
sample (`torch.Tensor`) : Mẫu đầu vào.
return_dict (`bool`, *tùy chọn*, mặc định là `True`) : Có nên trả về một `DecoderOutput` thay vì một tuple thông thường hay không.
**Trả về:** `DecoderOutput` hoặc `tuple`
Nếu `return_dict` là True, một `DecoderOutput` sẽ được trả về, ngược lại một `tuple` thông thường sẽ được trả về.
#### scale_latents[[diffusers.AutoencoderTiny.scale_latents]]
```python
scale_latents(x: Tensor)
```
[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/autoencoder_tiny.py#L156)
raw latents -> [0, 1]
#### unscale_latents[[diffusers.AutoencoderTiny.unscale_latents]]
```python
unscale_latents(x: Tensor)
```
[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/autoencoder_tiny.py#L160)
[0, 1] -> latents thô
## AutoencoderTinyOutput[[diffusers.models.autoencoders.autoencoder_tiny.AutoencoderTinyOutput]]
#### diffusers.models.autoencoders.autoencoder_tiny.AutoencoderTinyOutput[[diffusers.models.autoencoders.autoencoder_tiny.AutoencoderTinyOutput]]
```python
diffusers.models.autoencoders.autoencoder_tiny.AutoencoderTinyOutput(latents: Tensor)
```
[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/autoencoder_tiny.py#L28)
**Tham số:**
latents (`torch.Tensor`) : Đầu ra đã mã hóa của `Encoder`.
Đầu ra của phương pháp mã hóa của AutoencoderTiny.

Xet Storage Details

Size:
8.81 kB
·
Xet hash:
644c45b1c125fe347489fb7dbc85cd58b15e90c70515da07ce571a742e8af0f7

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.