> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/reference/ja/tui-lun/inference-sdk/configuration.md).

# 設定

## 設定オプション

### コンテキストマネージャーでの設定

メソッド `use_configuration(...)` と `use_model(...)` は、コンテキストマネージャー内で動作するように設計されています。 **コンテキストマネージャーを抜けると、古い設定値が復元されます。**

```python
from inference_sdk import InferenceHTTPClient, InferenceConfiguration

image_url = "https://source.roboflow.com/pwYAXv9BTpqLyFfgQoPZ/u48G0UpWfk8giSw7wrU8/original.jpg"

custom_configuration = InferenceConfiguration(confidence_threshold=0.8)
# ROBOFLOW_API_KEY を Roboflow の API キーに置き換えてください
CLIENT = InferenceHTTPClient(
    api_url="http://localhost:9001",
    api_key="ROBOFLOW_API_KEY"
)

with CLIENT.use_configuration(custom_configuration):
    _ = CLIENT.infer(image_url, model_id="soccer-players-5fuqs/1")

with CLIENT.use_model("soccer-players-5fuqs/1"):
    _ = CLIENT.infer(image_url)

# コンテキストマネージャーを抜けた後 - 変更は元に戻り、`model_id` は引き続き必要です
_ = CLIENT.infer(image_url, model_id="soccer-players-5fuqs/1")
```

ご覧のとおり、 `model_id` は、デフォルトのモデルが設定されていない場合にのみ、予測メソッドに必要です。

{% hint style="info" %}
モデルIDは次の文字列で構成されます `<project_id>/<version_id>`。参照 [ワークスペースIDとプロジェクトID](/reference/ja/ren-zheng/authentication/workspace-and-project-ids.md) で、これらの情報を確認してください。
{% endhint %}

### 一度設定して、次の変更まで使用する設定

メソッド `configure(...)` と `select_model(...)` はクライアントの状態を変更し、その変更は次の変更まで保持されます。

```python
from inference_sdk import InferenceHTTPClient, InferenceConfiguration

image_url = "https://source.roboflow.com/pwYAXv9BTpqLyFfgQoPZ/u48G0UpWfk8giSw7wrU8/original.jpg"

custom_configuration = InferenceConfiguration(confidence_threshold=0.8)
# ROBOFLOW_API_KEY を Roboflow の API キーに置き換えてください
CLIENT = InferenceHTTPClient(
    api_url="http://localhost:9001",
    api_key="ROBOFLOW_API_KEY"
)

CLIENT.configure(custom_configuration)
CLIENT.infer(image_url, model_id="soccer-players-5fuqs/1")

# カスタム設定はそのまま保持されます
CLIENT.select_model(model_id="soccer-players-5fuqs/1")
_ = CLIENT.infer(image_url)

# カスタム設定と選択されたモデル - そのまま保持されます
_ = CLIENT.infer(image_url)
```

また、次の形式で初期化することもできます `チェーン` モード:

```python
from inference_sdk import InferenceHTTPClient, InferenceConfiguration

# ROBOFLOW_API_KEY を Roboflow の API キーに置き換えてください
CLIENT = InferenceHTTPClient(api_url="http://localhost:9001", api_key="ROBOFLOW_API_KEY") \
    .select_model("soccer-players-5fuqs/1")
```

### 上書き `model_id` 特定の呼び出しに対して

`model_id` は、特定の呼び出しで上書きできます:

```python
from inference_sdk import InferenceHTTPClient

image_url = "https://source.roboflow.com/pwYAXv9BTpqLyFfgQoPZ/u48G0UpWfk8giSw7wrU8/original.jpg"

# ROBOFLOW_API_KEY を Roboflow の API キーに置き換えてください
CLIENT = InferenceHTTPClient(api_url="http://localhost:9001", api_key="ROBOFLOW_API_KEY") \
    .select_model("soccer-players-5fuqs/1")

_ = CLIENT.infer(image_url, model_id="another-model/1")
```

## クライアント設定の詳細

`InferenceHTTPClient` は、次を提供します `InferenceConfiguration` 完全な設定を保持するための dataclass です。

```python
from inference_sdk import InferenceConfiguration
```

この設定内のフィールドを上書きすると、クライアント（およびモデルを提供する API）の挙動が変わります。特定のフィールドは特定のコンテキストで使用されます。特に:

### 分類モデル

* `visualize_predictions`: 可視化を有効 / 無効にするフラグ
* `confidence_threshold` を `confidence`
* `stroke_width`: 可視化における線の太さ
* `disable_preproc_auto_orientation`, `disable_preproc_contrast`, `disable_preproc_grayscale`, `disable_preproc_static_crop` サーバー側の前処理を変更するため
* `disable_active_learning` を防ぐため [アクティブラーニング](https://docs.roboflow.com/deployment/monitoring-and-analytics/active-learning) 機能がデータポイントを登録するのを防ぎます（たとえば、モデルをテストしているときに便利です）
* `active_learning_target_dataset` - 特定のモデルから推論を行うとき（たとえば `project_a/1`）に、別のプロジェクトにデータを保存したい場合 `project_b`をこのパラメータで指定してください。 **異なる種類のモデルを `project_a` と `project_b`で使用することはできないことに注意してください。その場合、データは登録されません。**
* `source`: 推論呼び出しに「source」属性を設定する任意の文字列です。 [モデル監視](https://docs.roboflow.com/deployment/monitoring-and-analytics/model-monitoring)を使用している場合、これは推論リクエストとともに記録されるため、どのアプリケーション、システム、またはデプロイメントがリクエストを送信しているかを特定するなど、特定のソースからの推論リクエストをフィルタリングまたは検索できます。
* `source_info`: 推論呼び出しに追加の「source\_info」属性を設定する任意の文字列です。たとえば、アプリ内のサブコンポーネントを特定するために使えます。

### 物体検出モデル

* `visualize_predictions`: 可視化を有効 / 無効にするフラグ
* `visualize_labels`: 可視化が有効な場合にラベル可視化を有効 / 無効にするフラグ
* `confidence_threshold` を `confidence`
* `class_filter` クラスのリストを除外するため
* `class_agnostic_nms`: NMS がクラス非依存かどうかを制御するフラグ
* `fix_batch_size`
* `iou_threshold`: NMS の IoU 閾値を指定するため
* `stroke_width`: 可視化における線の太さ
* `max_detections`: モデルから返す最大検出数
* `max_candidates`: モデルの後処理における最大候補数
* `disable_preproc_auto_orientation`, `disable_preproc_contrast`, `disable_preproc_grayscale`, `disable_preproc_static_crop` サーバー側の前処理を変更するため
* `disable_active_learning`, `active_learning_target_dataset`, `source`, `source_info` - 上記で説明したとおり

### キーポイント検出モデル

* `visualize_predictions`: 可視化を有効 / 無効にするフラグ
* `visualize_labels`: 可視化が有効な場合にラベル可視化を有効 / 無効にするフラグ
* `confidence_threshold` を `confidence`
* `keypoint_confidence_threshold` (as `keypoint_confidence`) を使って、モデルの信頼度に基づいて検出されたキーポイントを除外します
* `class_filter` オブジェクトクラスのリストを除外するため
* `class_agnostic_nms`: NMS がクラス非依存かどうかを制御するフラグ
* `fix_batch_size`
* `iou_threshold`: NMS の IoU 閾値を指定するため
* `stroke_width`: 可視化における線の太さ
* `max_detections`: モデルから返す最大検出数
* `max_candidates`: モデルの後処理における最大候補数
* `disable_preproc_auto_orientation`, `disable_preproc_contrast`, `disable_preproc_grayscale`, `disable_preproc_static_crop` サーバー側の前処理を変更するため
* `disable_active_learning`, `active_learning_target_dataset`, `source`, `source_info` - 上記で説明したとおり

### インスタンスセグメンテーションモデル

* `visualize_predictions`: 可視化を有効 / 無効にするフラグ
* `visualize_labels`: 可視化が有効な場合にラベル可視化を有効 / 無効にするフラグ
* `confidence_threshold` を `confidence`
* `class_filter` クラスのリストを除外するため
* `class_agnostic_nms`: NMS がクラス非依存かどうかを制御するフラグ
* `fix_batch_size`
* `iou_threshold`: NMS の IoU 閾値を指定するため
* `stroke_width`: 可視化における線の太さ
* `max_detections`: モデルから返す最大検出数
* `max_candidates`: モデルの後処理における最大候補数
* `disable_preproc_auto_orientation`, `disable_preproc_contrast`, `disable_preproc_grayscale`, `disable_preproc_static_crop` サーバー側の前処理を変更するため
* `mask_decode_mode`
* `tradeoff_factor`
* `disable_active_learning`, `active_learning_target_dataset`, `source`, `source_info` - 上記で説明したとおり

### クライアントの設定

* `output_visualisation_format`: 次のいずれか `VisualisationResponseFormat.BASE64`, `VisualisationResponseFormat.NUMPY`, `VisualisationResponseFormat.PILLOW`。サーバー側の可視化が有効な場合、出力で使用する形式を選択できます。
* `client_downsizing_disabled`: 次に設定 `False` クライアント側での縮小を行いたい場合。デフォルトは `True`です。クライアント側のスケーリングは、インターネット接続をより効率的に利用するために、推論用の入力を単に縮小する（アスペクト比を維持する）ことだけを目的としています（その代わりに画像操作 / トランスコードが発生します）。モデルの入力サイズ情報を使用してターゲットサイズを決定します。利用できない場合は `default_max_input_size` が使用されます。
* `max_concurrent_requests`: 同時に開始できるリクエストの最大数
* `max_batch_size`: 1回のリクエストに投入できる要素の最大数
* `workflow_run_retries_enabled`: Workflows の実行中に発生した一時的なエラーを再試行するかどうかを決めるフラグ。デフォルトは `true` で、デフォルトは環境変数 `WORKFLOW_RUN_RETRIES_ENABLED`.

### Workflows 実行の設定

* `profiling_directory`: Workflows のプロファイラートレースが保存される場所を指定します。デフォルトでは `./inference_profiling` ディレクトリです。
