Buckets:

mishig's picture
|
download
raw
6.99 kB
# VQModel
VQ-VAEモデルは、Aaron van den Oord、Oriol Vinyals、Koray Kavukcuogluによる論文[Neural Discrete Representation Learning](https://huggingface.co/papers/1711.00937)で提案されました。このモデルは、🤗 Diffusersにおいて潜在表現を画像にデコードするために使用されます。[AutoencoderKL](/docs/diffusers/main/ja/api/models/autoencoderkl#diffusers.AutoencoderKL)とは異なり、[VQModel](/docs/diffusers/main/ja/api/models/vq#diffusers.VQModel)は量子化された潜在空間で動作します。
論文の抄録は以下の通りです:
*教師なしで有用な表現を学習することは、機械学習における重要な課題であり続けます。本論文では、そのような離散表現を学習する、シンプルでありながら強力な生成モデルを提案します。我々のモデルであるVector Quantised-Variational AutoEncoder (VQ-VAE)は、VAEと2つの重要な点で異なります。1つ目は、エンコーダーネットワークが連続的なコードではなく離散なコードを出力すること、2つ目は、事前分布が静的ではなく学習されることです。離散な潜在表現を学習するために、ベクトル量子化 (VQ) のアイデアを取り入れています。VQ手法を用いることで、強力な自己回帰デコーダーとペアリングされた際に潜在変数が無視される「後方崩壊 (posterior collapse)」の問題を回避でき、これはVAEフレームワークで典型的に観察される現象です。これらの表現を自己回帰事前分布と組み合わせることで、モデルは高品質な画像、動画、音声の生成が可能となり、さらに高品質な話者変換や音素の教師なし学習も実現します。これにより、学習された表現の有用性がさらに裏付けられます。*
## VQModel[[diffusers.VQModel]]
#### diffusers.VQModel[[diffusers.VQModel]]
```python
diffusers.VQModel(in_channels: int = 3, out_channels: int = 3, down_block_types: tuple[str, ...] = ('DownEncoderBlock2D',), up_block_types: tuple[str, ...] = ('UpDecoderBlock2D',), block_out_channels: tuple[int, ...] = (64,), layers_per_block: int = 1, act_fn: str = 'silu', latent_channels: int = 3, sample_size: int = 32, num_vq_embeddings: int = 256, norm_num_groups: int = 32, vq_embed_dim: int | None = None, scaling_factor: float = 0.18215, norm_type: str = 'group', mid_block_add_attention = True, lookup_from_codebook = False, force_upcast = False)
```
[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/vq_model.py#L40)
**パラメータ:**
in_channels (int, *optional*, デフォルトは 3) : 入力画像のチャネル数。
out_channels (int, *optional*, デフォルトは 3) : 出力のチャネル数。
down_block_types (`tuple[str]`、*任意*、デフォルトは`("DownEncoderBlock2D",)`) : ダウンサンプルブロックのタイプのタプル。
up_block_types (`tuple[str]`、*任意*、デフォルトは`("UpDecoderBlock2D",)`) : アップサンプリングブロックのタイプのタプル。
block_out_channels (`tuple[int]`、*optional*、デフォルトは`(64,)`) : ブロックの出力チャネルのタプル。
layers_per_block (`int`, *optional*, デフォルトは `1`) : ブロックあたりのレイヤー数。
act_fn (`str`、*任意*、デフォルトは`"silu"`) : 使用する活性化関数。
latent_channels (`int`、*optional*、デフォルトは `3`) : 潜在空間のチャネル数。
sample_size (`int`、*任意*、デフォルトは`32`) : サンプル入力サイズ。
num_vq_embeddings (`int`、*任意*、デフォルトは `256`) : VQ-VAE のコードブックベクトルの数。
norm_num_groups (`int`、*optional*、デフォルトは`32`) : 正規化レイヤーのグループ数。
vq_embed_dim (`int`, *任意*) : VQ-VAEにおけるコードブックベクトルの隠れ次元数。
scaling_factor (`float`、*任意*、デフォルト値は `0.18215`) : 学習セットの最初のバッチを使用して計算された、学習済み潜在空間の要素ごとの標準偏差です。これは、拡散モデルの学習時に潜在空間を分散 1 にスケーリングするために使用されます。潜在変数は、拡散モデルに渡される前に `z = z * scaling_factor` という式でスケーリングされます。デコード時には、`z = 1 / scaling_factor * z` という式で元のスケールに戻されます。詳細については、[High-Resolution Image Synthesis with Latent Diffusion Models](https://huggingface.co/papers/2112.10752) 論文のセクション 4.3.2 と D.1 を参照してください。
norm_type (`str`、*任意*、デフォルトは`"group"`) : 使用する正規化レイヤーの種類。`"group"`または`"spatial"`のいずれかです。
潜在表現をデコードするためのVQ-VAEモデル。
このモデルは [ModelMixin](/docs/diffusers/main/ja/api/models/overview#diffusers.ModelMixin) を継承しています。すべてのモデルに実装されている汎用的なメソッド(ダウンロードや保存など)については、スーパークラスのドキュメントを参照してください。
#### forward[[diffusers.VQModel.forward]]
```python
forward(sample: Tensor, return_dict: bool = True)
```
[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/vq_model.py#L163)
**パラメータ:**
sample (`torch.Tensor`) : 入力サンプル。
return_dict (`bool`、*任意*、デフォルトは `True`) : プレーンなタプルではなく [models.autoencoders.vq_model.VQEncoderOutput](/docs/diffusers/main/ja/api/models/vq#diffusers.models.autoencoders.vq_model.VQEncoderOutput) を返すかどうか。
**戻り値:** [VQEncoderOutput](/docs/diffusers/main/ja/api/models/vq#diffusers.models.autoencoders.vq_model.VQEncoderOutput) または `tuple`
return_dict が True の場合、[VQEncoderOutput](/docs/diffusers/main/ja/api/models/vq#diffusers.models.autoencoders.vq_model.VQEncoderOutput) が返され、それ以外の場合は通常の `tuple` が返されます。
[VQModel](/docs/diffusers/main/ja/api/models/vq#diffusers.VQModel)のforwardメソッド。
## VQEncoderOutput[[diffusers.models.autoencoders.vq_model.VQEncoderOutput]]
#### diffusers.models.autoencoders.vq_model.VQEncoderOutput[[diffusers.models.autoencoders.vq_model.VQEncoderOutput]]
```python
diffusers.models.autoencoders.vq_model.VQEncoderOutput(latents: Tensor)
```
[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/vq_model.py#L28)
**パラメータ:**
latents (`torch.Tensor`、形状 `(batch_size, num_channels, height, width)`) : モデルの最終層からのエンコードされた出力サンプル。
VQModelのエンコードメソッドの出力。

Xet Storage Details

Size:
6.99 kB
·
Xet hash:
0f64a7e67e0a7f3a92439cf26e672b2638a6170b5176b4d23a1b014ac71b47df

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