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

L2Cs-Net

Use L2Cs-Net gaze detection model through our Serverless Cloud API

L2Cs-Net is a gaze direction estimation model that detects faces and predicts each face's yaw and pitch angles. You can run it through our Serverless Cloud API.

Code sample

Run L2Cs-Net through the HTTP endpoint directly with curl, or with the inference-sdk wrapper.

1

Get your API Key

Create a Roboflow account, find your key on the Roboflow API settings page and make it available to your shell:

export ROBOFLOW_API_KEY="your-key-here"
2

Run the model

Call the /gaze/gaze_detection endpoint with curl:

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"}
  }'
1

Get your API Key

Create a Roboflow account, find your key on the Roboflow API settings page and make it available to your shell:

export ROBOFLOW_API_KEY="your-key-here"
2

Install the dependencies

This package calls the model:

pip install -U inference-sdk supervision
3

Run the model

The code sample below calls detect_gazes, which hits the same /gaze/gaze_detection endpoint:

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 at ({face['x']}, {face['y']}) - yaw: {yaw:.3f}, pitch: {pitch:.3f}")

Inference speed

Latency measured with Roboflow Inference on 1x NVIDIA L4, batch size 1, mean after warmup.

Model
Latency (ms)

l2cs-net

6.0

Measured on a single face crop, which is what the model expects as input.

Set api_url to match your deployment target:

  • https://serverless.roboflow.com for the Serverless Cloud API.

  • http://localhost:9001 for a local Inference server.

  • Your Dedicated Deployment URL for a private endpoint.

The response contains a list with predictions (each with face bounding box, landmarks, yaw, and pitch in radians), time, time_face_det, and time_gaze_det.

For self-hosted deployments and additional examples, see the Roboflow Inference docs.

Use with Inference (self-hosted)

L2Cs-Net can also be served by a local Inference server:

The model returns one entry per detected face, containing the face box and landmarks plus yaw and pitch in radians:

Converting yaw and pitch into a point in space assumes faces are roughly one meter from the camera and roughly 250 mm tall, which is a reasonable starting point for webcam setups.

The gaze detection example in the Inference repository shows how to run L2Cs-Net on a webcam, compute where a person is looking, and annotate the frame.

Execution modes in Workflows

When used in a Workflow, gaze detection runs in one of two modes:

  • Local execution: the model runs on your Inference server.

  • Remote execution: the model is invoked over HTTP on a remote Inference server through the detect_gazes() client method.

Further reading

Last updated

Was this helpful?