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.
Deprecated in self-hosted Inference. Gaze detection was deprecated in Roboflow Inference when the MediaPipe dependency was removed. On affected versions, the /gaze/gaze_detection endpoint and the Gaze model class raise FeatureDeprecatedError (HTTP 410 Gone), and the stub endpoint is scheduled for removal. Set CORE_MODEL_GAZE_ENABLED=False to disable it outright. Contact Roboflow if you need this capability.
L2CS-Net API
Run L2CS-Net through the HTTP endpoint directly with curl, or with the inference-sdk wrapper.
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"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"}
}'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"Install the dependencies
This package calls the model:
pip install -U inference-sdk supervisionRun 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}")L2CS-Net 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.comfor the Serverless Cloud API.http://localhost:9001for 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.
Run L2CS-Net with self-hosted Inference
L2CS-Net can also be served by a local Inference server:
pip install inference inference-cli inference-sdk
inference server start # serves http://localhost:9001import 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")The model returns one entry per detected face, containing the face box and landmarks plus yaw and pitch in radians:
[{'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}]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.