Transformers documentation

EoMT

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v5.22.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

このモデルは2025年3月24日にHF papersで公開され、2025年6月27日にHugging Face Transformersに貢献されました。

EoMT

概要

The Encoder-only Mask Transformer (EoMT) モデルは、Tommie Kerssies、Niccolò Cavagnero、Alexander Hermans、Narges Norouzi、Giuseppe Averta、Bastian Leibe、Gijs Dubbelman、Daan de Geus による CVPR 2025 のハイライト論文 Your ViT is Secretly an Image Segmentation Model で紹介されました。 EoMT は、Vision Transformers がタスク固有のコンポーネントなしに効率的に画像セグメンテーションを実行できることを示しています。

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

Vision Transformers (ViTs) は、さまざまなコンピュータビジョンタスクにおいて、優れた性能とスケーラビリティを示してきました。単一スケールの ViT を画像セグメンテーションに適用するため、既存の方法では、マルチスケール特徴を生成するための畳み込みアダプタ、これらの特徴を融合するためのピクセルデコーダ、そして融合された特徴を用いて予測を行う Transformer デコーダを採用しています。本論文では、十分に大きなモデルと広範な事前学習が与えられた場合、これらのタスク固有のコンポーネントによって導入される帰納的バイアスは、ViT 自体によって学習され得ることを示します。これらの知見に基づき、プレーンな ViT アーキテクチャを再利用して画像セグメンテーションを行う Encoder-only Mask Transformer (EoMT) を提案します。大規模なモデルと事前学習により、EoMT は、タスク固有のコンポーネントを使用する最先端モデルと同等のセグメンテーション精度を達成します。同時に、EoMT はそのアーキテクチャの簡素さにより、これらの方法よりも大幅に高速であり、例えば ViT-L を使用する場合、最大で 4 倍高速です。EoMT は、幅広いモデルサイズにおいて、セグメンテーション精度と予測速度の間の最適なバランスを示しており、計算リソースはアーキテクチャの複雑さを増やすよりも、ViT 自体のスケーリングに費やされるべきであることを示唆しています。

このモデルはYaswanth Gali氏によって提供されました。 元のコードはこちらで確認できます。

アーキテクチャ情報

EoMTモデルは、register tokensを備えたDINOv2事前学習済みのVision Transformerをバックボーンとして使用しています。EoMTはエンコーダーのみを頼りにセグメンテーションのパイプラインを簡素化し、従来のアプローチで一般的に使用されていたタスク固有のデコーダーの必要性を排除しています。

アーキテクチャの観点から、EoMT は 学習されたクエリの小さなセットと、軽量な マスク予測モジュールを導入します。これらのクエリはエンコーダの最終ブロックに注入され、画像パッチとオブジェクトクエリ間の ジョイントアテンションを可能にします。学習時には、マスク付きアテンションを適用して、各クエリが対応する領域に焦点を当てるよう制約します。これにより、クロスアテンションを効果的に模倣します。この制約は マスクアニーリング戦略によって段階的に解除され、セグメンテーション性能を損なうことなく、デコーダ不要の効率的な推論を実現します。

drawing

このモデルは、統一されたアーキテクチャとタスク固有の後処理を用いて、セマンティックセグメンテーション、インスタンスセグメンテーション、パノプティックセグメンテーションをサポートします。

使用例

事前学習済みモデルでの推論には、Hugging Face による EoMT の実装を使用します。

セマンティックセグメンテーション

EoMTモデルは、スライディングウィンドウ推論を用いてセマンティックセグメンテーションを実行します。入力画像は、短い辺がターゲット入力サイズに一致するようにリサイズされ、その後、重複するクロップに分割されます。各クロップはモデルに渡されます。推論後、各クロップから得られた予測ロジットは再結合され、元の画像サイズにリスケールされることで、最終的なセグメンテーションマスクが得られます。

注:
セマンティックセグメンテーションでカスタムのターゲットサイズを使用する場合は、以下の形式で指定してください:
{"shortest_edge": 512}
ここではlongest_edgeが指定されていませんが、これは意図的なものです。セマンティックセグメンテーションでは、画像は通常、最短辺がターゲットサイズ以上になるようにスケーリングされるため、longest_edgeは不要です。

import matplotlib.pyplot as plt
import requests
import torch
from PIL import Image

from transformers import AutoImageProcessor, EomtForUniversalSegmentation


model_id = "tue-mps/ade20k_semantic_eomt_large_512"
processor = AutoImageProcessor.from_pretrained(model_id)
model = EomtForUniversalSegmentation.from_pretrained(model_id, device_map="auto")

image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)

inputs = processor(
    images=image,
    return_tensors="pt",
)

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

# Prepare the original image size in the format (height, width)
target_sizes = [(image.height, image.width)]

# Post-process the model outputs to get final segmentation prediction
preds = processor.post_process_semantic_segmentation(
    outputs,
    target_sizes=target_sizes,
)

# Visualize the segmentation mask
plt.imshow(preds[0])
plt.axis("off")
plt.title("Semantic Segmentation")
plt.show()

インスタンスセグメンテーション

EoMTモデルは、パディング付き推論を用いてインスタンスセグメンテーションを実行します。入力画像は、長い辺がターゲット入力サイズに一致するようにリサイズされ、短い辺はゼロパディングによって正方形に整形されます。生成されたマスクとクラスロジットは、後処理(Mask2Formerから適応)を通じて結合され、統合されたインスタンスセグメンテーションマップが生成されます。これには、セグメントID、クラスラベル、信頼度スコアなどのセグメントメタデータも含まれます。

注:
カスタムのターゲットサイズを使用するには、以下の形式の辞書としてサイズを指定します:
{"shortest_edge": 512, "longest_edge": 512}
インスタンスセグメンテーションとパノプティックセグメンテーションの両方で、入力画像はこのターゲットサイズにスケーリングおよびパディングされます。

import matplotlib.pyplot as plt
import requests
import torch
from PIL import Image

from transformers import AutoImageProcessor, EomtForUniversalSegmentation


model_id = "tue-mps/coco_instance_eomt_large_640"
processor = AutoImageProcessor.from_pretrained(model_id)
model = EomtForUniversalSegmentation.from_pretrained(model_id, device_map="auto")

image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)

inputs = processor(
    images=image,
    return_tensors="pt",
)

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

# Prepare the original image size in the format (height, width)
target_sizes = [(image.height, image.width)]

# Post-process the model outputs to get final segmentation prediction
preds = processor.post_process_instance_segmentation(
    outputs,
    target_sizes=target_sizes,
)

# Visualize the segmentation mask
plt.imshow(preds[0]["segmentation"])
plt.axis("off")
plt.title("Instance Segmentation")
plt.show()

パンセグメンテーション

EoMTモデルは、インスタンスセグメンテーションと同じパディング付き推論戦略を用いてパンノミックセグメンテーションを実行します。パディングと正規化の後、モデルはthing(インスタンス)クラスとstuff(不定形領域)クラスの両方を予測します。得られたマスクとクラスロジットは、後処理(Mask2Formerから適応)を通じて統合され、統一されたパンノミックセグメンテーションマップが生成されます。これには、セグメントID、クラスラベル、信頼度スコアなどのセグメントメタデータも含まれます。

import matplotlib.pyplot as plt
import requests
import torch
from PIL import Image

from transformers import AutoImageProcessor, EomtForUniversalSegmentation


model_id = "tue-mps/coco_panoptic_eomt_large_640"
processor = AutoImageProcessor.from_pretrained(model_id)
model = EomtForUniversalSegmentation.from_pretrained(model_id, device_map="auto")

image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)

inputs = processor(
    images=image,
    return_tensors="pt",
)

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

# Prepare the original image size in the format (height, width)
target_sizes = [(image.height, image.width)]

# Post-process the model outputs to get final segmentation prediction
preds = processor.post_process_panoptic_segmentation(
    outputs,
    target_sizes=target_sizes,
)

# Visualize the panoptic segmentation mask
plt.imshow(preds[0]["segmentation"])
plt.axis("off")
plt.title("Panoptic Segmentation")
plt.show()

EomtImageProcessor

クラス transformers.EomtImageProcessor

< >

( **kwargs: *<class 'transformers.models.eomt.image_processing_eomt.EomtImageProcessorKwargs'> )

パラメータ

  • do_convert_rgb (bool、kwargs、任意) — 画像を RGB に変換するかどうかを指定します。
  • do_resize (bool、kwargs、任意、デフォルトはTrue) — 画像をリサイズするかどうか。
  • size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs, デフォルトは {'shortest_edge' -- 640, 'longest_edge': 640}): モデルへの最大入力サイズを指定します。
  • default_to_square (bool、kwargs、任意、デフォルトは False) — size が整数の場合、リサイズ時に正方形の画像をデフォルトとするかどうか。
  • crop_size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — center_crop を適用した後の出力画像のサイズ。
  • resample (Annotated[Union[int, PILImageResampling, NoneType], None], kwargs, デフォルトは 2) — 画像のリサイズ時に使用するリサンプリングフィルタです。PILImageResampling の列挙型のいずれかを使用できます。do_resize が True に設定されている場合のみ、効果が現れます。
  • do_rescale (bool、kwargs、任意、デフォルトはTrue) — 画像をリスケールするかどうかを指定します。
  • rescale_factor (float、kwargs、任意、デフォルト値は 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_pad (bool、kwargs、optional、デフォルトは False) — 画像をパディングするかどうかを指定します。パディングは、バッチ内の最大サイズに合わせるか、画像ごとに固定の正方形サイズに合わせるかのいずれかで行われます。具体的なパディング戦略はモデルによって異なります。
  • pad_size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — 画像をパディングする {"height": int, "width" int} のサイズです。前処理に提供されるすべての画像サイズより大きくなければなりません。pad_size が指定されない場合、バッチ内の最大の幅と高さにパディングされます。do_pad=True. の場合のみ適用されます。
  • do_center_crop (bool, kwargs, optional) — 画像を中央クロップするかどうかを指定します。
  • data_format (Union[str, ~image_utils.ChannelDimension]、kwargs、任意) — サポートされているのは 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: (高さ, 幅, チャネル数) 形式の画像。
    • "none" または ChannelDimension.NONE: (height, width) 形式の画像。
  • device (Annotated[Union[str, torch.device, NoneType], None], kwargs) — 動画を処理するデバイスです。未設定の場合、入力動画からデバイスが推論されます。
  • return_tensors (Annotated[str | ~utils.generic.TensorType | None, None], kwargs) — 'pt' に設定されている場合はスタックされたテンソルを返し、それ以外の場合はテンソルのリストを返します。
  • disable_grouping (bool、kwargs、任意) — サイズごとに画像をグループ化してバッチ処理するのではなく、個別に処理するためにグループ化を無効にするかどうか。None の場合、画像が CPU にある場合は True、それ以外の場合は False に設定されます。この選択は、https://github.com/huggingface/transformers/pull/38157 に詳しく記載されている経験則に基づいています。
  • image_seq_length (int、kwargs、任意) — 入力内の各画像に使用される画像トークンの数です。 後方互換性のために追加されましたが、将来のモデルではプロセッサの属性として設定されるべきです。
  • do_split_image (bool、kwargs、任意、デフォルトは self.do_split_image) — セマンティックセグメンテーションのために、入力画像を重複するパッチに分割するかどうかを指定します。True に設定すると、入力画像は size["shortest_edge"] のサイズのパッチに分割され、パッチ間にオーバーラップが設けられます。それ以外の場合、入力画像はターゲットサイズにパディングされます。
  • ignore_index (int、kwargs、任意、デフォルトは self.ignore_index) — セグメンテーションマップの背景ピクセルに割り当てられるラベルです。指定された場合、セグメンテーションマップ内で 0(背景)と示されたピクセルは ignore_index に置き換えられます。

EomtImageProcessor 画像プロセッサを構築します。

preprocess

< >

( images: typing.Union[ForwardRef('PIL.Image.Image'), numpy.ndarray, ForwardRef('torch.Tensor'), list['PIL.Image.Image'], list[numpy.ndarray], list['torch.Tensor']]segmentation_maps: list[torch.Tensor] | None = Noneinstance_id_to_semantic_id: dict[int, int] | None = None**kwargs: *<class 'transformers.models.eomt.image_processing_eomt.EomtImageProcessorKwargs'> ) → ~image_processing_base.BatchFeature

パラメータ

  • images (Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]) — 前処理対象の画像です。ピクセル値が 0 から 255 の範囲にある単一の画像またはバッチを想定しています。ピクセル値が 0 から 1 の範囲にある画像を渡す場合は、do_rescale=False を設定してください。
  • segmentation_maps (ImageInput、任意) — 対応する画像の前処理に使用するセグメンテーションマップです。
  • instance_id_to_semantic_id (list[dict[int, int]] または dict[int, int]、省略可) — オブジェクトのインスタンス ID とクラス ID の間のマッピングです。
  • do_convert_rgb (bool、kwargs、任意) — 画像を RGB に変換するかどうかを指定します。
  • do_resize (bool、kwargs、optional) — 画像をリサイズするかどうか。
  • size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — モデルへの最大入力次元を記述します。
  • default_to_square (bool、kwargs、任意) — サイズが整数の場合、リサイズ時に正方形の画像をデフォルトとするかどうか。
  • crop_size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — center_crop を適用した後の出力画像のサイズ。
  • resample (Annotated[Union[int, PILImageResampling, NoneType], None], kwargs) — 画像のリサイズ時に使用するリサンプリングフィルタ。PILImageResampling の列挙型のいずれかを使用できます。do_resize が True に設定されている場合のみ有効です。
  • do_rescale (bool、kwargs、optional) — 画像をリスケールするかどうかを指定します。
  • rescale_factor (float、kwargs、任意) — do_rescale が True に設定されている場合、画像をリスケールするための係数。
  • do_normalize (bool, kwargs, optional) — 画像を正規化するかどうかを指定します。
  • image_mean (Union[float, list[float], tuple[float, ...]]、kwargs、optional) — 正規化に使用する画像の平均値。do_normalize が True に設定されている場合のみ有効です。
  • image_std (Union[float, list[float], tuple[float, ...]], kwargs, optional) — 正規化に使用する画像の標準偏差。do_normalize が True に設定されている場合のみ有効です。
  • do_pad (bool, kwargs, optional) — 画像をパディングするかどうかを指定します。パディングは、バッチ内の最大サイズに合わせるか、画像ごとに固定の正方形サイズに合わせるかのいずれかで行われます。具体的なパディング戦略はモデルによって異なります。
  • pad_size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — 画像をパディングする {"height": int, "width" int} のサイズです。前処理に提供されるすべての画像サイズより大きくなければなりません。pad_size が指定されない場合、バッチ内の最大の幅と高さにパディングされます。do_pad=True. の場合のみ適用されます。
  • do_center_crop (bool, kwargs, optional) — 画像を中央クロップするかどうかを指定します。
  • data_format (Union[str, ~image_utils.ChannelDimension]、kwargs、任意) — サポートされているのは 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: (高さ, 幅, チャネル数) 形式の画像。
    • "none" または ChannelDimension.NONE: (height, width) 形式の画像。
  • device (Annotated[Union[str, torch.device, NoneType], None], kwargs) — 動画を処理するデバイスです。未設定の場合、入力動画からデバイスが推論されます。
  • return_tensors (Annotated[str | ~utils.generic.TensorType | None, None], kwargs) — 'pt' に設定されている場合はスタックされたテンソルを返し、それ以外の場合はテンソルのリストを返します。
  • disable_grouping (bool、kwargs、任意) — サイズごとに画像をグループ化してバッチ処理するのではなく、個別に処理するためにグループ化を無効にするかどうか。None の場合、画像が CPU にある場合は True、それ以外の場合は False に設定されます。この選択は、https://github.com/huggingface/transformers/pull/38157 に詳しく記載されている経験則に基づいています。
  • image_seq_length (int、kwargs、任意) — 入力内の各画像に使用される画像トークンの数です。 後方互換性のために追加されましたが、将来のモデルではプロセッサの属性として設定されるべきです。
  • do_split_image (bool、kwargs、任意、デフォルトは self.do_split_image) — セマンティックセグメンテーションのために、入力画像を重複するパッチに分割するかどうかを指定します。True に設定すると、入力画像はパッチ間の重複を伴い、size["shortest_edge"] のサイズのパッチに分割されます。それ以外の場合は、入力画像はターゲットサイズにパディングされます。
  • ignore_index (int、kwargs、任意、デフォルトは self.ignore_index) — セグメンテーションマップの背景ピクセルに割り当てられるラベルです。指定された場合、セグメンテーションマップ内で 0(背景)と示されたピクセルは ignore_index に置き換えられます。

戻り値

~image_processing_base.BatchFeature

  • data (dict) — call メソッド(‘pixel_values’ など)によって返される、リスト/配列/テンソルの辞書。
  • tensor_type (Union[None, str, TensorType]、省略可) — 初期化時に PyTorch/Numpy の Tensor 内の整数リストを変換するために、ここで tensor_type を指定できます。

post_process_semantic_segmentation

< >

( outputstarget_sizes: listsize: dict[str, int] | None = Nonereturn_segmentation_scores: bool = False ) → list[torch.Tensor] or list[SemanticSegmentationPostProcessorOutput]

パラメータ

  • outputs (EomtForUniversalSegmentation) — モデルの生出力。
  • target_sizes (list[tuple[int, int]]) — バッチ内の各画像のターゲットサイズ(高さ、幅)を含むタプルのリスト(tuple[int, int])。
  • size (dict[str, int]、任意) — 中間マスクを補間するサイズ。デフォルトは self.size です。
  • 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) はターゲットサイズに対応します。

EomtForUniversalSegmentationの出力をセマンティックセグメンテーションマップに変換します。

post_process_instance_segmentation

< >

( outputstarget_sizes: listthreshold: float = 0.8size: dict[str, int] | None = None )

モデルの出力を後処理して、Instance Segmentation Predictionsに変換します。

post_process_panoptic_segmentation

< >

( outputstarget_sizes: listthreshold: float = 0.8mask_threshold: float = 0.5overlap_mask_area_threshold: float = 0.8stuff_classes: list[int] | None = Nonesize: dict[str, int] | None = None )

モデルの出力を後処理し、最終的なパノプティックセグメンテーション予測を生成します。

EomtImageProcessorPil

class transformers.EomtImageProcessorPil

< >

( **kwargs: *<class 'transformers.models.eomt.image_processing_pil_eomt.EomtImageProcessorKwargs'> )

パラメータ

  • do_convert_rgb (bool、kwargs、任意) — 画像を RGB に変換するかどうかを指定します。
  • do_resize (bool、kwargs、任意、デフォルトはTrue) — 画像をリサイズするかどうか。
  • size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs, デフォルトは {'shortest_edge' -- 640, 'longest_edge': 640}): モデルへの最大入力サイズを指定します。
  • default_to_square (bool、kwargs、任意、デフォルトは False) — size が整数の場合、リサイズ時に正方形の画像をデフォルトとするかどうか。
  • crop_size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — center_crop を適用した後の出力画像のサイズ。
  • resample (Annotated[Union[int, PILImageResampling, NoneType], None], kwargs, デフォルトは 2) — 画像のリサイズ時に使用するリサンプリングフィルタです。PILImageResampling の列挙型のいずれかを使用できます。do_resize が True に設定されている場合のみ、効果が現れます。
  • do_rescale (bool、kwargs、任意、デフォルトはTrue) — 画像をリスケールするかどうかを指定します。
  • rescale_factor (float、kwargs、任意、デフォルト値は 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_pad (bool、kwargs、optional、デフォルトは False) — 画像をパディングするかどうかを指定します。パディングは、バッチ内の最大サイズに合わせるか、画像ごとに固定の正方形サイズに合わせるかのいずれかで行われます。具体的なパディング戦略はモデルによって異なります。
  • pad_size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — 画像をパディングする {"height": int, "width" int} のサイズです。前処理に提供されるすべての画像サイズより大きくなければなりません。pad_size が指定されない場合、バッチ内の最大の幅と高さにパディングされます。do_pad=True. の場合のみ適用されます。
  • do_center_crop (bool, kwargs, optional) — 画像を中央クロップするかどうかを指定します。
  • data_format (Union[str, ~image_utils.ChannelDimension]、kwargs、任意) — サポートされているのは 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: (高さ, 幅, チャネル数) 形式の画像。
    • "none" または ChannelDimension.NONE: (height, width) 形式の画像。
  • device (Annotated[Union[str, torch.device, NoneType], None], kwargs) — 動画を処理するデバイスです。未設定の場合、入力動画からデバイスが推論されます。
  • return_tensors (Annotated[str | ~utils.generic.TensorType | None, None], kwargs) — 'pt' に設定されている場合はスタックされたテンソルを返し、それ以外の場合はテンソルのリストを返します。
  • disable_grouping (bool、kwargs、任意) — サイズごとに画像をグループ化してバッチ処理するのではなく、個別に処理するためにグループ化を無効にするかどうか。None の場合、画像が CPU にある場合は True、それ以外の場合は False に設定されます。この選択は、https://github.com/huggingface/transformers/pull/38157 に詳しく記載されている経験則に基づいています。
  • image_seq_length (int、kwargs、任意) — 入力内の各画像に使用される画像トークンの数です。 後方互換性のために追加されましたが、将来のモデルではプロセッサの属性として設定されるべきです。
  • do_split_image (bool、kwargs、任意、デフォルトは self.do_split_image) — セマンティックセグメンテーションのために、入力画像を重複するパッチに分割するかどうかを指定します。True に設定すると、入力画像はパッチ間の重複を伴い、size["shortest_edge"] のサイズのパッチに分割されます。それ以外の場合は、入力画像はターゲットサイズにパディングされます。
  • ignore_index (int、kwargs、任意、デフォルトは self.ignore_index) — セグメンテーションマップの背景ピクセルに割り当てられるラベルです。指定された場合、セグメンテーションマップ内で 0(背景)と示されたピクセルは ignore_index に置き換えられます。

EomtImageProcessor 画像プロセッサを構築します。

preprocess

< >

( images: typing.Union[ForwardRef('PIL.Image.Image'), numpy.ndarray, ForwardRef('torch.Tensor'), list['PIL.Image.Image'], list[numpy.ndarray], list['torch.Tensor']]segmentation_maps: list[torch.Tensor] | None = Noneinstance_id_to_semantic_id: dict[int, int] | None = None**kwargs: *<class 'transformers.models.eomt.image_processing_pil_eomt.EomtImageProcessorKwargs'> ) → ~image_processing_base.BatchFeature

パラメータ

  • images (Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]) — 前処理対象の画像です。ピクセル値が 0 から 255 の範囲にある単一の画像またはバッチを想定しています。ピクセル値が 0 から 1 の範囲にある画像を渡す場合は、do_rescale=False を設定してください。
  • segmentation_maps (ImageInput、任意) — 対応する画像の前処理に使用するセグメンテーションマップです。
  • instance_id_to_semantic_id (list[dict[int, int]] または dict[int, int]、省略可) — オブジェクトのインスタンス ID とクラス ID の間のマッピングです。
  • do_convert_rgb (bool、kwargs、任意) — 画像を RGB に変換するかどうかを指定します。
  • do_resize (bool、kwargs、optional) — 画像をリサイズするかどうか。
  • size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — モデルへの最大入力次元を記述します。
  • default_to_square (bool、kwargs、任意) — サイズが整数の場合、リサイズ時に正方形の画像をデフォルトとするかどうか。
  • crop_size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — center_crop を適用した後の出力画像のサイズ。
  • resample (Annotated[Union[int, PILImageResampling, NoneType], None], kwargs) — 画像のリサイズ時に使用するリサンプリングフィルタ。PILImageResampling の列挙型のいずれかを使用できます。do_resize が True に設定されている場合のみ有効です。
  • do_rescale (bool、kwargs、optional) — 画像をリスケールするかどうかを指定します。
  • rescale_factor (float、kwargs、任意) — do_rescale が True に設定されている場合、画像をリスケールするための係数。
  • do_normalize (bool, kwargs, optional) — 画像を正規化するかどうかを指定します。
  • image_mean (Union[float, list[float], tuple[float, ...]]、kwargs、optional) — 正規化に使用する画像の平均値。do_normalize が True に設定されている場合のみ有効です。
  • image_std (Union[float, list[float], tuple[float, ...]], kwargs, optional) — 正規化に使用する画像の標準偏差。do_normalize が True に設定されている場合のみ有効です。
  • do_pad (bool, kwargs, optional) — 画像をパディングするかどうかを指定します。パディングは、バッチ内の最大サイズに合わせるか、画像ごとに固定の正方形サイズに合わせるかのいずれかで行われます。具体的なパディング戦略はモデルによって異なります。
  • pad_size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — 画像をパディングする {"height": int, "width" int} のサイズです。前処理に提供されるすべての画像サイズより大きくなければなりません。pad_size が指定されない場合、バッチ内の最大の幅と高さにパディングされます。do_pad=True. の場合のみ適用されます。
  • do_center_crop (bool, kwargs, optional) — 画像を中央クロップするかどうかを指定します。
  • data_format (Union[str, ~image_utils.ChannelDimension]、kwargs、任意) — サポートされているのは 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: (高さ, 幅, チャネル数) 形式の画像。
    • "none" または ChannelDimension.NONE: (height, width) 形式の画像。
  • device (Annotated[Union[str, torch.device, NoneType], None], kwargs) — 動画を処理するデバイスです。未設定の場合、入力動画からデバイスが推論されます。
  • return_tensors (Annotated[str | ~utils.generic.TensorType | None, None], kwargs) — 'pt' に設定されている場合はスタックされたテンソルを返し、それ以外の場合はテンソルのリストを返します。
  • disable_grouping (bool、kwargs、任意) — サイズごとに画像をグループ化してバッチ処理するのではなく、個別に処理するためにグループ化を無効にするかどうか。None の場合、画像が CPU にある場合は True、それ以外の場合は False に設定されます。この選択は、https://github.com/huggingface/transformers/pull/38157 に詳しく記載されている経験則に基づいています。
  • image_seq_length (int、kwargs、任意) — 入力内の各画像に使用される画像トークンの数です。 後方互換性のために追加されましたが、将来のモデルではプロセッサの属性として設定されるべきです。
  • do_split_image (bool、kwargs、任意、デフォルトは self.do_split_image) — セマンティックセグメンテーションのために、入力画像を重複するパッチに分割するかどうかを指定します。True に設定すると、入力画像はパッチ間の重複を伴い、size["shortest_edge"] のサイズのパッチに分割されます。それ以外の場合は、入力画像はターゲットサイズにパディングされます。
  • ignore_index (int、kwargs、任意、デフォルトは self.ignore_index) — セグメンテーションマップの背景ピクセルに割り当てられるラベルです。指定された場合、セグメンテーションマップ内で 0(背景)と示されたピクセルは ignore_index に置き換えられます。

戻り値

~image_processing_base.BatchFeature

  • data (dict) — call メソッド(‘pixel_values’ など)によって返される、リスト/配列/テンソルの辞書。
  • tensor_type (Union[None, str, TensorType]、省略可) — 初期化時に PyTorch/Numpy の Tensor 内の整数リストを変換するために、ここで tensor_type を指定できます。

post_process_semantic_segmentation

< >

( outputstarget_sizes: listsize: dict[str, int] | None = Nonereturn_segmentation_scores: bool = False ) → list[torch.Tensor] or list[SemanticSegmentationPostProcessorOutput]

パラメータ

  • outputs (EomtForUniversalSegmentation) — モデルの生出力。
  • target_sizes (list[tuple[int, int]]) — バッチ内の各画像のターゲットサイズ(高さ、幅)を含むタプルのリスト(tuple[int, int])。
  • size (dict[str, int]、任意) — 中間マスクを補間するサイズ。デフォルトは self.size です。
  • 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) はターゲットサイズに対応します。

EomtForUniversalSegmentation の出力をセマンティックセグメンテーションマップに変換します。

post_process_instance_segmentation

< >

( outputstarget_sizes: listthreshold: float = 0.8size: dict[str, int] | None = None )

モデルの出力を後処理して、Instance Segmentation Predictionsに変換します。

post_process_panoptic_segmentation

< >

( outputstarget_sizes: listthreshold: float = 0.8mask_threshold: float = 0.5overlap_mask_area_threshold: float = 0.8stuff_classes: list[int] | None = Nonesize: dict[str, int] | None = None )

モデルの出力を後処理し、最終的なパノプティックセグメンテーション予測を生成します。

EomtConfig

class transformers.EomtConfig

< >

( transformers_version: str | None = Nonearchitectures: list[str] | None = Noneoutput_hidden_states: bool | None = Falsereturn_dict: bool | None = Truedtype: str | torch.dtype | None = Nonechunk_size_feed_forward: int = 0is_encoder_decoder: bool = Falseid2label: dict[int, str] | dict[str, str] | None = Nonelabel2id: dict[str, int] | dict[str, str] | None = Noneproblem_type: Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = Nonehidden_size: int = 1024num_hidden_layers: int = 24num_attention_heads: int = 16hidden_act: str = 'gelu'hidden_dropout_prob: float | int = 0.0initializer_range: float = 0.02layer_norm_eps: float = 1e-06image_size: int | list[int] | tuple[int, int] = 640patch_size: int | list[int] | tuple[int, int] = 16num_channels: int = 3mlp_ratio: int = 4layerscale_value: float = 1.0drop_path_rate: float | int = 0.0num_upscale_blocks: int = 2attention_dropout: float | int = 0.0use_swiglu_ffn: bool = Falsenum_blocks: int = 4no_object_weight: float = 0.1class_weight: float = 2.0mask_weight: float = 5.0dice_weight: float = 5.0train_num_points: int = 12544oversample_ratio: float = 3.0importance_sample_ratio: float = 0.75num_queries: int = 200num_register_tokens: int = 4 )

パラメータ

  • hidden_size (int、任意、デフォルトは 1024) — 隠れ表現の次元数。
  • num_hidden_layers (int、任意、デフォルトは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) — レイヤーノーマル層で使用する 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、任意、デフォルト値は 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、任意、デフォルト値は 12544)— 学習中にマスク損失の計算のためにサンプリングする点の数。
  • oversample_ratio (float、任意、デフォルトは 3.0) — マスク学習におけるポイントサンプリングで使用するオーバーサンプリング比率。
  • importance_sample_ratio (float、任意、デフォルト値: 0.75) — 学習中に重要度に基づいてサンプリングするポイントの比率。
  • num_queries (int、任意、デフォルトは 200) — Transformer におけるオブジェクトクエリの数。
  • num_register_tokens (int、省略可、デフォルト値は 4) — Transformer の入力に追加される、学習可能な register token の数です。

これは EomtModel の設定を保存するための設定クラスです。指定された引数に基づいて Eomt モデルをインスタンス化し、モデルのアーキテクチャを定義するために使用されます。デフォルト値で設定をインスタンス化すると、tue-mps/coco_panoptic_eomt_large_640 と同様の設定が得られます。

設定オブジェクトはPreTrainedConfigを継承し、モデルの出力を制御するために使用できます。詳細については、PreTrainedConfigのドキュメントを参照してください。

例:

>>> from transformers import EomtConfig, EomtForUniversalSegmentation

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

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

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

EomtForUniversalSegmentation

class transformers.EomtForUniversalSegmentation

< >

( config: EomtConfig )

パラメータ

  • config (EomtConfig) — モデルのすべてのパラメータを含むモデル設定クラスです。設定ファイルで初期化しても、モデルに関連付けられた重みは読み込まれず、設定のみが読み込まれます。モデルの重みをロードするには、from_pretrained() メソッドを参照してください。

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

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

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

forward

< >

( pixel_values: Tensormask_labels: list[torch.Tensor] | None = Noneclass_labels: list[torch.Tensor] | None = Nonepatch_offsets: list[torch.Tensor] | None = None**kwargs: *<class 'transformers.utils.generic.TransformersKwargs'> ) → EomtForUniversalSegmentationOutput or tuple(torch.FloatTensor)

パラメータ

  • pixel_values (torch.Tensor、形状 (batch_size, num_channels, image_size, image_size)) — 入力画像に対応するテンソルです。ピクセル値は EomtImageProcessor を使用して取得できます。詳細については EomtImageProcessor.call() を参照してください(processor_class は画像の処理に EomtImageProcessor を使用します)。
  • mask_labels (list[torch.Tensor]、任意) — (num_labels, height, width) の形状を持つマスクラベルのリストで、モデルに渡すものです
  • class_labels (list[torch.LongTensor]、任意) — モデルに渡す、(num_labels, height, width) の形状を持つターゲットクラスラベルのリストです。mask_labels のラベルを識別します。例えば、class_labels[i][j] が真の場合、mask_labels[i][j] のラベルを示します。
  • patch_offsets (list[torch.Tensor], 任意) — セマンティックセグメンテーションにおけるパッチの画像インデックスおよび開始・終了位置を示すタプルのリスト。

戻り値

EomtForUniversalSegmentationOutput または tuple(torch.FloatTensor)

EomtForUniversalSegmentationOutput、またはtorch.FloatTensorのタプル(return_dict=Falseが渡された場合、またはconfig.return_dict=Falseの場合)。設定(EomtConfig)や入力に応じて、さまざまな要素で構成されます。

EomtForUniversalSegmentationのforwardメソッドは、__call__特殊メソッドをオーバーライドします。

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

  • loss (torch.Tensor, optional) — ラベルが存在する場合に返される、計算された損失。
  • class_queries_logits (torch.FloatTensor, optional) — 各クエリに対して提案されるクラスを表す、形状が(batch_size, num_queries, num_labels + 1)のテンソル。nullクラスを組み込む必要があるため、+ 1が必要です。
  • masks_queries_logits (torch.FloatTensor, オプション) — 各クエリに対する提案マスクを表す、形状が(batch_size, num_queries, height, width)のテンソル。
  • last_hidden_state (torch.FloatTensor、shape (batch_size, num_channels, height, width)) — 最終層の最後の隠れ状態(最終的な特徴マップ)。
  • hidden_states (tuple(torch.FloatTensor)、optional、output_hidden_states=True が渡された場合または config.output_hidden_states=True の場合に返されます)— torch.FloatTensor のタプル(埋め込みの出力用 1 つ + 各ステージの出力用 1 つ)、shape は (batch_size, sequence_length, hidden_size)。モデルの全レイヤーの隠れ状態です。
  • attentions (tuple(tuple(torch.FloatTensor))、optional、output_attentions=True が渡された場合または config.output_attentions=True の場合に返されます) — tuple(torch.FloatTensor) のタプル(レイヤーごとに1つ)、形状は (batch_size, num_heads, sequence_length, sequence_length)。Transformer デコーダーからの Self Attention と Cross Attention の重み。
  • patch_offsets (list[torch.Tensor]、任意) — セマンティックセグメンテーションにおけるパッチの画像インデックスおよび開始・終了位置を示すタプルのリスト。
Update on GitHub