Classification

Roboflow でホストされている分類モデルで推論を実行します。

ローカルおよびホストされた画像で推論する

依存関係をインストールするには、 pip install inference-sdk.

from inference_sdk import InferenceHTTPClient

CLIENT = InferenceHTTPClient(
    api_url="https://classify.roboflow.com",
    api_key="API_KEY"
)

result = CLIENT.infer(your_image.jpg, model_id="vehicle-classification-eapcd/2")

レスポンスオブジェクトの形式

Single-Label Classification

ホストされたAPI推論ルートは次を返します JSON 配列 predictions を含むオブジェクトを返します。各 prediction は以下のプロパティを持ちます:

  • time = 画像を処理して予測を返すのにかかる合計時間(秒)

  • image = 画像に関する情報を保持するオブジェクト width および height

    • width 予測された画像の高さ

    • height = 予測された画像の高さ

  • predictions = 予測に対するすべての予測クラスとそれらに関連する信頼度の集合

    • class = 分類のラベル

    • confidence = 画像に検出された分類のオブジェクトが含まれているというモデルの信頼度

  • top = 最も高い信頼度の予測クラス

  • confidence = 最も高い予測信頼度スコア

  • image_path = 予測された画像のパス

  • prediction_type = 推論に使用されたモデルのタイプ、 ClassificationModel この場合

// JSONオブジェクトの例
{
  "time": 0.19064618100037478,
  "image": {
    "width": 210,
    "height": 113
  },
  "predictions": [
    {
      "class": "real-image",
      "confidence": 0.7149
    },
    {
      "class": "illustration",
      "confidence": 0.2851
    }
  ],
  "top": "real-image",
  "confidence": 0.7149,
  "image_path": "/cropped-images-1.jpg",
  "prediction_type": "ClassificationModel"
}

APIリファレンス

Inference APIの使用方法

POST https://classify.roboflow.com/:datasetSlug/:versionNumber

base64エンコードされた画像を直接モデルエンドポイントにPOSTできます。あるいは、画像が既に別の場所にホストされている場合は、クエリ文字列の image パラメータとしてURLを渡すことができます。

パスパラメータ

名前
タイプ
説明

datasetSlug

string

URL セーフなデータセット名。メインのプロジェクトビューの URL を見てウェブ UI で確認できます。

string

データセットのバージョンを識別するバージョン番号。

Query Parameters

名前
タイプ
説明

api_key

string

あなたの API キー(ワークスペースの API 設定ページから取得)

{
   "predictions":{
      "bird":{
         "confidence":0.5282308459281921
      },
      "cat":{
         "confidence":0.5069406032562256
      },
      "dog":{
         "confidence":0.49514248967170715
      }
   },
   "predicted_classes":[
      "bird",
      "cat"
   ]
}

Last updated

Was this helpful?