L2Cs-Net

Use L2Cs-Net gaze detection model through our Serverless Hosted 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 Hosted API.

Code sample

Call the /gaze/gaze_detection endpoint directly with curl:

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

The same call through the SDK. Install it:

pip install inference-sdk

The code sample below calls detect_gazes, which hits the same /gaze/gaze_detection endpoint. Pass your Roboflow API Key via the API_KEY env variable.

import os
import urllib.request
from inference_sdk import InferenceHTTPClient

image_url = "https://media.roboflow.com/inference/man.jpg"
image_path = "man.jpg"
urllib.request.urlretrieve(image_url, image_path)

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.getenv("API_KEY"),
).select_api_v1()

result = client.detect_gazes(image_path)

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}")

Set api_url to match your deployment target:

  • https://serverless.roboflow.com for the Serverless Hosted 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.

Last updated

Was this helpful?