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

サーバーレス Cloud API

Roboflow クラウドの GPU アクセラレーションされたオートスケール基盤上で、Workflow とモデル推論を実行します。

概要

Roboflow にデプロイされたモデルには REST API があり、これを使って画像に対する推論を実行できます。このデプロイ方法は、デプロイ先デバイスで永続的なインターネット接続がある環境に最適です。

アプリでは、このエンドポイントは「Serverless Cloud API」と表示されます。スペースが限られている場合(例:Workflow エディタのランタイム選択器)は「Cloud API」と表示されます。A 専用デプロイメント エンドポイント(*.roboflow.cloud)は「Dedicated Cloud API」と表示され、古い v1 エンドポイントは「Hosted API (Legacy)」と表示されます。これらのラベルは、以前の「Serverless Hosted API」および「Serverless API V2」という名称に置き換わります。

Serverless Cloud API は次の用途で使えます:

Inference サーバー

私たちの Serverless Cloud API は次の技術によって支えられています。 Inference Server。つまり、以下に示すように、Serverless Cloud API とセルフホスティングのオプションを簡単に切り替えたり、その逆も行えます:

from inference_sdk import InferenceHTTPClient

CLIENT = InferenceHTTPClient(
    # api_url="http://localhost:9001" # セルフホスト型 Inference サーバー
    api_url="https://serverless.roboflow.com", # 私たちの Serverless Cloud API
    api_key="API_KEY" # 非公開モデルとデータにアクセスする場合は任意
)

result = CLIENT.infer("image.jpg", model_id="model-id/1")
print(result)

制限

私たちの Serverless Cloud API は最大 20MB のファイルアップロードをサポートしています。高解像度の画像では制限に達する場合があります。問題が発生した場合は、エンタープライズサポートの担当者に連絡するか、以下にメッセージを投稿してください。 フォーラム.

リクエストが大きすぎる場合は、添付画像のサイズを小さくすることを推奨します。画像は、サーバーで受信された後に、モデルアーキテクチャが受け付ける入力サイズまで自動的に縮小されるため、通常はパフォーマンスが低下することはありません。 Python SDK などの一部の SDK では、API に送信される前に画像をモデルアーキテクチャの入力サイズまで自動的に縮小します。


次を参照してください: Serverless Cloud API v1 従来の API ドキュメントを参照してください。

HTTP API

REST API とともに使用

Serverless Cloud API には、すべてのモデルと Workflows に対して 1 つのエンドポイントがあります:

HTTP エンドポイント

Legacy Infer From Request

post

Legacy inference endpoint for object detection, instance segmentation, and classification.

Args: background_tasks: (BackgroundTasks) pool of fastapi background tasks dataset_id (str): ID of a Roboflow dataset corresponding to the model to use for inference OR workspace ID version_id (str): ID of a Roboflow dataset version corresponding to the model to use for inference OR model ID api_key (Optional[str], default None): Roboflow API Key passed to the model during initialization for artifact retrieval. # Other parameters described in the function signature...

Returns: Union[InstanceSegmentationInferenceResponse, KeypointsDetectionInferenceRequest, ObjectDetectionInferenceResponse, ClassificationInferenceResponse, MultiLabelClassificationInferenceResponse, SemanticSegmentationInferenceResponse, Any]: The response containing the inference results.

パスパラメータ
dataset_idstring必須

ID of a Roboflow dataset corresponding to the model to use for inference OR workspace ID

version_idstring必須

ID of a Roboflow dataset version corresponding to the model to use for inference OR model ID

クエリパラメータ
api_keystring · ヌル許容オプション

Roboflow API Key that will be passed to the model during initialization for artifact retrieval

confidenceany ofオプション

The confidence threshold used to filter out predictions. Pass a float in [0, 1], or "best" to use F1-optimal thresholds from model evaluation, or "default" to use the model's built-in default.

Default: 0.4
numberオプション
または
string · enumオプション可能な値:
keypoint_confidencenumberオプション

The confidence threshold used to filter out keypoints that are not visible based on model confidence

Default: 0
formatstringオプション

One of 'json' or 'image'. If 'json' prediction data is return as a JSON string. If 'image' prediction data is visualized and overlayed on the original input image.

Default: json
imagestring · ヌル許容オプション

The publically accessible URL of an image to use for inference.

image_typestring · ヌル許容オプション

One of base64 or numpy. Note, numpy input is not supported for Roboflow Hosted Inference.

Default: base64
labelsboolean · ヌル許容オプション

If true, labels will be include in any inference visualization.

Default: false
mask_decode_modestring · ヌル許容オプション

One of 'accurate' or 'fast'. If 'accurate' the mask will be decoded using the original image size. If 'fast' the mask will be decoded using the original mask size. 'accurate' is slower but more accurate.

Default: accurate
tradeoff_factornumber · ヌル許容オプション

The amount to tradeoff between 0='fast' and 1='accurate'

Default: 0
max_detectionsintegerオプション

The maximum number of detections to return. This is used to limit the number of predictions returned by the model. The model may return more predictions than this number, but only the top max_detections predictions will be returned.

Default: 300
overlapnumberオプション

The IoU threhsold that must be met for a box pair to be considered duplicate during NMS

Default: 0.3
strokeintegerオプション

The stroke width used when visualizing predictions

Default: 1
disable_preproc_auto_orientboolean · ヌル許容オプション

If true, disables automatic image orientation

Default: false
disable_preproc_contrastboolean · ヌル許容オプション

If true, disables automatic contrast adjustment

Default: false
disable_preproc_grayscaleboolean · ヌル許容オプション

If true, disables automatic grayscale conversion

Default: false
disable_preproc_static_cropboolean · ヌル許容オプション

If true, disables automatic static crop

Default: false
disable_active_learningboolean · ヌル許容オプション

If true, the predictions will be prevented from registration by Active Learning (if the functionality is enabled)

Default: false
active_learning_target_datasetstring · ヌル許容オプション

Parameter to be used when Active Learning data registration should happen against different dataset than the one pointed by model_id

sourcestring · ヌル許容オプション

The source of the inference request

Default: external
source_infostring · ヌル許容オプション

The detailed source information of the inference request

Default: external
response_mask_formatstring · enum · ヌル許容オプション

The format of the prediction mask - polygon (default) or rle - applicable for instance segmentation models.

Default: polygon可能な値:
レスポンス
200

Successful Response

application/json
または
または
または
または
または
または
または
anyオプション
post/{dataset_id}/{version_id}
POST /{dataset_id}/{version_id} HTTP/1.1
Accept: */*
{
  "visualization": "text",
  "inference_id": "text",
  "frame_id": 1,
  "time": 1,
  "image": [
    {
      "width": 1,
      "height": 1
    }
  ],
  "predictions": [
    {
      "x": 1,
      "y": 1,
      "width": 1,
      "height": 1,
      "confidence": 1,
      "class": "text",
      "class_id": 1,
      "detection_id": "text",
      "parent_id": "text",
      "class_confidence": 1,
      "points": [
        {
          "x": 1,
          "y": 1
        }
      ],
      "mask_format": "polygon"
    }
  ]
}

画像上でモデルを実行する

Roboflow は複数のランタイムを通じて推論を提供しています。適切な選択は、単一のモデルを呼び出すのか Workflow を呼び出すのか、必要なスループット、そしてワークロードがどこで実行されるかによって決まります。

このページは簡単な概要です。詳細な推論リファレンスは、同じドキュメントサイトの一部である 製品ドキュメントにあります。より詳しい内容がある場所には相互リンクが用意されています。

推論ランタイム

ランタイム
次の場合に使用
参照

サーバーレス Cloud API (serverless.roboflow.com)

デフォルト。ホスト型、自動スケーリング、モデルと Workflows をサポート。

専用デプロイメント

予測可能なレイテンシ、高スループット、または固定 GPU 種類が必要な場合。Roboflow によって管理されます。

Roboflow Inference (セルフホスト型)

オンプレミス、エッジデバイス、エアギャップ環境、または VPC の外に出せないワークロード向け。オープンソースです。

Serverless Cloud API の呼び出し

モデルを実行:

Workflow を実行:

ライブ動画については、 サーバーレス動画ストリーミング APIを参照してください。大きな画像や動画セットを非同期処理する場合は、 バッチ処理.

非推奨: Serverless v1

従来のタスク固有エンドポイントである detect.roboflow.com, classify.roboflow.com, outline.roboflow.com, segment.roboflow.com非推奨です。後方互換性のために今でも応答しますが、新しいコードでは serverless.roboflow.com を使用してください。

もし *.roboflow.com のタスクホストを指すスニペットを見つけたら、それは従来版として扱い、上の Serverless Cloud API 形式に変換してください。

Python SDK

Python SDK とともに使用

Python を使っている場合、Serverless Cloud API とやり取りする最も便利な方法は Inference Python SDK を使うことです。

を使用するには、 Inference SDK、まずインストールします:

Serverless Cloud API にリクエストを送るには、次のコードを使用します:

上で、 モデルID および APIキーを指定してください。このコードはモデルを実行し、結果を返します。

Roboflow Instant Model

Serverless Cloud API は Roboflow の Instant Modelの実行もサポートしています。Instant Model は他のモデルと同じように実行できますが、信頼度のしきい値は Instant Model では敏感に影響する場合があることに注意してください。

最適な confidence は、モデルが学習した画像枚数によって異なります。最適なしきい値は通常 0.85 から 0.99 の範囲です。

Python SDK で動画をストリーミングする

Inference SDK の WebRTC クライアントを使用して、動画上で物体検出モデルを実行できます。Serverless Video Streaming API は Roboflow Cloud で動画を処理し、各フレームの予測を返します。

SDK を WebRTC 依存関係とともにインストールし、 supervision:

置き換える API_KEY および model-id/1 をあなたの API キーとモデル ID に置き換えてください。ウェブカメラや RTSP カメラからのストリーミング、各フレームの処理、または Workflow の実行方法については、 Serverless Video Streaming API ガイド.

CLI

Roboflow CLI を使用して、Roboflow で学習したモデルや、 Roboflow Universe.

を実行することで roboflow infer コマンドラインで、CLI は画像を Roboflow API に送信し、予測を出力します。

コマンド

オプション

フラグ
説明

-m, --model

内のモデル ID project/version 形式(必須)

-c, --confidence

confidence のしきい値、0.0〜1.0(デフォルト: 0.5)

-o, --overlap

重なり / NMS のしきい値、0.0〜1.0(デフォルト: 0.5)

-t, --type

モデルの種類(自動検出をスキップ): object-detection, classification, instance-segmentation, semantic-segmentation, keypoint-detection

Roboflow Universe のオープンソースモデルを使って推論を実行します。たとえば、 poker-cards データセット:

ワークスペースは、設定済みのワークスペースが既定値になります。別のワークスペースのモデルを使うには:

自動検出 API 呼び出しをスキップするには、モデルの種類を指定します:

JSON 出力

使用 --json を使うと、スクリプト化や自動化向けの構造化された予測データを取得できます:

サポートされているすべてのパラメータは以下で確認できます: roboflow infer --help.

最終更新

役に立ちましたか?