コンテンツにスキップ

モデルのデプロイ

MLOps Desktopには、モデルサービング用のHTTPサーバーが組み込まれています。学習済みモデルをデプロイし、REST API経由で予測を取得できます。追加のインフラストラクチャは不要です。

  • 学習済みモデル(クイックスタートを参照)
  • Pythonパッケージ:pip install fastapi uvicorn slowapi
  • ONNX使用時(オプション):pip install onnxruntime
  1. Servingタブを開く

    出力パネルのServingタブをクリックします。

  2. モデルを選択

    以下から選択できます。

    • Modelsタブに登録されたモデル
    • 現在のセッションで学習したモデル

    複数バージョンがある場合は特定のバージョンを選択します。

  3. サーバーを設定

    Configureボタン(歯車アイコン)をクリックします。

    設定デフォルト説明
    Host0.0.0.0リッスンアドレス
    Port8000HTTPポート
    Use ONNX RuntimeOff高速推論を有効化
  4. サーバーを起動

    Start Serverをクリックします。

    ステータスが変化します:Stopped → Starting → Running

    サーバーURL:http://localhost:8000

  5. 予測を実行

    curl、Python、JavaScriptなど任意のHTTPクライアントを使用できます。

Playgroundパネルでは、コードを書いたり外部ツールを使わずに、モデルをインタラクティブにテストできます。

  1. プレイグラウンドを開く — 出力パネルのPlaygroundタブをクリックします(Servingタブの隣)。
  2. 特徴量を入力 — モデルが必要とする各特徴量の入力フィールドに値を入力します。
  3. 予測を実行 — プレイグラウンドが実行中のサーバーにリクエストを送信し、結果をインラインで表示します。
  4. バッチテスト — CSVファイルをアップロードして、複数行の予測を一度に実行できます。結果はCSVとしてダウンロード可能です。

サーバー起動後、以下のエンドポイントが利用可能です。

Terminal window
curl http://localhost:8000/health

レスポンス:

{"status": "healthy", "model": "RandomForestClassifier"}
Terminal window
curl -X POST http://localhost:8000/predict \
-H "Content-Type: application/json" \
-d '{"features": [[5.1, 3.5, 1.4, 0.2]]}'

分類の場合:

{
"predictions": [0],
"probabilities": [[0.98, 0.01, 0.01]]
}

回帰の場合:

{
"predictions": [24.5]
}

複数サンプルを一度に送信できます。

Terminal window
curl -X POST http://localhost:8000/predict \
-H "Content-Type: application/json" \
-d '{
"features": [
[5.1, 3.5, 1.4, 0.2],
[6.2, 3.4, 5.4, 2.3],
[4.9, 2.5, 4.5, 1.7]
]
}'

FastAPIが自動生成するドキュメントにアクセスできます。

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

Servingタブにリアルタイムメトリクスが表示されます。

メトリクス説明
Total Requestsサーバー起動からの総リクエスト数
Success Rate成功レスポンス(2xx)の割合
Avg Latency平均応答時間
Requests/min現在のスループット

最近のリクエストログも表示されます。

ONNX Runtimeを使用すると、推論が高速化されます(ツリーベースモデルで2-10倍)。

  1. pip install onnxruntimeを実行
  2. ModelExporterノードでONNX形式にエクスポート
  3. Serving設定でUse ONNX Runtimeを有効化
  4. .onnxモデルファイルを選択
import requests
# 単一予測
response = requests.post(
"http://localhost:8000/predict",
json={"features": [[5.1, 3.5, 1.4, 0.2]]}
)
result = response.json()
print(f"予測クラス: {result['predictions'][0]}")
print(f"信頼度: {max(result['probabilities'][0]):.1%}")
# バッチ予測
import pandas as pd
df = pd.read_csv("new_data.csv")
features = df.drop(columns=["target"]).values.tolist()
response = requests.post(
"http://localhost:8000/predict",
json={"features": features}
)
predictions = response.json()["predictions"]
const response = await fetch('http://localhost:8000/predict', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
features: [[5.1, 3.5, 1.4, 0.2]]
})
});
const { predictions, probabilities } = await response.json();
console.log(`予測: ${predictions[0]}`);

MLOps Desktop外での本番デプロイ用にモデルをエクスポートできます。

ModelExporterノードで以下の形式で保存できます。

  • .joblib — Pythonアプリケーション向け
  • .onnx — クロスプラットフォーム、高速推論
  • .pkl — Pythonネイティブ(セキュリティに注意)
パッケージ用途必須
fastapiWebフレームワークYes
uvicornASGIサーバーYes
slowapiレート制限Yes
onnxruntimeONNX推論Optional

一括インストール:

Terminal window
pip install fastapi uvicorn slowapi onnxruntime

Servingタブは依存関係をチェックし、不足している場合は警告を表示します。

「FastAPIがインストールされていません」

Section titled “「FastAPIがインストールされていません」”
Terminal window
pip install fastapi uvicorn slowapi

設定でポートを変更するか、既存のプロセスを停止します。

Terminal window
lsof -i :8000 # プロセスを確認
kill -9 <PID> # 停止
  • ONNX Runtimeを有効化
  • 単一リクエストではなくバッチ予測を使用
  • モデルの複雑さを確認(大規模なRandom Forestは遅い)

サーバーはデフォルトで全オリジンを許可しています。問題が続く場合はリクエストヘッダーを確認してください。

サーバーにはslowapiによる基本的なレート制限が含まれています(IP毎に100リクエスト/分)。共有環境での乱用を防止します。