# AutoencoderOobleck

Stability AI 在 [Stability-AI/stable-audio-tools](https://github.com/Stability-AI/stable-audio-tools) 和 [Stable Audio Open](https://huggingface.co/papers/2407.14358) 中引入了带有 KL 损失的 Oobleck 变分自编码器（VAE）模型。该模型在 🤗 Diffusers 中用于将音频波形编码为潜在表示，并将潜在表示解码为音频波形。

该论文的摘要如下：

*开放生成模型对社区至关重要，它们支持微调，并在发布新模型时作为基线。然而，目前大多数文本转音频模型都是私有的，艺术家和研究人员无法基于这些模型进行开发。本文介绍了一个新的开放权重文本转音频模型的架构和训练过程，该模型使用 Creative Commons 数据进行训练。我们的评估表明，该模型在各项指标上的表现与当前最先进水平具有竞争力。值得注意的是，报告的 FDopenl3 结果（衡量生成内容的真实感）展示了其在 44.1kHz 下实现高质量立体声合成的潜力。*

## AutoencoderOobleck[[diffusers.AutoencoderOobleck]]

#### diffusers.AutoencoderOobleck[[diffusers.AutoencoderOobleck]]

```python
diffusers.AutoencoderOobleck(encoder_hidden_size = 128, downsampling_ratios = [2, 4, 4, 8, 8], channel_multiples = [1, 2, 4, 8, 16], decoder_channels = 128, decoder_input_channels = 64, audio_channels = 2, sampling_rate = 44100)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/models/autoencoders/autoencoder_oobleck.py#L294)

**参数：**

encoder_hidden_size (`int`，*可选*，默认为 128)：编码器的中间表示维度。

downsampling_ratios (`list[int]`，*可选*，默认为 `[2, 4, 4, 8, 8]`)：编码器中的下采样比例。这些比例在解码器中按相反顺序用于上采样。

channel_multiples (`list[int]`，*可选*，默认为 `[1, 2, 4, 8, 16]`)：用于确定隐藏层隐藏大小的倍数。

decoder_channels (`int`，*可选*，默认值为 128)：解码器的中间表示维度。

decoder_input_channels (`int`，*可选*，默认为 64)：解码器的输入维度。对应于潜在维度。

audio_channels (`int`，*可选*，默认为 2)：音频数据的通道数。单声道为 1，立体声为 2。

sampling_rate (`int`，*可选*，默认值为 44100)：以赫兹（Hz）为单位表示的音频波形数字化采样率。

一种自编码器，用于将波形编码为潜在表示，并将潜在表示解码为波形。首次引入于 Stable Audio。

该模型继承自 [ModelMixin](/docs/diffusers/v0.43.0/zh/api/models/overview#diffusers.ModelMixin)。请查阅其父类文档，了解为所有模型实现的通用方法（例如下载或保存）。

#### decode[[diffusers.AutoencoderOobleck.decode]]

```python
decode(z: FloatTensor, return_dict: bool = True, generator = None)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/models/autoencoders/autoencoder_oobleck.py#L488)

**参数：**

z (`torch.Tensor`) : 输入的潜在向量批次。

return_dict (`bool`，*可选*，默认为 `True`)：是否返回 `~models.vae.OobleckDecoderOutput` 而不是普通元组。

**返回：** `~models.vae.OobleckDecoderOutput` 或 `tuple`

If return_dict is True, a `~models.vae.OobleckDecoderOutput` is returned, otherwise a plain `tuple` is returned.

解码一批图像。

#### encode[[diffusers.AutoencoderOobleck.encode]]

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

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/models/autoencoders/autoencoder_oobleck.py#L377)

**参数：**

x (`torch.Tensor`) : 输入图像批次。

return_dict (`bool`，*可选*，默认为 `True`)：是否返回 `~models.autoencoder_kl.AutoencoderKLOutput` 而不是普通元组。

**返回值：**

编码图像的潜在表示。如果 `return_dict` 为 True，则返回 `~models.autoencoder_kl.AutoencoderKLOutput`，否则返回普通的 `tuple`。

将一批图像编码为潜在表示。

#### forward[[diffusers.AutoencoderOobleck.forward]]

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

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/models/autoencoders/autoencoder_oobleck.py#L517)

**参数：**

sample (`torch.Tensor`) : 输入样本。

sample_posterior (`bool`，*可选*，默认为 `False`)：是否从后验分布中采样。

return_dict (`bool`，*可选*，默认为 `True`)：是否返回 `OobleckDecoderOutput` 而非普通元组。

generator (`torch.Generator`，*可选*)：一个 [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html)，用于使采样过程具有确定性。

**返回：** `~models.vae.OobleckDecoderOutput` 或 `tuple`

如果 `return_dict` 为 True，则返回 `~models.vae.OobleckDecoderOutput`，否则返回普通的 `tuple`。

## OobleckDecoderOutput[[diffusers.models.autoencoders.autoencoder_oobleck.OobleckDecoderOutput]]

#### diffusers.models.autoencoders.autoencoder_oobleck.OobleckDecoderOutput[[diffusers.models.autoencoders.autoencoder_oobleck.OobleckDecoderOutput]]

```python
diffusers.models.autoencoders.autoencoder_oobleck.OobleckDecoderOutput(sample: Tensor)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/models/autoencoders/autoencoder_oobleck.py#L202)

**参数：**

sample (`torch.Tensor`，形状为 `(batch_size, audio_channels, sequence_length)`)：模型最后一层解码后的输出样本。

解码方法的输出。

## AutoencoderOobleckOutput[[diffusers.models.autoencoders.autoencoder_oobleck.AutoencoderOobleckOutput]]

#### diffusers.models.autoencoders.autoencoder_oobleck.AutoencoderOobleckOutput[[diffusers.models.autoencoders.autoencoder_oobleck.AutoencoderOobleckOutput]]

```python
diffusers.models.autoencoders.autoencoder_oobleck.AutoencoderOobleckOutput(latent_dist: OobleckDiagonalGaussianDistribution)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/models/autoencoders/autoencoder_oobleck.py#L187)

**参数：**

latent_dist (`OobleckDiagonalGaussianDistribution`)：`Encoder` 的编码输出，表示为 `OobleckDiagonalGaussianDistribution` 的均值和标准差。`OobleckDiagonalGaussianDistribution` 允许从该分布中采样潜在变量。

AutoencoderOobleck 编码方法的输出。

