pyfaceau
A python-based implementation of OpenFace 2.2's Facial Action Unit extraction pipeline with an accurate dlib substitute (pymtcnn, pyclnf).
Accuracy: r = 0.97 correlation with C++ OpenFace 2.2
Installation
Installing pyfaceau takes two steps: install the package, then download the OpenFace model files once.
Step 1: Install pyfaceau
pip install pyfaceau
This also installs the packages pyfaceau needs:
- pyclnf - Facial landmark detection (68 points)
- pymtcnn - Face detection
- pyfhog - FHOG feature extraction
Step 2: Download the OpenFace model files (one time)
pyfaceau uses model files from OpenFace 2.2.0. They are not included in pyfaceau: they belong to Carnegie Mellon University and may only be used for academic or non-profit, non-commercial research. To download them, open a terminal and run:
pyfaceau-download-models
The command shows a short summary of the OpenFace license and a link to the
full text, then asks you to type YES. It then prepares the OpenFace files
for pyfaceau and for the two packages pyfaceau uses, pyclnf (facial
landmarks) and pymtcnn (face detection): about 440 MB in total, almost all of
it pyclnf's landmark models. The files come from OpenFace's official GitHub
page and, for pyclnf's four large files, from the Dropbox or OneDrive links
OpenFace itself uses. Every file is checked, and the command tells you when it
is done. You only need to do this once per computer, also after upgrading.
The files are saved in one folder shared by pyfaceau, pyclnf and pymtcnn:
| System | Folder |
|---|---|
| macOS | ~/Library/Application Support/OpenFaceModels/2.2.0/ |
| Windows | %LOCALAPPDATA%\OpenFaceModels\2.2.0\ |
| Linux | ~/.local/share/OpenFaceModels/2.2.0/ (or $XDG_DATA_HOME) |
To use another folder, set the environment variable OPENFACE_MODELS_DIR
before running the command and your program (the 2.2.0 sub-folder is added
for you). On a computer without a terminal prompt (scripts, servers), use
pyfaceau-download-models --accept-license, or set
OPENFACE_MODELS_ACCEPT_LICENSE=1 to accept the license; pyfaceau then
downloads missing files when it starts.
If you already have a folder with the model files, you can keep using it:
OpenFaceProcessor(weights_dir="/path/to/weights") always uses the folder
you give it.
Troubleshooting
- "The OpenFace model files that pyfaceau needs are not installed yet"
(or the same message for pyclnf or pymtcnn): run
pyfaceau-download-models(Step 2). It prepares the files of all three packages. pyfaceau-download-models: command not found: runpython -m pyfaceau.download_modelsinstead, with the same Python you installed pyfaceau into.- Certificate error on macOS (
CERTIFICATE_VERIFY_FAILED): open the Python folder in Applications, double-clickInstall Certificates.command, and try again. - Download stopped or failed: run the command again. Files that were
already downloaded and checked are kept. Behind a firewall or proxy, make
sure
raw.githubusercontent.comandwww.dropbox.com(oronedrive.live.com) can be reached.
Upgrading from pyfaceau 1.3 or earlier
Run pyfaceau-download-models once. The old ~/.pyfaceau/weights folder is
no longer used and can be deleted. If you used the automatic download of
earlier versions, you may now see values for AU05, AU09, AU14 and AU20, which
that download did not include.
Install from GitHub (for development)
git clone https://github.com/johnwilsoniv/pyfaceau.git
cd pyfaceau
conda create -n pyfaceau python=3.11
conda activate pyfaceau
pip install -e .
pyfaceau-download-models
The repository does not contain model files either.
Quick Start
From a terminal
pyfaceau input.mp4
This measures the 17 action units in every frame of input.mp4 and saves them
in input.csv, in the folder you are in (see Output Format).
To choose the file name, add -o:
pyfaceau input.mp4 -o results.csv
If you see "command not found", type python -m pyfaceau input.mp4 instead.
With a window
pyfaceau-gui
opens a small window: add your videos, choose a folder for the results and
click Process Videos. You get one CSV file per video. (If you see "command
not found", type python -m pyfaceau.gui instead.)
Video Processing in Python
from pyfaceau import OpenFaceProcessor
# Initialize processor
processor = OpenFaceProcessor(verbose=True)
# Process the video and save the AU values as a CSV file (see Output Format)
processor.process_video("input.mp4", "output.csv")
Batch Processing
from pyfaceau import process_videos
# Process all videos in a directory
process_videos(
directory_path="/path/to/videos",
output_dir="/path/to/output"
)
Frame-by-Frame Processing
from pyfaceau import FullPythonAUPipeline
import cv2
# Initialize pipeline (model files come from the folder installed by
# `pyfaceau-download-models`; you can also pass pdm_file=, au_models_dir=,
# triangulation_file= and patch_expert_file= yourself)
pipeline = FullPythonAUPipeline()
# Process single frame
image = cv2.imread("face.jpg")
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
result = pipeline.process_frame(image_rgb, frame_num=0)
if result['success']:
print("AU intensities:", result['au_intensities'])
print("Landmarks shape:", result['landmarks_2d'].shape) # (68, 2)
print("Pose (pitch, yaw, roll):", result['pose'])
Output Format
CSV Output Columns
The CSV file has one row per video frame and these columns:
frame- Frame number, starting at 0timestamp- Time of the frame in secondssuccess-Trueif a face was found and measured in this frame,Falseif notAU01_r,AU02_r, ...AU45_r- the intensities of the 17 action units listed below, from 0 (absent) to 5 (maximum). Use them only in rows wheresuccessisTrue; in the other rows they are empty or not meaningful.
These are the AU intensity columns of OpenFace's output (OpenFace's own CSV has more columns, such as landmarks and head pose, which pyfaceau does not write).
Action Units
17 facial action units with intensity values (0.0 - 5.0):
| AU | Description |
|---|---|
| AU01 | Inner Brow Raiser |
| AU02 | Outer Brow Raiser |
| AU04 | Brow Lowerer |
| AU05 | Upper Lid Raiser |
| AU06 | Cheek Raiser |
| AU07 | Lid Tightener |
| AU09 | Nose Wrinkler |
| AU10 | Upper Lip Raiser |
| AU12 | Lip Corner Puller |
| AU14 | Dimpler |
| AU15 | Lip Corner Depressor |
| AU17 | Chin Raiser |
| AU20 | Lip Stretcher |
| AU23 | Lip Tightener |
| AU25 | Lips Part |
| AU26 | Jaw Drop |
| AU45 | Blink |
Accuracy
Validated against C++ OpenFace 2.2
| Metric | Correlation |
|---|---|
| Overall Mean | r = 0.97 |
| Overall Median | r = 0.996 |
| Static AUs | r = 0.98 |
| Dynamic AUs | r = 0.96 |
Per-AU correlations:
- AU01: 0.997, AU02: 0.999, AU04: 0.989, AU05: 0.999
- AU06: 0.999, AU07: 0.996, AU09: 0.997, AU10: 0.994
- AU12: 0.998, AU14: 0.974, AU15: 0.893, AU17: 0.948
- AU20: 0.817, AU23: 0.996, AU25: 0.984, AU26: 0.902, AU45: 0.998
Requirements
- Python 3.10-3.12 (3.10 recommended; newer versions lack prebuilt wheels)
- numpy
- opencv-python 4 (installed automatically). pyfaceau stays on OpenCV 4 on purpose: OpenCV 5 resamples images slightly differently, which changes the AU values (see the changelog).
- torch
- scipy
Acknowledgments
Based on OpenFace 2.2:
Baltrusaitis, T., Zadeh, A., Lim, Y. C., & Morency, L. P. (2018). OpenFace 2.0: Facial Behavior Analysis Toolkit. IEEE International Conference on Automatic Face and Gesture Recognition.
Citation
If you use this in research, please cite:
Wilson IV, J., Rosenberg, J., Gray, M. L., & Razavi, C. R. (2025). A split-face computer vision/machine learning assessment of facial paralysis using facial action units. Facial Plastic Surgery & Aesthetic Medicine. https://doi.org/10.1177/26893614251394382
License
pyfaceau's code: CC BY-NC 4.0 - free for non-commercial use with attribution (see LICENSE).
OpenFace model files: not included in pyfaceau. pyfaceau-download-models
downloads them from OpenFace after you accept the
OpenFace license
(academic or non-profit, non-commercial research only; do not share the files).
For commercial use, contact Carnegie Mellon University.
Metadata
Release files for pyfaceau 1.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyfaceau-1.4.1.tar.gz | 535.7 kB | Without provenance | Details for pyfaceau-1.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyfaceau-1.4.1-cp310-cp310-macosx_10_9_universal2.whl | CPython 3.10 | CPython 3.10 | macOS 10.9+ universal2 (ARM64, x86-64) | Details for pyfaceau-1.4.1-cp310-cp310-macosx_10_9_universal2.whl |
Total release size: 1.5 MB
Release files / pyfaceau-1.4.1.tar.gz
| Download URL | pyfaceau-1.4.1.tar.gz |
|---|---|
| Size | 535.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b91721dfa66d7a06b5ead3720fae57bae94a0eb2dfc6241f297d8ee47d701282
|
|
BLAKE2b-256 checksum How to use checksums |
93738186bd51e839788e16819a7187555492c2b95c8c464b80985c50776abe18
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / pyfaceau-1.4.1-cp310-cp310-macosx_10_9_universal2.whl
| Download URL | pyfaceau-1.4.1-cp310-cp310-macosx_10_9_universal2.whl |
|---|---|
| Size | 935.8 kB |
| Tags | CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
5990fd10020aacc74ab32d3fc53010a2200b1ae70532b17862f1ec18aa713d22
|
|
BLAKE2b-256 checksum How to use checksums |
baa5da6f894a71eba736e1d1f2f737987fe68cbd31cfde717f2dd37b8d9f309f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Security for pyfaceau 1.4.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.