Transformers documentation

SAM3-LiteText

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

このモデルは2026年2月12日にHF papersで公開され、2026年4月13日にHugging Face Transformersに貢献されました。

SAM3-LiteText

概要

SAM3-LiteTextは、Chengxi Zeng、Yuxuan Jiang、Ge Gao、Shuai Wang、Duolikun Danier、Bin Zhu、Stevan Rudinac、David Bull、Fan Zhang によって提案された SAM3-LiteText: An Anatomical Study of the SAM3 Text Encoder for Efficient Vision-Language Segmentation に記載されています。

SAM3-LiteText は、SAM3 の軽量版です。重たい SAM3 のテキストエンコーダー(353M パラメータ)を、知識蒸留によって最適化されたコンパクトな MobileCLIP ベースのテキストエンコーダーに置き換えています。SAM3 の ViT-H 画像エンコーダーはそのまま維持されています。これにより、セグメンテーション性能を元のモデルと同等に保ちながら、テキストエンコーダーのパラメータ数を最大 88% 削減できます。

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

SAM3のようなビジュアル・言語セグメンテーションモデルは、柔軟でプロンプト駆動型の視覚グラウンディングを可能にしますが、オープンエンドな言語理解のために設計された大規模な汎用テキストエンコーダを継承しています。実際には、セグメンテーションのプロンプトは短く、構造化されており、意味的に制約されているため、テキストエンコーダの容量に過剰な割当てが生じ、計算リソースとメモリに持続的なオーバーヘッドが発生します。本論文では、ビジュアル・言語セグメンテーションにおけるテキストプロンプティングの大規模な解剖学的分析を行い、複数のベンチマークにまたがる404,796件の実プロンプトを対象としました。分析の結果、深刻な冗長性が明らかになりました。ほとんどのコンテキストウィンドウは未活用であり、語彙の使用は極めてスパースで、高次元表現にもかかわらず、テキスト埋め込みは低次元の多様体上に位置しています。これらの知見に基づき、我々はSAM3-LiteTextを提案します。これは軽量なテキストエンコーディングフレームワークであり、元のSAM3のテキストエンコーダを、知識蒸留によって最適化されたコンパクトなMobileCLIPの学生モデルに置き換えます。画像および動画セグメンテーションのベンチマークにおける広範な実験により、SAM3-LiteTextはテキストエンコーダのパラメータを最大88%削減し、静的メモリフットプリントを大幅に削減しながら、元のモデルと同等のセグメンテーション性能を維持することが示されました。

テキストエンコーダーのアーキテクチャはMobileCLIPをベースとしており、3つのバリアントが用意されています。

バリアントテキストエンコーダーテキストのパラメータ集約
SAM3-LiteText-S0-16MobileCLIP-S042.54M~88%
SAM3-LiteText-S1-16MobileCLIP-S163.53M~82%
SAM3-LiteText-L-16MobileCLIP2-L123.80M~65%

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

使用方法

SAM3-LiteTextは、軽量なテキストエンコーダーを搭載したSAM3のドロップイン代替です。同じプロセッサ(Sam3Processor)を使用し、同じプロンプトインターフェースをサポートしています。テキストプロンプト、ボックスプロンプト、バッチ推論など、詳細な使用例については、SAM3のドキュメントを参照してください。

from io import BytesIO

from huggingface_hub.utils import httpx
from PIL import Image

from transformers import AutoModel, AutoProcessor


model = AutoModel.from_pretrained("yonigozlan/sam3-litetext-s0", device_map="auto")
processor = AutoProcessor.from_pretrained("yonigozlan/sam3-litetext-s0")

image_url = "http://images.cocodataset.org/val2017/000000077595.jpg"
image = Image.open(BytesIO(httpx.get(image_url).content)).convert("RGB")

inputs = processor(images=image, text="ear", return_tensors="pt").to(model.device)

outputs = model(**inputs)

results = processor.post_process_instance_segmentation(
    outputs,
    threshold=0.5,
    mask_threshold=0.5,
    target_sizes=inputs.get("original_sizes").tolist(),
)[0]

print(f"Found {len(results['masks'])} objects")

Sam3LiteTextConfig

class transformers.Sam3LiteTextConfig

< >

( 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 = Nonevision_config: dict | transformers.configuration_utils.PreTrainedConfig | None = Nonetext_config: dict | transformers.configuration_utils.PreTrainedConfig | None = Nonegeometry_encoder_config: dict | transformers.configuration_utils.PreTrainedConfig | None = Nonedetr_encoder_config: dict | transformers.configuration_utils.PreTrainedConfig | None = Nonedetr_decoder_config: dict | transformers.configuration_utils.PreTrainedConfig | None = Nonemask_decoder_config: dict | transformers.configuration_utils.PreTrainedConfig | None = Noneinitializer_range: float = 0.02 )

パラメータ

  • vision_config (Union[dict, ~configuration_utils.PreTrainedConfig]、任意) — ビジョンバックボーンの config オブジェクトまたは辞書です。
  • text_config (Union[dict, ~configuration_utils.PreTrainedConfig]、省略可) — テキストバックボーンの設定オブジェクトまたは辞書。
  • geometry_encoder_config (dict または Sam3LiteTextGeometryEncoderConfig、省略可) — ジオメトリエンコーダーの設定です。
  • detr_encoder_config (dict または Sam3LiteTextDETREncoderConfig、任意) — DETR エンコーダーの設定です。
  • detr_decoder_config (dictまたはSam3LiteTextDETRDecoderConfig、省略可) — DETRデコーダーの設定です。
  • mask_decoder_config (dict または Sam3LiteTextMaskDecoderConfig、省略可) — マスクデコーダーの設定です。
  • initializer_range (float、任意、デフォルトは 0.02) — すべての重み行列を初期化するための truncated_normal_initializer の標準偏差です。

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

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

例:

>>> from transformers import Sam3LiteTextConfig, Sam3LiteTextModel

>>> # Initializing a SAM3_LITE_TEXT configuration
>>> configuration = Sam3LiteTextConfig()

>>> # Initializing a model from the configuration
>>> model = Sam3LiteTextModel(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config

Sam3LiteTextTextConfig

class transformers.Sam3LiteTextTextConfig

< >

( 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 = Nonevocab_size: int = 49408hidden_size: int = 512intermediate_size: int = 2048projection_dim: int = 512num_hidden_layers: int = 12num_attention_heads: int = 8max_position_embeddings: int = 77hidden_act: str = 'gelu'layer_norm_eps: float = 1e-05attention_dropout: float = 0.0use_repmixer_blocks: bool = Truelayer_scale_init_value: float = 1e-05repmixer_kernel_size: int = 11 )

パラメータ

  • vocab_size (int、任意、デフォルトは 49408) — モデルの語彙サイズ。input_ids で表現できるトークンの種類数を定義します。
  • hidden_size (int、任意、デフォルトは 512) — 隠れ表現の次元数。
  • intermediate_size (int、任意、デフォルトは2048) — MLP 表現の次元数。
  • projection_dim (int、任意、デフォルトは 512) — テキストおよびビジョンの投影層の次元数。
  • num_hidden_layers (int、任意、デフォルトは 12) — Transformer デコーダーの隠れ層の数。
  • num_attention_heads (int、任意、デフォルトは 8) — Transformer デコーダーの各アテンション層におけるアテンションヘッドの数。
  • max_position_embeddings (int、任意、デフォルトは 77) — このモデルが使用される可能性のある最大シーケンス長です。
  • hidden_act (str、任意、デフォルトは gelu) — デコーダーで使用する非線形活性化関数(関数または文字列)。例えば、"gelu"、 "relu"、"silu" など。
  • layer_norm_eps (float、任意、デフォルトは 1e-05) — レイヤーノーマル層で使用する epsilon です。
  • attention_dropout (float、任意、デフォルトは 0.0) — アテンション確率のドロップアウト率です。
  • use_repmixer_blocks (bool、任意、デフォルトはTrue) — エンコーダーの最初の層と最後の層に RepMixer ブロック(MobileCLIP スタイル)を使用するかどうか。False の場合、すべての層は標準的な Transformer エンコーダー層になります。
  • layer_scale_init_value (float、任意、デフォルトは 1e-5) — RepMixer ブロック(残差ブランチ)内の学習可能な layer-scale パラメータの初期値です。
  • repmixer_kernel_size (int, 任意、デフォルトは 11) — RepMixer ブロック内の depthwise convolution におけるカーネルサイズ(token mixer と convolutional feed-forward パス)。

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

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

Sam3LiteTextGeometryEncoderConfig

クラス transformers.Sam3LiteTextGeometryEncoderConfig

< >

( 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 = 256num_layers: int = 3num_attention_heads: int = 8intermediate_size: int = 2048dropout: float | int = 0.1hidden_act: str = 'relu'hidden_dropout: float | int = 0.0layer_norm_eps: float = 1e-06roi_size: int = 7initializer_range: float = 0.02 )

パラメータ

  • hidden_size (int、任意、デフォルトは 256) — 隠れ表現の次元数。
  • num_layers (int、任意、デフォルトは 3) — Transformer デコーダーの隠れ層の数。
  • num_attention_heads (int、任意、デフォルトは 8) — Transformer デコーダーの各アテンション層におけるアテンションヘッドの数。
  • intermediate_size (int、任意、デフォルトは2048) — MLP 表現の次元数。
  • dropout (Union[float, int]、任意、デフォルト値は0.1) — すべての dropout レイヤーの比率です。
  • hidden_act (str、任意、デフォルトは relu) — デコーダーで使用する非線形活性化関数(関数または文字列)。例えば、"gelu"、 "relu"、"silu" など。
  • hidden_dropout (Union[float, int]、任意、デフォルト値は 0.0) — embeddings、encoder、pooler 内のすべての全結合層における dropout 確率です。
  • layer_norm_eps (float、任意、デフォルトは 1e-06) — レイヤーノーマル層で使用する epsilon です。
  • roi_size (int、任意、デフォルトは 7) — ボックスプーリング操作の ROI サイズ。
  • initializer_range (float、任意、デフォルトは 0.02) — すべての重み行列を初期化するための truncated_normal_initializer の標準偏差です。

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

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

Sam3LiteTextDETREncoderConfig

class transformers.Sam3LiteTextDETREncoderConfig

< >

( 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 = 256num_layers: int = 6num_attention_heads: int = 8intermediate_size: int = 2048dropout: float | int = 0.1hidden_act: str = 'relu'hidden_dropout: float | int = 0.0layer_norm_eps: float = 1e-06initializer_range: float = 0.02 )

パラメータ

  • hidden_size (int、任意、デフォルトは 256) — 隠れ表現の次元数。
  • num_layers (int、任意、デフォルトは6) — Transformerデコーダーの隠れ層の数。
  • num_attention_heads (int、任意、デフォルトは 8) — Transformer デコーダーの各アテンション層におけるアテンションヘッドの数。
  • intermediate_size (int、任意、デフォルトは2048) — MLP 表現の次元数。
  • dropout (Union[float, int]、任意、デフォルト値は0.1) — すべての dropout レイヤーの比率です。
  • hidden_act (str、任意、デフォルトは relu) — デコーダーで使用する非線形活性化関数(関数または文字列)。例えば、"gelu"、 "relu"、"silu" など。
  • hidden_dropout (float、任意、デフォルト値は 0.0)— 隠れ状態の Dropout 確率です。
  • layer_norm_eps (float、任意、デフォルトは 1e-06) — レイヤーノーマル層で使用する epsilon です。
  • initializer_range (float、任意、デフォルトは 0.02) — すべての重み行列を初期化するための truncated_normal_initializer の標準偏差です。

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

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

Sam3LiteTextDETRDecoderConfig

クラス transformers.Sam3LiteTextDETRDecoderConfig

< >

( 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 = 256num_layers: int = 6num_queries: int = 200num_attention_heads: int = 8intermediate_size: int = 2048dropout: float | int = 0.1hidden_act: str = 'relu'hidden_dropout: float | int = 0.0layer_norm_eps: float = 1e-06initializer_range: float = 0.02 )

パラメータ

  • hidden_size (int、任意、デフォルトは 256) — 隠れ表現の次元数。
  • num_layers (int、任意、デフォルトは6) — Transformerデコーダーの隠れ層の数。
  • num_queries (int、任意、デフォルトは 200) — オブジェクトクエリの数。
  • num_attention_heads (int、任意、デフォルトは 8) — Transformer デコーダーの各アテンション層におけるアテンションヘッドの数。
  • intermediate_size (int、任意、デフォルトは2048) — MLP 表現の次元数。
  • dropout (Union[float, int]、任意、デフォルト値は0.1) — すべての dropout レイヤーの比率です。
  • hidden_act (str、任意、デフォルトは relu) — デコーダーで使用する非線形活性化関数(関数または文字列)。例えば、"gelu"、 "relu"、"silu" など。
  • hidden_dropout (Union[float, int]、任意、デフォルト値は 0.0) — embeddings、encoder、pooler 内のすべての全結合層における dropout 確率です。
  • layer_norm_eps (float、任意、デフォルトは 1e-06) — レイヤーノーマル層で使用する epsilon です。
  • initializer_range (float、任意、デフォルトは 0.02) — すべての重み行列を初期化するための truncated_normal_initializer の標準偏差です。

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

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

Sam3LiteTextMaskDecoderConfig

class transformers.Sam3LiteTextMaskDecoderConfig

< >

( 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 = 256num_upsampling_stages: int = 3layer_norm_eps: float = 1e-06dropout: float | int = 0.0num_attention_heads: int = 8initializer_range: float = 0.02 )

パラメータ

  • hidden_size (int、任意、デフォルトは 256) — 隠れ表現の次元数。
  • num_upsampling_stages (int、任意、デフォルトは 3)— ピクセルデコーダー(FPN)におけるアップサンプリングのステージ数。
  • layer_norm_eps (float、任意、デフォルトは 1e-06) — レイヤーノーマル層で使用する epsilon です。
  • dropout (Union[float, int]、省略可、デフォルト値は0.0) — すべての dropout レイヤーの比率です。
  • num_attention_heads (int、任意、デフォルトは 8) — Transformer デコーダーの各アテンション層におけるアテンションヘッドの数。
  • initializer_range (float、任意、デフォルトは 0.02) — すべての重み行列を初期化するための truncated_normal_initializer の標準偏差です。

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

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

Sam3LiteTextTextModel

class transformers.Sam3LiteTextTextModel

< >

( config: Sam3LiteTextTextConfig )

パラメータ

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

EfficientSAM3 LiteTextで使用されるMobileCLIP MCTテキストエンコーダー。

config.use_repmixer_blocks が True の場合、最初の層と最後の層は Sam3LiteTextRepMixerBlock モジュールであり、それ以外は標準的な Sam3LiteTextTextEncoderLayer 層です。

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

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

forward

< >

( input_ids: typing.Optional[torch.LongTensor] = Noneattention_mask: typing.Optional[torch.Tensor] = None**kwargs: *<class 'transformers.utils.generic.TransformersKwargs'> ) → Sam3LiteTextTextEncoderOutput or tuple(torch.FloatTensor)

パラメータ

  • input_ids (torch.LongTensor の形状 (batch_size, sequence_length), 、省略可) — 語彙における入力シーケンスのトークンインデックスです。デフォルトではパディングは無視されます。

    インデックスはAutoTokenizerを使用して取得できます。詳細については、PreTrainedTokenizer.encode()およびPreTrainedTokenizer.call()を参照してください。

    入力IDとは何ですか?

  • attention_mask (torch.Tensor の形状 (batch_size, sequence_length), 、任意) — パディングトークンのインデックスに対するアテンションを回避するためのマスク。 [0, 1]:
    • マスクされていないトークンに対して1
    • マスクされたトークンに対しては 0 です。

    アテンションマスクとは?

戻り値

Sam3LiteTextTextEncoderOutput または tuple(torch.FloatTensor)

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

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

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

  • last_hidden_state (torch.FloatTensor、shape (batch_size, sequence_length, hidden_size)) — テキストエンコーダーからの隠れ状態の完全なシーケンス。
  • pooler_output (torch.FloatTensor、shape (batch_size, projection_dim)) — 内部の CLIP 形式の projection によって projection_dim に射影された、EOT によるプーリング済み出力。
  • hidden_states (tuple(torch.FloatTensor), 任意) — output_hidden_states=True の場合に返される、各層の隠れ状態のタプル。
  • attentions (tuple(torch.FloatTensor)、任意) — output_attentions=True の場合に返される、各 Transformer レイヤーの注意重みのタプル。

Sam3LiteTextModel

class transformers.Sam3LiteTextModel

< >

( config: Sam3LiteTextConfig )

forward

< >

( pixel_values: typing.Optional[torch.FloatTensor] = Nonevision_embeds: transformers.models.sam3_lite_text.modeling_sam3_lite_text.Sam3LiteTextVisionEncoderOutput | None = Noneinput_ids: typing.Optional[torch.LongTensor] = Noneattention_mask: typing.Optional[torch.Tensor] = Nonetext_embeds: typing.Optional[torch.FloatTensor] = Noneinput_boxes: typing.Optional[torch.FloatTensor] = Noneinput_boxes_labels: typing.Optional[torch.LongTensor] = None**kwargs: *<class 'transformers.utils.generic.TransformersKwargs'> ) → Sam3LiteTextImageSegmentationOutput or tuple(torch.FloatTensor)

パラメータ

  • pixel_values (torch.FloatTensor、形状 (batch_size, num_channels, image_size, image_size)、任意) — 入力画像に対応するテンソルです。ピクセル値は Sam3ImageProcessor を使用して取得できます。詳細については Sam3ImageProcessor.call() を参照してください(Sam3Processor は画像の処理に Sam3ImageProcessor を使用します)。
  • vision_embeds (Sam3LiteTextVisionEncoderOutput、任意) — 事前計算済みのビジョン埋め込みです。ビジョン埋め込みを簡単に再利用できます。指定した場合、pixel_values は渡さないでください。pixel_values とは排他的です。
  • input_ids (torch.LongTensor の形状 (batch_size, sequence_length), 、省略可) — 語彙における入力シーケンスのトークンインデックスです。デフォルトではパディングは無視されます。

    インデックスはAutoTokenizerを使用して取得できます。詳細については、PreTrainedTokenizer.encode()およびPreTrainedTokenizer.call()を参照してください。

    入力IDとは何ですか?

  • attention_mask (torch.Tensor の形状 (batch_size, sequence_length), 、任意) — パディングトークンのインデックスに対するアテンションを回避するためのマスク。 [0, 1]:
    • マスクされていないトークンに対して1
    • マスクされたトークンに対しては 0 です。

    アテンションマスクとは?

  • text_embeds (torch.FloatTensor、形状 (batch_size, sequence_length, hidden_size)、任意) — 事前計算されたテキスト埋め込み。テキスト埋め込みを簡単に再利用するために使用できます。指定した場合、input_ids は渡すべきではありません。input_ids とは排他的です。
  • input_boxes (torch.FloatTensor、shape (batch_size, num_boxes, 4)、任意) — [0, 1] の範囲で正規化されたボックス座標。(cx, cy, w, h) の形式です。
  • input_boxes_labels (torch.LongTensor、形状 (batch_size, num_boxes)、任意) — ボックスのラベル: 1 (正)、0 (負)。

戻り値

Sam3LiteTextImageSegmentationOutput または tuple(torch.FloatTensor)

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

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

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

  • pred_masks (torch.FloatTensor、shape (batch_size, num_queries, height, width)) — 各クエリに対する予測セグメンテーションマスク。
  • pred_boxes (torch.FloatTensor、shape (batch_size, num_queries, 4)) — (x1, y1, x2, y2) 形式で予測されたバウンディングボックス。
  • pred_logits (torch.FloatTensor、shape (batch_size, num_queries)、optional) — 各クエリに対する分類の信頼度スコア。デコーダのクエリ特徴量とテキスト特徴量の間の内積によって計算されます。
  • presence_logits (torch.FloatTensor、shape (batch_size, 1)、任意) — DETR デコーダーの presence トークンからの presence logits(最終層のみ)。シーン内にオブジェクトが存在するかどうかを示します。pred_logits と乗算することで最終スコアを計算できます: final_scores = pred_logits.sigmoid() * presence_logits.sigmoid()。
  • semantic_seg (torch.FloatTensor、shape (batch_size, 1, height, width)、任意) — セマンティックセグメンテーションの出力。
  • decoder_hidden_states (tuple[torch.FloatTensor]、optional) — DETR のデコーダー各層からの隠れ状態のタプル。各テンソルの形状は (batch_size, num_queries, hidden_size) です。
  • decoder_reference_boxes (torch.FloatTensor、shape (num_layers, batch_size, num_queries, 4)、optional) — DETR のすべての decoder レイヤーからの参照ボックス。
  • encoder_hidden_states (tuple[torch.FloatTensor]、optional) — DETRエンコーダーの全レイヤーからの隠れ状態のタプル。
  • vision_hidden_states (tuple[torch.FloatTensor]、optional) — 全ビジョンエンコーダー(ViT)層からの隠れ状態のタプル。
  • vision_attentions (tuple[torch.FloatTensor]、optional) — ビジョンエンコーダー(ViT)レイヤーからのアテンション重み。
  • detr_encoder_attentions (tuple[torch.FloatTensor]、任意) — DETRエンコーダ層からのアテンション重み。
  • detr_decoder_attentions (tuple[torch.FloatTensor]、任意) — DETR デコーダー層からのアテンション重み(自己アテンションとクロスアテンション)。
  • mask_decoder_attentions (tuple[torch.FloatTensor]、任意) — マスクデコーダー層からのアテンション重み。

例:

>>> from PIL import Image
>>> from huggingface_hub.utils import httpx
>>> from io import BytesIO
>>> from transformers import AutoModel, AutoProcessor

>>> model = AutoModel.from_pretrained("facebook/sam3_lite_text")
>>> processor = AutoProcessor.from_pretrained("facebook/sam3_lite_text")

>>> url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/sam-car.png"
>>> with httpx.stream("GET", url) as response:
...     image = Image.open(BytesIO(response.read())).convert("RGB")
>>> text = "car"
>>> inputs = processor(images=image, text=text, return_tensors="pt")

>>> # Get segmentation output
>>> outputs = model(**inputs)
>>> pred_masks = outputs.pred_masks
>>> pred_boxes = outputs.pred_boxes

Sam3LiteTextPreTrainedModel

class transformers.Sam3LiteTextPreTrainedModel

< >

( config: PreTrainedConfig*inputs**kwargs )

パラメータ

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

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

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

forward

( *args**kwargs )

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

Update on GitHub