Skip to main content

Welcome to face-rhythm

PyPI version Downloads Python versions build Documentation Status License: MIT

What is face-rhythm

A Python package that turns videos of facial or other behavior into a small set of interpretable behavioral components.

Why use face-rhythm?

  • Unsupervised. No labels, no model zoo.
  • Interpretable. Each component is a (space × frequency × time) factor you can plot and read off directly.

How to use it

Interactive notebooks:

Command line for batch runs across many sessions:

python scripts/run_pipeline_basic.py --path_params params.json --directory_save /path/to/project/

scripts/params_pipeline_basic.json is a ready-to-edit template.

Python API: see Quick start below, or the full API reference.

Installation

0. Requirements

1. Create a conda environment

conda create -n face_rhythm python=3.12
conda activate face_rhythm
python -m pip install --upgrade pip

Activate the env (conda activate face_rhythm) each time you use face-rhythm.

2. Install video packages

Linux:

conda install -c conda-forge 'torchcodec=*=cpu*' ffmpeg libstdcxx-ng

macOS:

conda install -c conda-forge 'torchcodec=*=cpu*' ffmpeg

Windows: skip this step. torchcodec doesn't explicitly support Windows. Installing it often works, but is not guaranteed. Unless you need ultrafast GPU speeds, just use the 'decord' backend, instead.

3. Install face-rhythm

pip install face-rhythm

For headless servers, GPU acceleration, and installation troubleshooting, see the installation docs.

4. Clone the repo to get the notebooks

git clone https://github.com/RichieHakim/face-rhythm.git

CLI Quick start

import json
import face_rhythm as fr

with open("params_pipeline_basic.json", "r") as f:
    params = json.load(f)

params["project"]["directory_project"] = "/path/to/new/project/"
params["paths_videos"]["directory_videos"] = "/path/to/videos/"
params["ROIs"]["initialize"]["path_file"] = "/path/to/ROIs.h5"

results = fr.pipelines.pipeline_basic(params)

Copy scripts/params_pipeline_basic.json as a template, edit the three paths, and run. Results land in the project directory as HDF5 files plus summary plots.

Upgrading

pip install --upgrade face-rhythm

To update the cloned notebooks/scripts: cd face-rhythm && git pull.

Pipeline at a glance

  1. Read the video frames (face_rhythm.helpers.BufferedVideoReader).
  2. Draw ROIs that pick (a) where to track and (b) what region to crop (face_rhythm.rois).
  3. Track a dense grid of points via optical flow (face_rhythm.point_tracking).
  4. Compute a spectrogram for each point's trajectory (face_rhythm.spectral_analysis).
  5. Factorize the (points × frequency × time) tensor with non-negative TCA (face_rhythm.decomposition).

GPU acceleration (optional)

face-rhythm runs on CPU by default. Install the CPU setup above first.

PyTorch compute: set project.use_GPU: true in your params. Check CUDA with:

python -c "import torch; print(torch.cuda.is_available())"

OpenCV CUDA: build OpenCV plus opencv_contrib with CUDA enabled, then make sure that build is the cv2 imported in this env. Useful links: OpenCV CUDA build options and opencv_contrib.

NVDEC video decoding: (uses experimental libraries). On Linux/NVIDIA systems, try a CUDA torchcodec package, then pass device='cuda' when constructing video readers:

conda install -c conda-forge 'torchcodec=*=cuda130*' ffmpeg libstdcxx-ng

Use cuda126*, cuda129*, or cuda130* to match your driver. Useful links: TorchCodec CUDA decoding and NVIDIA Video Codec SDK.

Citation

If you use face-rhythm in your research, please cite our preprint:

Hakim et al. (2025). Spectral envelopes of facial movements predict intention, cortical representations, and neural prosthetic control. bioRxiv. https://doi.org/10.1101/2025.09.10.675423

BibTeX and a machine-readable CITATION.cff are at the root of the repo.

Contributing

Bug reports, feature requests, and pull requests are welcome. Please open an issue before submitting substantial changes.

License

MIT — see LICENSE.

Metadata

Release files for face-rhythm 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for face-rhythm 0.3.3
File Size Uploaded
face_rhythm-0.3.3.tar.gz 174.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for face-rhythm 0.3.3
File Interpreter ABI Platform
face_rhythm-0.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 341.4 kB

Release files / face_rhythm-0.3.3.tar.gz

Download URL face_rhythm-0.3.3.tar.gz
Size 174.8 kB
Tags Source
SHA-256 checksum
How to use checksums
aea05c2540e0eeb58e15bf4d5e120347eba75d12364b06c20db2c517ba551b66
BLAKE2b-256 checksum
How to use checksums
dccff345ce7d8f4c0e389443d69b69c70dae2d1e5c4f1fd3991f26e0a5df65c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 7, 2026.

Transparency log

Release files / face_rhythm-0.3.3-py3-none-any.whl

Download URL face_rhythm-0.3.3-py3-none-any.whl
Size 166.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aaffe256f6ef5eac4751fc83b42d6a027cde973b25aac1865f779e372d0c0278
BLAKE2b-256 checksum
How to use checksums
e5bd169b87ebe8a054d742dee2c5741636c0803ef78e8c4e7611ebaffcfca9dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 7, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.3 This release

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page