Skip to main content

A Python-based framework for Tobii eye tracker experiments and multimodal interaction.

Project description

PyPI License PyPI - Downloads Documentation Status

Toolkit for AI-enhanced Eye-tracking data collection

A Python framework for conducting eyetracking-based experiments on perception and reasoning in machine learning (ML) tasks, as well as for data enrichment.

The framework integrates multiple data modalities commonly used as inputs for ML models and provides a platform for rapid experiment design and execution. It combines the PsychoPy platform for basic user input and eye-tracking hardware calibration (and emulation), state-of-the-art AI models for data processing and analysis, and a custom, extensible architecture built on top of tobii-pytracker.

  • Non-intrusive, multimodal data labeling, including:

    • Classical label assignment
    • ML-guided object annotations with free speech input, which is automatically transcribed into text and aligned with the regions the user refers to (based on eye gaze area-of-interest detection)
  • Analytical platform for experiment results, offering:

    • Classical metrics such as saccades, fixations, and heatmaps
    • Advanced methods for analysis and visualization, including process mining scanpath analysis and concept detection based on eye-gaze clusters

Alt text

Table of Contents

Requirements

  • Python 3.10.x - (Python 3.10 version is crucial, the script won't work with any other version)
  • Pip
  • Tobii Pro Eye Tracker Manager (only optional, for some extra features like firmware updates, etc.)

Installation

  1. Clone or download this repository to your local machine.

    conda create --name pytracker-env python=3.10
    conda activate pytracker-env
    git clone https://github.com/sbobek/tobii-pytracker.git
    cd tobii-pytracker
    pip install .
    

    Install psychopy, with no-deps, to keep the installation simple and lightweight. Note that we need psychopy in a version at least 2024.1.4

    pip install "psychopy>=2024.1.4,<2025.1.0" --no-deps
    

Usage

  1. To run the script, use the following command (make sure you have activated virtual environment):

    tobii-pytracker
    

*Make sure to connect eyetracker to your device before running the script with --enable_eyetracker=True, otherwise it will fail.

  1. Additionally you can specify a few arguments:
  • --config_file - Path to YAML script config file (default: configs/config.yaml)
  • --eyetracker_config_file - Path to YAML eyetracker config file (default: configs/eyetracker_config.yaml)
  • --enable_eyetracker - Launch script with launchHubServer (requires connected eyetracker) (default: False)
  • --enable_voice - Start voice recording for Think-Aloud Protocol (default: False)
  • --raw_data - Record full Tobii raw samples instead of filtered gaze positions (default: False)
  • --disable_psychopy - Run headless (no GUI) and continuously record gaze + voice until stopped (default: False)
  • --loop_count - Number of stimuli to display before exit (default: 10)
  • --log_level - Logger level ("info", "debug", "warning", "error", "critical") (default: info)

For more information and usage you can run tobii-pytracker --help

Datasets

Different datasets can be specified in the config file that will be processed and displayed in the PsychoPy window. They must be downloaded locally on the device where the script is run and follow these structure rules:

  1. Image datasets (.png, .jpg, .jpeg, .bmp, .gif):

    ├── dataset
    │   ├── category1
    │   │   ├──file1.jpg
    │   │   ├──file2.jpg
    │   │   └──...
    │   ├── category2
    │   │   ├──file1.jpg
    │   │   ├──file2.jpg
    │   │   └──...
    │   └── ...
    └── ...
    

    NOTE: GUI will be created accordingly to this structure and class labels will be extracted from subfolder names within the dataset. If using custom model, remember to make them match class names.

  2. Text datasets (.csv):

    ├── dataset.csv
    └── ...
    

    NOTE: The first line in .csv file MUST be a header. The GUI will take unique label values from a column with a name specified in config file.

Custom Model

The custom model for detecting bounding boxes fro possible area of interest is optional. Every dataset class has its own bounding-box detection method (words for text, bins dor time-series, superpixels for images). However, you might want to change it with your custom implementation. It is desired, when you want to get bounding box from external model at the runtime, because for instance screenshots have format or size which is not used by you detection model and cannot be use post-hoc.

The CustomModel class (located in runtime_models/custom_model.py) serves as an abstract base class. It defines the essential methods that any custom model implementation must provide. By inheriting from CustomModel and implementing these methods, your custom model can seamlessly interact with the rest of the toolkit:

  • prepare_model(self): Load and prepare model for prediction
  • predict(self, input_data): Run prediction with the loaded model
  • process(self, path): Post-process the prediction and return formatted results

Creating Your Own Model Modules

To create your own model module:

  1. Create a new Python file within the specified directory (e.g., custom_runtime_models/my_custom_model.py).

  2. Import the CustomModel class:

from runtime_models.custom_model import CustomModel
  1. Define a new class that inherits from CustomModel:
class MyCustomModel(CustomModel):

  def prepare_model(self):
    # Load and prepare model for prediction
    self.logger.debug("Preparing MyCustomModel...")
    self.model = ...
    self.logger.debug("Model preparation done.")

  def predict(self, input_data):
    # Run prediction with the loaded model
    predictions = ...
    return predictions

  def process(self, data):
    # Post-process the prediction and return formatted results
    predictions = self.predict(data)
    processed_predictions = ...
    return processed_predictions

Keep in mind that main processing pipeline uses the process() method to save processed model predictions.

Configuration

The script requires two configuration files in YAML format: one for general settings and another for eye tracker settings. By default, the configuration files are located in `configs`` directory.

General Configuration (config.yaml)

The general configuration file should include the following fields:

dataset:
  path: path/to/dataset
display:
  monitor:
    name: monitor_name
    resolution:
      - width
      - height
    width: monitor_width
    distance: distance_from_monitor
  gui:
    button:
      size:
        - size_x
        - size_y
      color: color
      text:
        color: text_color
        size: text_size
    fixation_dot: 
      size: radius_of_a_dot
      color: dot_color
    aoe:
      - size_x
      - size_y
output:
  folder: folder
  file: file

bbox_model:
  folder: folder
  module: module
  class: class
  filename: filename


instructions:
  intro:
    - "Introductory message."
    - "Press SPACE to begin."
  outro:
    - "Message for the end of the study."
    - "You may now close the window or press ESC to exit."

NOTE: If using a dataset with text data, the path should be specified for a file in a .csv format, as well as additional text field:

dataset:
  path: path/to/file.csv
  text:
    label_column_name: label_column_name
    text_column_name: text_column_name

Eye Tracker Configuration (eyetracker_config.yaml)

The eye tracker configuration file should include the fields required by launchHubServer from the psychopy.iohub module. Refer to the PsychoPy documentation for more details on the specific settings.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tobii_pytracker-0.1.2.tar.gz (42.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tobii_pytracker-0.1.2-py3-none-any.whl (42.5 kB view details)

Uploaded Python 3

File details

Details for the file tobii_pytracker-0.1.2.tar.gz.

File metadata

  • Download URL: tobii_pytracker-0.1.2.tar.gz
  • Upload date:
  • Size: 42.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for tobii_pytracker-0.1.2.tar.gz
Algorithm Hash digest
SHA256 82014f28c69be0b8e47ed3e6fcf604cb5ae6afa59ed4ae51b903b564af7e29bf
MD5 216a1bef4453bc866453675cf2507b45
BLAKE2b-256 972027dc6841d83b51c1cd3d3c2de4f19ca8b732d4351d83ac4960f62ea9f5b4

See more details on using hashes here.

File details

Details for the file tobii_pytracker-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for tobii_pytracker-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8d6418aa9aa161a611693dd3ba0080851790239839791ffb77a068eeb38ed986
MD5 deb62683956bc9c44441ff3fa17c3928
BLAKE2b-256 289ce3c0108992e8961bb2da4a1fe2155b2a9b93bd062a6452e4af1a02d313ce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page