# VidEoMT

## 概要

VidEoMTモデルは、Narges Norouzi、Idil Esen Zulfikar、Niccolò Cavagnero、Tommie Kerssies、Bastian Leibe、Gijs Dubbelman、Daan de Geus による論文 [Your ViT is Secretly Also a Video Segmentation Model](https://huggingface.co/papers/2602.17807) で提案されました。Video Encoder-only Mask Transformer (VidEoMT) は、プレーンな [Vision Transformer (ViT)](vit) をベースに構築された、オンライン動画セグメンテーションのための軽量なエンコーダー専用モデルです。これは [EoMT](./eomt) の動画への最小限の拡張であり、専用のトラッキングモジュールや重いタスク固有のヘッドに依存することなく、ViTエンコーダー内で空間的および時間的な推論を行います。

論文の抄録は以下の通りです。

*既存のオンライン動画セグメンテーションモデルは、フレームごとのセグメンターと複雑な専用トラッキングモジュールを組み合わせるのが一般的です。これらのモジュールは効果的ですが、アーキテクチャの複雑さと計算オーバーヘッドを大きく引き起こします。最近の研究では、十分な容量と大規模な事前学習を施したプレーンなVision Transformer (ViT) エンコーダーは、専用モジュールを必要とせずに正確な画像セグメンテーションを実行できることが示唆されています。この観察を踏まえ、私たちは、専用のトラッキングモジュールを不要にするシンプルなエンコーダーオンリーの動画セグメンテーションモデル、Video Encoder-only Mask Transformer (VidEoMT) を提案します。エンコーダーオンリーのViTで時間モデリングを可能にするため、VidEoMTは、前のフレームのクエリを再利用してフレーム間で情報を伝達する軽量なクエリ伝播メカニズムを導入しています。これと新しいコンテンツへの適応性のバランスを取るため、伝播されたクエリと時間的に無関係な学習済みクエリのセットを組み合わせるクエリ融合戦略を採用しています。その結果、VidEoMTは追加の複雑さなしでトラッカーの利点を実現し、ViT-Lバックボーンで最大160 FPSで動作しながら、5倍から10倍高速で競争力のある精度を達成しています。*

ヒント:

- VidEoMTは現在、DINOv2バックボーン（register tokens付き）のみをサポートしています。利用可能なモデルサイズはViT-S、ViT-B、ViT-Lです。
- モデルは、`(batch_size, num_frames, 3, height, width)` の形状を持つ 5 次元テンソルとして動画入力を受け入れます。
- VidEoMTは3つの動画セグメンテーションタスクをサポートしています:**インスタンス**、**セマンティック**、および**パノプティック**セグメンテーションです。それぞれについて、動画プロセッサに専用の後処理メソッドが用意されています。

このモデルは [nielsr](https://huggingface.co/nielsr) によって提供されました。元のコードは [こちら](https://github.com/tue-mps/videomt) で確認できます。

## アーキテクチャ情報

VidEoMTは、**register tokens**を備えた通常のDINOv2事前学習済みVision Transformerをセグメンテーションモデルとして再利用する[EoMT](./eomt)を基盤としています。EoMTは、ViTエンコーダー内に直接、学習された**object queries**と軽量な**mask prediction head**を導入することで、タスク固有のデコーダーの必要性を排除しています。

VidEoMTは、次の2つの重要な追加要素により、これを動画に拡張します。

1. **クエリの伝播**: 前フレームのオブジェクトクエリは、線形射影（`query_updater`）を通じて次のフレームに引き継がれ、専用のトラッカーを用いずに時間的な推論を可能にします。
2. **クエリ融合**: 伝播されたクエリに、時間的に依存しない学習済みクエリのセットを加えることで、動画に新たに出現するオブジェクトに適応できるようにします。

初期のエンコーダ層はすべてのフレームを独立して（並列に）処理しますが、最終ブロックは融合されたクエリを用いてフレームごとに動作し、フレームごとのマスクとクラスの予測を生成します。

## 使用例

Hugging Face による VidEoMT の実装を使用して、事前学習済みモデルで推論を実行します。以下の例では、サンプル動画に対する動画インスタンス、セマンティック、パノプティックのポストプロセッシングをデモするために、公開されている `tue-mps/videomt-dinov2-small-ytvis2019` チェックポイントを再利用しています。

### Video Instance Segmentation

```python
import matplotlib.pyplot as plt
import numpy as np
import torch

from transformers import AutoModelForUniversalSegmentation, AutoVideoProcessor
from transformers.video_utils import load_video

model_id = "tue-mps/videomt-dinov2-small-ytvis2019"
processor = AutoVideoProcessor.from_pretrained(model_id)
model = AutoModelForUniversalSegmentation.from_pretrained(model_id, device_map="auto")

video_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/videos/pexels-allan-mas-5362370.mp4"
# Sample 8 frames to keep the example lightweight.
video_frames, _ = load_video(video_url, num_frames=8)

inputs = processor(videos=[video_frames], return_tensors="pt").to(model.device)

with torch.inference_mode():
    outputs = model(**inputs)

original_height, original_width = video_frames[0].shape[:2]
target_sizes = [(original_height, original_width)] * len(video_frames)

results = processor.post_process_instance_segmentation(
    outputs,
    target_sizes=target_sizes,
)

fig, axes = plt.subplots(2, 4, figsize=(16, 8))
for idx, (ax, frame, result) in enumerate(zip(axes.flatten(), video_frames, results)):
    ax.imshow(frame)
    seg = result["segmentation"].cpu().numpy()
    masked = np.ma.masked_where(seg == -1, seg)
    ax.imshow(masked, alpha=0.6, cmap="tab20")
    ax.set_title(f"Frame {idx}")
    ax.axis("off")
plt.suptitle("Video Instance Segmentation")
plt.tight_layout()
plt.show()
```

### ビデオセマンティックセグメンテーション

```python
import matplotlib.pyplot as plt
import torch

from transformers import AutoModelForUniversalSegmentation, AutoVideoProcessor
from transformers.video_utils import load_video

model_id = "tue-mps/videomt-dinov2-small-ytvis2019"
processor = AutoVideoProcessor.from_pretrained(model_id)
model = AutoModelForUniversalSegmentation.from_pretrained(model_id, device_map="auto")

video_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/videos/pexels-allan-mas-5362370.mp4"
# Sample 8 frames to keep the example lightweight.
video_frames, _ = load_video(video_url, num_frames=8)

inputs = processor(videos=[video_frames], return_tensors="pt").to(model.device)

with torch.inference_mode():
    outputs = model(**inputs)

original_height, original_width = video_frames[0].shape[:2]
target_sizes = [(original_height, original_width)] * len(video_frames)

preds = processor.post_process_semantic_segmentation(
    outputs,
    target_sizes=target_sizes,
)

fig, axes = plt.subplots(2, 4, figsize=(16, 8))
for idx, (ax, frame, seg_map) in enumerate(zip(axes.flatten(), video_frames, preds)):
    ax.imshow(frame)
    ax.imshow(seg_map.cpu().numpy(), alpha=0.6, cmap="tab20")
    ax.set_title(f"Frame {idx}")
    ax.axis("off")
plt.suptitle("Video Semantic Segmentation")
plt.tight_layout()
plt.show()
```

### Video Panoptic Segmentation

```python
import matplotlib.pyplot as plt
import numpy as np
import torch

from transformers import AutoModelForUniversalSegmentation, AutoVideoProcessor
from transformers.video_utils import load_video

model_id = "tue-mps/videomt-dinov2-small-ytvis2019"
processor = AutoVideoProcessor.from_pretrained(model_id)
model = AutoModelForUniversalSegmentation.from_pretrained(model_id, device_map="auto")

video_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/videos/pexels-allan-mas-5362370.mp4"
# Sample 8 frames to keep the example lightweight.
video_frames, _ = load_video(video_url, num_frames=8)

inputs = processor(videos=[video_frames], return_tensors="pt").to(model.device)

with torch.inference_mode():
    outputs = model(**inputs)

original_height, original_width = video_frames[0].shape[:2]
target_sizes = [(original_height, original_width)] * len(video_frames)

results = processor.post_process_panoptic_segmentation(
    outputs,
    target_sizes=target_sizes,
)

fig, axes = plt.subplots(2, 4, figsize=(16, 8))
for idx, (ax, frame, result) in enumerate(zip(axes.flatten(), video_frames, results)):
    ax.imshow(frame)
    seg = result["segmentation"].cpu().numpy()
    masked = np.ma.masked_where(seg == -1, seg)
    ax.imshow(masked, alpha=0.6, cmap="tab20")
    ax.set_title(f"Frame {idx}")
    ax.axis("off")
plt.suptitle("Video Panoptic Segmentation")
plt.tight_layout()
plt.show()
```

## VideomtVideoProcessor[[transformers.VideomtVideoProcessor]]

#### transformers.VideomtVideoProcessor[[transformers.VideomtVideoProcessor]]

```python
transformers.VideomtVideoProcessor(**kwargs: *<class 'transformers.processing_utils.VideosKwargs'>)
```

[ソース](https://github.com/huggingface/transformers/blob/main/src/transformers/models/videomt/video_processing_videomt.py#L147)

**パラメータ:**

do_convert_rgb (`bool`, *kwargs*, *optional*, デフォルトは `True`) : 画像を RGB に変換するかどうか。

do_resize (`bool`, *kwargs*, *任意*, デフォルトは `True`) : 画像をリサイズするかどうか。

size (`Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]`, *kwargs*、デフォルト値は`{'height' : 640, 'width': 640}`): モデルへの最大入力次元を記述します。

default_to_square (`bool`, *kwargs*, *任意*、デフォルトは `True`) : size が整数の場合、リサイズ時に正方形の画像をデフォルトとするかどうか。

resample (`Annotated[Union[int, PILImageResampling, NoneType], None]`, *kwargs*、デフォルト値は`2`) : 画像のリサイズ時に使用するリサンプリングフィルタです。これは列挙型`PILImageResampling`のいずれかになります。`do_resize`が`True`に設定されている場合のみ、効果が現れます。

do_rescale (`bool`, *kwargs*, *optional*, デフォルトは `True`) : 画像をリスケールするかどうか。

rescale_factor (`float`, *kwargs*, *optional*, デフォルトは `0.00392156862745098`) : `do_rescale` が `True` に設定されている場合、画像をリスケールするための係数。

do_normalize (`bool`, *kwargs*, *optional*, デフォルトは `True`) : 画像を正規化するかどうかを指定します。

image_mean (`Union[float, list[float], tuple[float, ...]]`, *kwargs*, *optional*, デフォルトは `[0.485, 0.456, 0.406]`) : 正規化に使用する画像の平均値です。`do_normalize` が `True` に設定されている場合のみ有効です。

image_std (`Union[float, list[float], tuple[float, ...]]`, *kwargs*, *optional*, デフォルトは `[0.229, 0.224, 0.225]`) : 正規化に使用する画像の標準偏差。`do_normalize` が `True` に設定されている場合のみ有効です。

do_center_crop (`bool`, *kwargs*, *optional*, デフォルトは `False`) : 画像を中央クロップするかどうか。

do_pad (`bool`, *kwargs*, *任意*) : 画像にパディングを適用するかどうか。パディングは、バッチ内の最大サイズに合わせるか、画像ごとに固定の正方形サイズに合わせるかのいずれかで行われます。正確なパディング戦略はモデルによって異なります。

crop_size (`Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]`, *kwargs*) : `center_crop` を適用した後の出力画像のサイズ。

data_format (`Union[str, ~image_utils.ChannelDimension]`、*kwargs*、*optional*) : 対応するのは `ChannelDimension.FIRST` のみです。slow processors との互換性のために追加されました。

input_data_format (`Union[str, ~image_utils.ChannelDimension]`, *kwargs*, *任意*) : 入力画像のチャネル次元の形式です。設定されていない場合、入力画像からチャネル次元の形式が推論されます。以下のいずれかになります: - `"channels_first"` または `ChannelDimension.FIRST`: (num_channels, height, width) 形式の画像。 - `"channels_last"` または `ChannelDimension.LAST`: (height, width, num_channels) 形式の画像。 - `"none"` または `ChannelDimension.NONE`: (height, width) 形式の画像。

device (`Annotated[Union[str, torch.device, NoneType], None]`, *kwargs*) : 動画を処理するデバイスです。未設定の場合、入力動画からデバイスが推論されます。

do_sample_frames (`bool`, *kwargs*, *optional*, デフォルトは `False`) : 処理前に動画からフレームをサンプリングするか、動画全体を処理するかを指定します。

video_metadata (`Annotated[~video_utils.VideoMetadata | dict | list[dict | ~video_utils.VideoMetadata] | list[list[dict | ~video_utils.VideoMetadata]] | None, None]`, *kwargs*) : 動画のメタデータ。総再生時間、fps、総フレーム数などの情報を含みます。動画からのフレームサンプリングやタイムスタンプの計算に使用されます。動画を処理する前に手動でデコードしようとしている場合を除き、メタデータは渡さないでください。

fps (`Annotated[int | float | None, None]`, *kwargs*) : `do_sample_frames=True` の場合、1 秒あたりにサンプリングするターゲットフレーム数。

num_frames (`Annotated[int | None, None]`, *kwargs*) : `do_sample_frames=True` の場合、サンプリングするフレームの最大数。

return_metadata (`bool`, *kwargs*, *任意*、デフォルトは `False`) : ビデオメタデータを返すかどうかを指定します。ビデオメタデータは、ビデオの長さ、fps、デコードバックエンドなどの情報を含むオブジェクトです。

return_tensors (`Annotated[str | ~utils.generic.TensorType | None, None]`, *kwargs*) : 設定されている場合、特定のフレームワークのテンソルを返します。許可される値は以下の通りです。 - `'pt'`: PyTorch の `torch.Tensor` オブジェクトを返します。 - `'np'`: NumPy の `np.ndarray` オブジェクトを返します。

- ****kwargs** ([VideosKwargs](/docs/transformers/main/ja/main_classes/processors#transformers.VideosKwargs)、*optional*) : 各モダリティ（テキスト、画像、動画、音声）の追加処理オプションです。モデル固有のパラメータは上記に記載されています。サポートされている引数の完全なリストについては、TypedDict クラスを参照してください。

VideomtVideoProcessor ビデオプロセッサを構築します。

#### post_process_semantic_segmentation[[transformers.VideomtVideoProcessor.post_process_semantic_segmentation]]

```python
post_process_semantic_segmentation(outputs, target_sizes: list, return_segmentation_scores: bool = False)
```

[ソース](https://github.com/huggingface/transformers/blob/main/src/transformers/models/videomt/video_processing_videomt.py#L178)

**パラメータ:**

outputs (`VideomtForUniversalSegmentationOutput`) : モデルの生出力。

target_sizes (`list[tuple[int, int]]`) : 各予測の要求された最終サイズに対応する`(height, width)`のタプルのリストです。長さは出力のフレーム数と一致する必要があります。

return_segmentation_scores (`bool`、*任意*、デフォルトは`False`) : セグメンテーションマップとともにセグメンテーションスコアを返すかどうか。`True`の場合、返されるリストの各要素は、`segmentation`（クラス ID、形状`(height, width)`）と`segmentation_scores`（形状`(num_classes, height, width)`）というフィールドを持つ`SemanticSegmentationPostProcessorOutput`です。

**戻り値:** `list[torch.Tensor]` または `list[SemanticSegmentationPostProcessorOutput]`

`return_segmentation_scores=False` (デフォルト)の場合、各要素がクラス ID を持つ `(height, width)` のセグメンテーションマップである、長さ `batch_size` のリストが返されます。`return_segmentation_scores=True` の場合、フィールド `segmentation` (クラス ID、形状 `(height, width)`) と `segmentation_scores` (形状 `(num_classes, height, width)`) を持つ `SemanticSegmentationPostProcessorOutput` のリストが返されます。どちらの場合も、`(height, width)` はターゲットサイズに対応します。

[VideomtForUniversalSegmentation](/docs/transformers/main/ja/model_doc/videomt#transformers.VideomtForUniversalSegmentation) の出力をセマンティックセグメンテーションの予測に変換します。

#### post_process_instance_segmentation[[transformers.VideomtVideoProcessor.post_process_instance_segmentation]]

```python
post_process_instance_segmentation(outputs, target_sizes: list, threshold: float = 0.5)
```

[ソース](https://github.com/huggingface/transformers/blob/main/src/transformers/models/videomt/video_processing_videomt.py#L232)

**パラメータ:**

outputs (`VideomtForUniversalSegmentationOutput`) : モデルの生出力。

target_sizes (`list[tuple[int, int]]`) : 各予測の要求された最終サイズに対応する`(height, width)`のタプルのリストです。長さは出力のフレーム数と一致する必要があります。

threshold (`float`、*任意*、デフォルトは 0.5) : インスタンスを保持するための最小の合計スコア。

**戻り値:** `list[dict]`

各フレームに対応する辞書のリスト（各辞書には以下が含まれます）：
- `"segmentation"` -- インスタンス ID(背景の場合は -1)を持つ、形状が `(height, width)` の `torch.Tensor`。
- `"segments_info"` -- 各インスタンスについて`"id"`、`"label_id"`、`"score"`を含む辞書のリスト。

[VideomtForUniversalSegmentation](/docs/transformers/main/ja/model_doc/videomt#transformers.VideomtForUniversalSegmentation)の出力をインスタンスセグメンテーションの予測に変換します。

#### post_process_panoptic_segmentation[[transformers.VideomtVideoProcessor.post_process_panoptic_segmentation]]

```python
post_process_panoptic_segmentation(outputs, target_sizes: list, threshold: float = 0.8, mask_threshold: float = 0.5, overlap_mask_area_threshold: float = 0.8, label_ids_to_fuse: set[int] | None = None)
```

[ソース](https://github.com/huggingface/transformers/blob/main/src/transformers/models/videomt/video_processing_videomt.py#L301)

**パラメータ:**

outputs (`VideomtForUniversalSegmentationOutput`) : モデルの生出力。

target_sizes (`list[tuple[int, int]]`) : 各予測の要求された最終サイズに対応する`(height, width)`のタプルのリストです。長さは出力のフレーム数と一致する必要があります。

threshold (`float`、*任意*、デフォルトは 0.8) : 予測されたセグメントを保持するための最小スコア。

mask_threshold (`float`、*任意*、デフォルトは 0.5) : マスクの確率を二値化するための閾値。

overlap_mask_area_threshold (`float`、*任意*、デフォルトは 0.8) : マスクを単一のセグメントにマージするためのオーバーラップしきい値。

label_ids_to_fuse (`set[int]`, *任意*) : 非連結領域間で融合すべきラベル ID。

**戻り値:** `list[dict]`

各フレームに対応する辞書のリスト（各辞書には以下が含まれます）：
- `"segmentation"` -- セグメント ID(背景の場合は -1)を持つ、形状が `(height, width)` の `torch.Tensor`。
- `"segments_info"` -- 各セグメントの`"id"`、`"label_id"`、`"score"`を含む辞書のリスト。

[VideomtForUniversalSegmentation](/docs/transformers/main/ja/model_doc/videomt#transformers.VideomtForUniversalSegmentation)の出力をパノプティックセグメンテーション予測に変換します。

## VideomtConfig[[transformers.VideomtConfig]]

#### transformers.VideomtConfig[[transformers.VideomtConfig]]

```python
transformers.VideomtConfig(transformers_version: str | None = None, architectures: list[str] | None = None, output_hidden_states: bool | None = False, return_dict: bool | None = True, dtype: str | torch.dtype | None = None, chunk_size_feed_forward: int = 0, is_encoder_decoder: bool = False, id2label: dict[int, str] | dict[str, str] | None = None, label2id: dict[str, int] | dict[str, str] | None = None, problem_type: Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = None, hidden_size: int = 1024, num_hidden_layers: int = 24, num_attention_heads: int = 16, hidden_act: str = 'gelu', hidden_dropout_prob: float | int = 0.0, initializer_range: float = 0.02, layer_norm_eps: float = 1e-06, image_size: int | list[int] | tuple[int, int] = 640, patch_size: int | list[int] | tuple[int, int] = 16, num_channels: int = 3, mlp_ratio: int = 4, layerscale_value: float = 1.0, drop_path_rate: float | int = 0.0, num_upscale_blocks: int = 2, attention_dropout: float | int = 0.0, use_swiglu_ffn: bool = False, num_blocks: int = 4, no_object_weight: float = 0.1, class_weight: float = 2.0, mask_weight: float = 5.0, dice_weight: float = 5.0, train_num_points: int = 12544, oversample_ratio: float = 3.0, importance_sample_ratio: float = 0.75, num_queries: int = 200, num_register_tokens: int = 4)
```

[ソース](https://github.com/huggingface/transformers/blob/main/src/transformers/models/videomt/configuration_videomt.py#L29)

**パラメータ:**

hidden_size (`int`、*任意*、デフォルトは`1024`) : 隠れ表現の次元数。

num_hidden_layers (`int`、*optional*、デフォルトは `24`) : Transformer デコーダーの隠れ層の数。

num_attention_heads (`int`、*任意*、デフォルトは`16`) : Transformerデコーダーの各アテンション層におけるアテンションヘッドの数。

hidden_act (`str`、*任意*、デフォルトは`gelu`) : デコーダーで使用する非線形活性化関数（関数または文字列）。例えば、`"gelu"`、`"relu"`、`"silu"`など。

hidden_dropout_prob (`Union[float, int]`、*任意*、デフォルトは`0.0`) : embeddings、encoder、pooler 内のすべての全結合層における dropout 確率。

initializer_range (`float`、*任意*、デフォルトは`0.02`) : すべての重み行列を初期化するためのtruncated_normal_initializerの標準偏差です。

layer_norm_eps (`float`、*任意*、デフォルトは`1e-06`) : Layer Normalization 層で使用する epsilon です。

image_size (`Union[int, list[int], tuple[int, int]]`、*任意*、デフォルトは`640`) : 各画像のサイズ（解像度）。

patch_size (`Union[int, list[int], tuple[int, int]]`、*任意*、デフォルトは`16`) : 各パッチのサイズ（解像度）。

num_channels (`int`、*任意*、デフォルトは`3`) : 入力チャネル数。

mlp_ratio (`int`、*任意*、デフォルトは`4`) : MLPの隠れ層次元と埋め込み次元の比率。

layerscale_value (`float`、*任意*、デフォルト値は 1.0) : LayerScale パラメータの初期値。

drop_path_rate (`Union[float, int]`、*任意*、デフォルトは`0.0`) : パッチ融合のドロップパス率。

num_upscale_blocks (`int`、*optional*、デフォルトは 2) : デコーダーまたはセグメンテーションヘッドで使用するアップサンプリングブロックの数。

attention_dropout (`Union[float, int]`、*任意*、デフォルトは`0.0`) : 注意確率のドロップアウト率。

use_swiglu_ffn (`bool`, *任意*, デフォルトは `False`) : SwiGLUフィードフォワードニューラルネットワークを使用するかどうか。

num_blocks (`int`、*任意*、デフォルトは 4) : アーキテクチャにおける特徴量ブロックまたはステージの数。

no_object_weight (`float`、*任意*、デフォルト値は 0.1) : パノプティック/インスタンスセグメンテーションにおける 'no object' クラスの損失重み。

class_weight (`float`、*任意*、デフォルト値は 2.0) : 分類ターゲットの損失重み。

mask_weight (`float`、*任意*、デフォルト値は 5.0) : マスク予測の損失重み。

dice_weight (`float`、*任意*、デフォルトは `5.0`) : パノプティックセグメンテーション損失における dice loss の相対的な重み。

train_num_points (`int`、*optional*、デフォルトは 12544) : 学習中のマスク損失の計算のためにサンプリングする点の数。

oversample_ratio (`float`、*任意*、デフォルト値は 3.0) : マスク学習におけるポイントサンプリングで使用するオーバーサンプリング比率。

importance_sample_ratio (`float`、*任意*、デフォルトは 0.75) : 学習中に重要度に基づいてサンプリングするポイントの比率。

num_queries (`int`、*任意*、デフォルトは 200) : Transformer におけるオブジェクトクエリの数。

num_register_tokens (`int`、*任意*、デフォルトは 4) : Transformer の入力に追加される学習可能なレジスタトークンの数。

これはVideomtModelの設定を保存するための設定クラスです。指定された引数に基づいてVideomtモデルをインスタンス化し、モデルのアーキテクチャを定義するために使用されます。デフォルト値で設定をインスタンス化すると、[tue-mps/videomt-dinov2-small-ytvis2019](https://huggingface.co/tue-mps/videomt-dinov2-small-ytvis2019)と類似した設定が得られます。

設定オブジェクトは [PreTrainedConfig](/docs/transformers/main/ja/main_classes/configuration#transformers.PreTrainedConfig) を継承し、モデルの出力を制御するために使用できます。詳細については、[PreTrainedConfig](/docs/transformers/main/ja/main_classes/configuration#transformers.PreTrainedConfig) のドキュメントを参照してください。

例:

```python
>>> from transformers import VideomtConfig, VideomtForUniversalSegmentation

>>> # Initialize configuration
>>> config = VideomtConfig()

>>> # Initialize model
>>> model = VideomtForUniversalSegmentation(config)

>>> # Access config
>>> config = model.config
```

## VideomtPreTrainedModel[[transformers.VideomtPreTrainedModel]]

#### transformers.VideomtPreTrainedModel[[transformers.VideomtPreTrainedModel]]

```python
transformers.VideomtPreTrainedModel(config: PreTrainedConfig, *inputs, **kwargs)
```

[ソース](https://github.com/huggingface/transformers/blob/main/src/transformers/models/videomt/modeling_videomt.py#L924)

**パラメータ:**

config ([PreTrainedConfig](/docs/transformers/main/ja/main_classes/configuration#transformers.PreTrainedConfig)) : モデルのパラメータをすべて含むモデル設定クラスです。設定ファイルで初期化しても、モデルに関連する重みは読み込まれず、設定のみが読み込まれます。モデルの重みをロードするには、[from_pretrained()](/docs/transformers/main/ja/main_classes/model#transformers.PreTrainedModel.from_pretrained) メソッドを確認してください。

このモデルは [PreTrainedModel](/docs/transformers/main/ja/main_classes/model#transformers.PreTrainedModel) を継承しています。ライブラリがすべてのモデルに対して実装している汎用的なメソッド（ダウンロードや保存、入力埋め込みのリサイズ、ヘッドのプルーニングなど）については、スーパークラスのドキュメントを参照してください。

このモデルは、PyTorchの[torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module)のサブクラスでもあります。通常のPyTorch Moduleとして使用し、一般的な使用方法や動作に関する詳細については、PyTorchのドキュメントを参照してください。

#### forward[[transformers.VideomtPreTrainedModel.forward]]

```python
forward(*args, **kwargs)
```

ドット区切りパス（例: `torch.float32`）に対するモック値: 属性アクセスのチェーン、呼び出しはパススルーデコレータとして動作し、`repr` はドット区切りパスを返し、ベースクラスとして使用するとプレーンな `type` ベースに置き換えられます（PEP 560 の `__mro_entries__`）。これにより、実際のサブクラスは通常のメタクラスを保持し、`inspect.signature` はモックのものではなく実際の `__init__` を読み取ります。

## VideomtForUniversalSegmentation[[transformers.VideomtForUniversalSegmentation]]

#### transformers.VideomtForUniversalSegmentation[[transformers.VideomtForUniversalSegmentation]]

```python
transformers.VideomtForUniversalSegmentation(config: VideomtConfig)
```

[ソース](https://github.com/huggingface/transformers/blob/main/src/transformers/models/videomt/modeling_videomt.py#L1044)

**パラメータ:**

config ([VideomtConfig](/docs/transformers/main/ja/model_doc/videomt#transformers.VideomtConfig)) : モデルのパラメータをすべて含むモデル設定クラスです。設定ファイルで初期化しても、モデルに関連する重みは読み込まれず、設定のみが読み込まれます。モデルの重みをロードするには、[from_pretrained()](/docs/transformers/main/ja/main_classes/model#transformers.PreTrainedModel.from_pretrained) メソッドを確認してください。

インスタンス/セマンティック/パンオプティックセグメンテーション用のヘッドを上部に備えたVideomtモデル。

このモデルは [PreTrainedModel](/docs/transformers/main/ja/main_classes/model#transformers.PreTrainedModel) を継承しています。ライブラリがすべてのモデルに対して実装している汎用的なメソッド（ダウンロードや保存、入力埋め込みのリサイズ、ヘッドのプルーニングなど）については、スーパークラスのドキュメントを参照してください。

このモデルは、PyTorchの[torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module)のサブクラスでもあります。通常のPyTorch Moduleとして使用し、一般的な使用方法や動作に関する詳細については、PyTorchのドキュメントを参照してください。

#### forward[[transformers.VideomtForUniversalSegmentation.forward]]

```python
forward(pixel_values_videos: typing.Optional[torch.Tensor] = None, mask_labels: list[torch.Tensor] | None = None, class_labels: list[torch.Tensor] | None = None, patch_offsets: list[torch.Tensor] | None = None, **kwargs: *<class 'transformers.utils.generic.TransformersKwargs'>)
```

[ソース](https://github.com/huggingface/transformers/blob/main/src/transformers/models/videomt/modeling_videomt.py#L1103)

**パラメータ:**

pixel_values_videos (`torch.Tensor`, *任意*) : 形状が`(batch_size, num_frames, num_channels, height, width)`の動画入力。

mask_labels (`list[torch.Tensor]`、*optional*) : 5次元の動画入力には対応していません。

class_labels (`list[torch.LongTensor]`、*optional*) : 5次元の動画入力には対応していません。

patch_offsets (`list[torch.Tensor]`, *任意*) : 動画入力では使用されず、モジュール互換性のためにのみ保持されています。

**戻り値:** `VideomtForUniversalSegmentationOutput` または `tuple(torch.Tensor)`

`VideomtForUniversalSegmentationOutput`または`torch.Tensor`のタプル（`return_dict=False`が渡された場合、または`config.return_dict=False`の場合）。[VideomtConfig](/docs/transformers/main/ja/model_doc/videomt#transformers.VideomtConfig)および入力に応じて、さまざまな要素で構成されます。

[VideomtForUniversalSegmentation](/docs/transformers/main/ja/model_doc/videomt#transformers.VideomtForUniversalSegmentation)のforwardメソッドは、`__call__`特殊メソッドをオーバーライドします。

この関数内でフォワードパスの手順を定義する必要がありますが、その後、この関数ではなく`Module`インスタンスを呼び出すべきです。前者は前処理と後処理の実行を適切に処理するのに対し、後者はそれらを無視してしまいます。

- **loss** (`torch.Tensor`, *optional*) -- ラベルが存在する場合に返される、計算された損失。
- **class_queries_logits** (`torch.Tensor`, *optional*) -- 各クエリに対して提案されるクラスを表す、形状が`(batch_size, num_queries, num_labels + 1)`のテンソルです。`+ 1`は、nullクラスを組み込む必要があるためです。
- **masks_queries_logits** (`torch.Tensor`, *オプション*) -- 各クエリに対する提案マスクを表す、形状が`(batch_size, num_queries, height, width)`のテンソル。
- **last_hidden_state** (`torch.Tensor`、形状 `(batch_size, num_channels, height, width)`) -- 最終層の最後の隠れ状態（最終的な特徴マップ）。
- **hidden_states** (`tuple(torch.Tensor)`、*optional*、`output_hidden_states=True` が渡された場合または `config.output_hidden_states=True` の場合に返されます) -- `torch.Tensor` のタプル（埋め込みの出力用 1 つ + 各ステージの出力用 1 つ）、形状は `(batch_size, sequence_length, hidden_size)`。モデルの全レイヤーの隠れ状態です。
- **attentions** (`tuple(tuple(torch.Tensor))`、*optional*、`output_attentions=True` が渡された場合または `config.output_attentions=True` の場合に返されます) -- 各レイヤーごとに1つの `tuple(torch.Tensor)` からなるタプルで、形状は `(batch_size, num_heads, sequence_length, sequence_length)` です。Transformer デコーダーからの Self Attention と Cross Attention の重みです。

