For the complete documentation index, see llms.txt. This page is also available as Markdown.

Perception Encoder

Dedicated Deployment または self-hosted Inference で、Meta の Perception Encoder を使用して画像とテキストの embedding を計算します

Perception Encoder は Meta の vision-language embedding model です。画像とテキストを共通の embedding space にマッピングし、類似検索、zero-shot classification、retrieval に使用します。

Perception Encoder は Serverless Hosted API では利用できません。実行するには Dedicated Deployment または self-hosted Inference.

Perception Encoder のエンドポイントは 3 つサポートしています:

  • /perception_encoder/embed_image — 画像を埋め込む

  • /perception_encoder/embed_text — 文字列を埋め込む

  • /perception_encoder/compare — 画像とテキストプロンプトのリスト間の類似度を計算する

コードサンプル

1

API Key を取得する

Roboflow アカウントを作成し、キーを次の場所で見つけます Roboflow API 設定ページ そしてシェルで利用できるようにします:

export ROBOFLOW_API_KEY="your-key-here"
2

依存関係をインストールする

これらのパッケージは画像を取得して API を呼び出します:

pip install requests opencv-python
3

モデルを実行する

以下のサンプルは画像を /perception_encoder/embed_image に送信し、embedding の shape を出力します。次を設定してください: URL を Dedicated Deployment の URL またはローカルの Inference server に設定します。

import base64
import os
import cv2
import numpy as np
import requests

URL = "https://your-deployment.roboflow.cloud"

content = requests.get("https://media.roboflow.com/notebooks/examples/dog.jpeg").content
image = cv2.imdecode(np.frombuffer(content, np.uint8), cv2.IMREAD_COLOR)

_, buffer = cv2.imencode(".jpg", image)
image_base64 = base64.b64encode(buffer).decode("utf-8")

response = requests.post(
    f"{URL}/perception_encoder/embed_image",
    json={
        "api_key": os.environ["ROBOFLOW_API_KEY"],
        "image": {"type": "base64", "value": image_base64},
    },
)
result = response.json()
embedding = result["embeddings"][0]
print(f"Embedding length: {len(embedding)}")
print(f"First values: {embedding[:5]}")

上記のコードは embedding の shape をターミナルに出力します:

Embedding の長さ: 1024
最初の値: [0.0545, -0.0338, -0.0355, -0.0062, 0.0154]

推論速度

〜で測定されたレイテンシ Roboflow Inference 1x NVIDIA L4、バッチサイズ 1、ウォームアップ後の平均で測定。

モデル
レイテンシ (ms)

perception-encoder

25.2

で測定 embed_image 上の PE-Core-L14-336 チェックポイント(画像埋め込みのみ)。

設定する URL をデプロイ先に合わせてください:

  • http://localhost:9001 ローカルの Inference サーバー用。

  • あなたの Dedicated Deployment プライベートエンドポイントの URL。

最終更新

役に立ちましたか?