Skip to content
idiapPublic

About

Enhancing 3D Gaze Estimation in the Wild using Weak Supervision with Gaze Following Labels.

Resources

Stars

23 stars

Watchers

0 watching

Forks

Repository files navigation

[CVPR 2025] Enhancing 3D Gaze Estimation in the Wild using Weak Supervision with Gaze Following Labels

Demo 1 Demo 2

Note: The color of the gaze vector follows a gradient from blue (frontal gaze toward the camera) to green (gaze directed away from the camera). Red indicates a gaze perpendicular to the camera, appearing in the middle of the gradient.

Overview

Authors: Pierre Vuillecard, Jean-marc Odobez

Paper | BibTeX

This repository contains the code and checkpoints for our CVPR 2025 paper "Enhancing 3D Gaze Estimation in the Wild using Weak Supervision with Gaze Following Labels".

Setup & Installation

First, we need to clone the repository

git clone 
cd <name_of_the_repo>

Next, create the conda environment and activate it after installing the necessary packages:

conda env create -f environment.yaml
conda activate gazeCVPR

Writing the output videos requires ffmpeg (with libx264) on your PATH. It is not installed in the conda environment, install it separately (e.g. sudo apt install ffmpeg, or module load ffmpeg on a cluster) and check it with ffmpeg -version.

Download the head detection & tracking models from Hugging Face (optional, demo.py downloads them automatically on first run):

bash setup.sh

Run the demos

The demo code is located in the demo.py file. Our Gaze Transformer model can perform inference on both images and videos. The demo first detects all the heads in the input using a head detector. Then, for each detected head, it predicts the gaze direction using our Gaze Transformer model. The output is drawn on the image or video and saved to the specified output directory.

To run the demo on images, only image inference is availabale:

python demo.py --input-filename data/pexels-jopwell-2422290.jpg --output-dir output/ --modality image

To run the demo on videos, you can either run the model with image inference where each frame is processed independently:

python demo.py --input-filename data/7149282-hd_1280_720_25fps.mp4 --output-dir output/ --modality image

Or you can run the model with video inference where the model uses temporal information to process the video.

python demo.py --input-filename data/7149282-hd_1280_720_25fps.mp4 --output-dir output/ --modality video

Additional parameters can be set such as the model checkpoint

--checkpoint ./checkpoints/gat_stwsge_gaze360_gf.ckpt # best SOTA model trained on Gaze360 and Gazefollow
--checkpoint ./checkpoints/gat_gaze360.ckpt # best model trained on Gaze360 only

You can also run the demo on GPU by adding the --device cuda. To reduce the inference time on video a batch processing is performed. Therefore, the --batch-size and --num-workers parameters can be set to speed up inference.

Heads are detected and tracked with the OmniHead head tracker (YOLO11m + BoT-SORT). On videos, tracks are then interpolated over missing frames and smoothed. The following parameters control it:

--det-conf 0.3        # head detection confidence threshold
--det-iou 0.5         # NMS IoU threshold
--smooth-window 5     # bbox smoothing window (frames)
--no-interpolate      # disable interpolation of missing frames in tracks
--no-smooth           # disable bbox smoothing
--min-head-size 0     # drop tracks whose mean head width (px) is below this value

Output files

For an input <name>.<ext> and a --modality of image or video, the demo writes to --output-dir:

File Content
<name>_detected_head.csv Head detections and tracks
<name>_<modality>_predicted_gaze.csv Same rows as above, plus the predicted gaze
<name>_<modality>_output.mp4 / .png Input video or image with heads and gaze drawn

Each row of the CSV files is one head in one frame:

Column Description
xmin, ymin, xmax, ymax Head bounding box in pixels of the original frame
pid Person (track) id, constant over a video. For images, heads are numbered 1..N
frame_id Frame index, starting at 1 (always 1 for images)
conf Head detection confidence. 0 means the box was interpolated over a frame where the head was not detected
gaze_x, gaze_y, gaze_z Unit 3D gaze direction in the head's coordinate frame, see below (predicted_gaze file only)

The gaze vector follows the Gaze360 convention. It is expressed in a frame attached to each head: z points along the line from the camera to the head (away from the camera), y points up and x points to the left of the image. So (0, 0, -1) always means looking straight at the camera, wherever the person is in the image. Because this frame depends on the head position, the same gaze values correspond to different directions in camera coordinates for heads at different places in the image.

Gaze in camera coordinates

The predicted gaze $\mathbf{g} = (g_x, g_y, g_z)$ is given in the head's frame described above. For 3D applications, it must first be rotated into camera coordinates using the camera intrinsics $K$ and the position of the head in the image. Note that this gives only the gaze direction: a 3D gaze ray also needs the 3D position of the head (or eyes) as its origin.

With the head box center $u = \frac{x_{min} + x_{max}}{2}$, $v = \frac{y_{min} + y_{max}}{2}$ and the camera up direction $\mathbf{a} = (0, -1, 0)$ (OpenCV axes: $x$ right, $y$ down, $z$ forward):

$$\mathbf{z}_h = \frac{K^{-1} [u,\, v,\, 1]^\top}{\left\| K^{-1} [u,\, v,\, 1]^\top \right\|}, \qquad \mathbf{y}_h = \frac{\mathbf{a} - (\mathbf{a}^\top \mathbf{z}_h)\,\mathbf{z}_h}{\left\| \mathbf{a} - (\mathbf{a}^\top \mathbf{z}_h)\,\mathbf{z}_h \right\|}, \qquad \mathbf{x}_h = \mathbf{y}_h \times \mathbf{z}_h$$ $$\mathbf{g}_{cam} = \begin{bmatrix} \mathbf{x}_h & \mathbf{y}_h & \mathbf{z}_h \end{bmatrix} \mathbf{g} = g_x\,\mathbf{x}_h + g_y\,\mathbf{y}_h + g_z\,\mathbf{z}_h$$

$\mathbf{z}_h$ points from the camera to the head, $\mathbf{y}_h$ is the camera's up direction made perpendicular to it, and $\mathbf{x}h$ points to the left of the image. For a head at the image center it reduces to $\mathbf{g}{cam} = (-g_x, -g_y, g_z)$.

Training

The dataset preprocessing for training will be released in the future.

License & Third-party resources

Dataset used for training:

Code

  • Our model is buit upon Swin3D from omnivore and used as pretrained model. code License: Attribution-NonCommercial 4.0 International

Demo:

  • Head detection & tracking from OmniHead (code License: AGPL-3.0): YOLO11m head detector weights (License: CC BY-NC-SA 4.0) with the BoT-SORT tracker code (License: MIT) through ultralytics (License: AGPL-3.0)

Citation

If you use this work, please cite the following paper:

@INPROCEEDINGS{vuillecard3DGAZEWILD2025,
         author = {Vuillecard, Pierre and Odobez, Jean-Marc},
       projects = {Idiap},
          month = jun,
          title = {Enhancing 3D Gaze Estimation in the Wild using Weak Supervision with Gaze Following Labels},
      booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
           year = {2025},
            pdf = {https://publications.idiap.ch/attachments/papers/2025/Pierre_3DGAZEESTIMATIONINTHEWILD_2025.pdf}
}

About

Enhancing 3D Gaze Estimation in the Wild using Weak Supervision with Gaze Following Labels.

Resources

Stars

23 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages