> 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/models/ja/supported-models/l2cs-net.md).

# L2Cs-Net

L2Cs-Net は顔を検出し、各顔の yaw と pitch の角度を予測する視線方向推定モデルです。当社の [サーバーレスホスト型 API](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api).

{% hint style="warning" %}
**セルフホスト型 Inference では非推奨です。** 視線検出は非推奨になりました [Roboflow Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) MediaPipe 依存関係が削除されたときに。影響を受けるバージョンでは、 `/gaze/gaze_detection` エンドポイントと `Gaze` モデルクラスは FeatureDeprecatedError を送出します `FeatureDeprecatedError` （HTTP 410 Gone）となり、スタブエンドポイントは削除予定です。次を設定してください。 `CORE_MODEL_GAZE_ENABLED=False` 完全に無効化するには、これを設定してください。この機能が必要な場合は Roboflow にお問い合わせください。
{% endhint %}

## コード例

L2Cs-Net を HTTP エンドポイントで直接実行するには、 `curl`、または以下を使って: [`inference-sdk`](https://docs.roboflow.com/reference/inference/inference-sdk) ラッパー。

{% tabs %}
{% tab title="HTTP（curl）" icon="webhook" %}
{% stepper %}
{% step %}

### API キーを取得する

Roboflow アカウントを作成し、以下でキーを見つけます： [Roboflow API 設定ページ](https://app.roboflow.com/settings/api) その後、シェルで利用できるようにします：

```bash
export ROBOFLOW_API_KEY="your-key-here"
```

{% endstep %}

{% step %}

### モデルを実行する

以下を呼び出します: `/gaze/gaze_detection` エンドポイントを `curl`:

```bash
curl --location 'https://serverless.roboflow.com/gaze/gaze_detection' \
  --header 'Content-Type: application/json' \
  --data '{
    "api_key": "'"$ROBOFLOW_API_KEY"'",
    "image": {"type": "url", "value": "https://media.roboflow.com/inference/man.jpg"}
  }'
```

{% endstep %}
{% endstepper %}
{% endtab %}

{% tab title="SDK（Python）" icon="python" %}
{% stepper %}
{% step %}

### API キーを取得する

Roboflow アカウントを作成し、以下でキーを見つけます： [Roboflow API 設定ページ](https://app.roboflow.com/settings/api) その後、シェルで利用できるようにします：

```bash
export ROBOFLOW_API_KEY="your-key-here"
```

{% endstep %}

{% step %}

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

このパッケージは次のモデルを呼び出します：

```bash
pip install -U inference-sdk supervision
```

{% endstep %}

{% step %}

### モデルを実行する

下のコードサンプルは `detect_gazes`、これは同じ `/gaze/gaze_detection` エンドポイントを呼び出します:

```python
import os
import supervision as sv
from inference_sdk import InferenceHTTPClient

image = sv.load_image_from_url("https://media.roboflow.com/inference/man.jpg")

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
).select_api_v1()

result = client.detect_gazes(image)

for prediction in result[0]["predictions"]:
    face = prediction["face"]
    yaw = prediction["yaw"]
    pitch = prediction["pitch"]
    print(f"顔は ({face['x']}, {face['y']}) - yaw: {yaw:.3f}, pitch: {pitch:.3f}")
```

{% endstep %}
{% endstepper %}
{% endtab %}
{% endtabs %}

## 推論速度

レイテンシの測定条件： [Roboflow Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) NVIDIA L4 1基、バッチサイズ1でのウォームアップ後の平均。

<table data-search="false"><thead><tr><th>モデル</th><th>レイテンシ（ms）</th></tr></thead><tbody><tr><td><code>l2cs-net</code></td><td>6.0</td></tr></tbody></table>

モデルが入力として想定している単一の顔切り抜きで測定されます。

{% hint style="info" %}
設定する `api_url` をデプロイ先に合わせます：

* `https://serverless.roboflow.com` Serverless Hosted API 用。
* `http://localhost:9001` ローカルの [Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) サーバー用。
* あなたの [専用デプロイメント](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments) プライベートエンドポイント用の URL。
  {% endhint %}

レスポンスには、次を含むリストがあります。 `予測` （各項目に `顔` バウンディングボックス、 `ランドマーク`, `yaw`、および `pitch` （ラジアン単位）、 `時間`, `time_face_det`、および `time_gaze_det`.

セルフホスト型のデプロイと追加例については、 [Roboflow Inference ドキュメント](https://docs.roboflow.com/deployment/self-hosted/self-hosted).

## Inference（セルフホスト型）で使用する

L2Cs-Net はローカルの [Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) サーバーでも提供できます:

```bash
pip install inference inference-cli inference-sdk
inference server start  # serves http://localhost:9001
```

```python
import os
from inference_sdk import InferenceHTTPClient

client = InferenceHTTPClient(
    api_url="http://localhost:9001",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)

client.detect_gazes(inference_input="./image.jpg")
```

このモデルは、検出された顔ごとに 1 件のエントリを返し、顔ボックスとランドマークに加えて `yaw` と `pitch` （ラジアン単位）:

```python
[{'face': {'x': 1107.0, 'y': 1695.5, 'width': 1056.0, 'height': 1055.0,
           'confidence': 0.9356, 'class': 'face', 'class_id': 0,
           'landmarks': [{'x': 902.0, 'y': 1441.0}, {'x': 1350.0, 'y': 1449.0},
                         {'x': 1137.0, 'y': 1692.0}, {'x': 1124.0, 'y': 1915.0},
                         {'x': 625.0, 'y': 1551.0}, {'x': 1565.0, 'y': 1571.0}]},
  'pitch': 0.0295,
  'yaw': -0.0410}]
```

yaw と pitch を空間内の点に変換する際には、顔がカメラからおおよそ 1 メートル、身長がおおよそ 250 mm であると仮定します。これはウェブカメラ設定の出発点として妥当です。

以下の [視線検出の例](https://github.com/roboflow/inference) Inference リポジトリ内では、L2Cs-Net をウェブカメラで実行し、人がどこを見ているかを計算し、フレームに注釈を付ける方法を示しています。

### Workflows の実行モード

以下で使用する場合： [Workflow](https://docs.roboflow.com/workflows)、視線検出は次の 2 つのモードのいずれかで実行されます:

* **ローカル実行**：モデルは Inference サーバー上で実行されます。
* **リモート実行**：モデルは、以下を介してリモート Inference サーバー上で HTTP 経由で呼び出されます： `detect_gazes()` クライアントメソッド。

## さらに読む

* [視線検出とアイトラッキング：ハウツーガイド](https://blog.roboflow.com/gaze-direction-position/)
