CPU neural talking-head synthesis (offline). LivePortrait architecture with MediaPipe face detection.
Guido Batan | Software Systems Architect (AI/ML)
This project is part of a portfolio demonstrating software architecture and AI/ML systems design. See guidobatan.com for more.
- Apache 2.0 Licensed — commercial-friendly, redistribution permitted
- CPU-First Design — runs on CPU; GPU optional for acceleration
- No External Model Downloads for Face Detection — MediaPipe models bundled via pip
- Five-stage LivePortrait pipeline (F → M → W → G → S) fully integrated
- Strict ONNX shape/dtype contract validation at startup
- 3-thread async pipeline (Capture → Motion → Render) with last-state-wins scheduling
Face Detection: MediaPipe FaceDetector (Apache 2.0) Appearance Encoder: LivePortrait appearance_feature_extractor.onnx Motion Pipeline: LivePortrait motion_extractor.onnx + warping.onnx + spade_generator.onnx + stitching_retargeting.onnx
Derived from KwaiVGI/LivePortrait (MIT). See NOTICE.md for full attribution.
The project is dependency-locked via requirements.lock (generated with
uv pip compile pyproject.toml). Install from the lockfile for byte-for-byte
reproducibility, then add the package itself in editable mode.
uv venv --python 3.11
source .venv/bin/activate # Windows: .venv\Scripts\Activate.ps1
uv pip sync requirements.lock
uv pip install -e ".[dev]" --no-depspython -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\Activate.ps1
pip install -r requirements.lock
pip install -e ".[dev]" --no-depsThe --no-deps flag is intentional: dependency resolution belongs to the
lockfile, not to pyproject.toml. This is the same flow used in CI
(.github/workflows/tests.yml).
Note on
uv run. Avoiduv run pytestfor this project.uv runresolves an isolated environment frompyproject.toml(without the lockfile), which can pull different transitive versions and trigger re-downloads of large packages such asmediapipe. Activate.venvand invoke tools directly.
Source: LivePortrait ONNX (HuggingFace)
Download the following models into models/face/:
appearance_feature_extractor.onnxmotion_extractor.onnxwarping.onnxspade_generator.onnxstitching_retargeting.onnx
Do not rename files. The engine expects these exact filenames for session resolution.
| Pipeline stage | File |
|---|---|
| F - appearance | appearance_feature_extractor.onnx |
| M - motion | motion_extractor.onnx |
| W - warping | warping.onnx |
| G - generator | spade_generator.onnx |
| S - stitching | stitching_retargeting.onnx |
Full ONNX I/O contracts:
python scripts/print_model_contracts.py # prints to stdout; no downloadpython -m nsr_engine --avatar assets/avatar.png --debugThe engine workflow:
- Initializes MediaPipe face detector and five ONNX sessions.
- Validates session arity and shape contracts against specifications.
- Computes and freezes avatar appearance features and source latents.
- Orchestrates the 3-thread asynchronous pipeline (Capture → Motion → Render).
After installation (with .venv active):
ruff check .
mypy src/
pytest tests/ -vTwo execution modes:
- Skeleton mode (default): one or more of the five LivePortrait ONNX
files are missing from
models/face/. Tests markedrequires_onnxare skipped; data-contract, wiring, and shape-assertion tests run unconditionally. - Integrated mode: all five ONNX files present. Regression tests (identity preservation, temporal stability, responsiveness) activate.
Detection is conservative — partial presence fails closed (skeleton).
docs/ARCHITECTURE.md: Data flow, concurrency model, and I/O contracts.docs/VALIDATION_SUMMARY.md: Test suite coverage and inference verification.CHANGELOG.md: Version history.
Licensed under Apache License 2.0. See LICENSE for details.
This project is a derivative of KwaiVGI/LivePortrait (MIT License). See NOTICE.md and THIRD_PARTY_LICENSES.md for full attribution.