How gvclab/personalive works
Purpose and Entry Points
PersonaLive is a PyTorch diffusion system for real-time, streamable portrait animation: a reference image is animated by motion from a driving video or webcam. Batch and live entry points are inference_offline.py and inference_online.py; the latter serves a browser UI at port 7860. Training is explicitly staged through train_stage1.py, train_stage2.py, and train_stage3.py.
Inference Orchestration
Offline inference consumes a reference image plus driving video, with optional long-video streaming generation and xFormers attention. Live inference selects normal, xFormers, or TensorRT execution. Configuration separates stage 1/2 inference from stage 3 temporal streaming:
• inference_offline.py
• inference_online.py
• configs/inference/inference_stage1&2.yaml
• configs/inference/inference_stage3.yaml
Animation Pipeline
The central boundary is motion extraction versus diffusion synthesis. LivePortrait-derived components derive facial motion/camera signals from driving frames; pose conditioning and motion features then drive reference-conditioned image/video diffusion pipelines.
• src/liveportrait/motion_extractor.py
• src/models/pose_guider.py
• src/pipelines/pipeline_pose2img.py
• src/pipelines/pipeline_pose2vid.py
Diffusion and Temporal Model Stack
Reference appearance is represented through a reference UNet/attention path, while denoising uses customized 2D/3D UNets. The video path adds temporal modules and explicit reference handling to preserve identity and continuity over generated frame windows. DDIM controls the iterative denoising schedule.
• src/models/unet_2d_condition.py
• src/models/unet_3d_explicit_reference.py
• src/models/motion_module.py
• src/scheduler/scheduler_ddim.py
Runtime Wrappers and Acceleration
The wrapper layer packages model loading and inference execution. Standard execution is CUDA/PyTorch; ONNX export and TensorRT provide an optimized UNet path, with a locally built engine expected for hardware compatibility. Pretrained PersonaLive, Stable Diffusion VAE/image-variation, ONNX, and TensorRT artifacts are external runtime inputs under pretrained_weights/.
• src/wrapper.py
• src/wrapper_trt.py
• src/modeling/onnx_export.py
• torch2trt.py
Live Streaming Interface
The online path bridges webcam/video capture, frame-by-frame animation, and browser transport. Python live-video workers have standard and TensorRT variants; a Svelte frontend supplies image/video inputs, controls, logging, and rendered-frame playback. This is a local streaming application rather than a hosted backend integration.
• webcam/vid2vid.py
• webcam/vid2vid_trt.py
• webcam/connection_manager.py
• webcam/frontend/src/routes/+page.svelte
Training and Data Flow
Training progresses from image-level warm-up, to adversarial image refinement using StyleGAN2 discrimination, to temporal-module fine-tuning for streamable video. Video datasets require aligned face/eye/mouth box artifacts; portrait dataset loaders and augmentation feed stage-specific configs. Stages consume predecessor checkpoints, making checkpoint paths the handoff boundary.
• train_stage1.py
• train_stage2.py
• train_stage3.py
• src/dataset/portrait_video.py
• src/stylegan2/discriminator.py
• configs/train/personalive_stage3.yaml
Main entry points: pipeline_pose2vid.py Pose-to-video pipeline · pipeline_pose2img.py Pose-to-image pipeline · train_stage2.py Stage 2 training · train_stage3.py Stage 3 training
Components 26
Inference & Streaming
- Offline inference · Animates a reference image from a driving video.
inference_offline.py - Online inference · Serves the local browser UI on port 7860.
inference_online.py - Inference configs · Separates image stages from temporal streaming.
configs/inference/inference_stage1&2.yaml - Streaming config
configs/inference/inference_stage3.yaml - Live video worker · Captures and animates video frames.
webcam/vid2vid.py - TensorRT live worker
webcam/vid2vid_trt.py - Browser transport · Moves rendered frames to the local client.
webcam/connection_manager.py - Svelte frontend · Provides inputs, controls, logs, and playback.
webcam/frontend/src/routes/+page.svelte
Animation & Diffusion
- Motion extractor · Derives facial motion and camera signals from driving frames.
src/liveportrait/motion_extractor.py - Pose guider · Converts extracted motion into diffusion conditioning.
src/models/pose_guider.py - Pose-to-image pipeline · Generates reference-conditioned portrait frames.
src/pipelines/pipeline_pose2img.py - Pose-to-video pipeline · Generates temporal frame windows with explicit reference handling.
src/pipelines/pipeline_pose2vid.py - 2D conditioning UNet · Image-stage diffusion denoiser.
src/models/unet_2d_condition.py - 3D reference UNet · Video denoiser with explicit reference conditioning.
src/models/unet_3d_explicit_reference.py - Temporal modules · Adds continuity across generated video windows.
src/models/motion_module.py - DDIM scheduler · Controls iterative denoising.
src/scheduler/scheduler_ddim.py
Runtime Acceleration
- PyTorch wrapper · Packages model loading and CUDA/PyTorch execution.
src/wrapper.py - TensorRT wrapper · Runs the optimized UNet execution path.
src/wrapper_trt.py - ONNX export · Exports the optimized UNet path for TensorRT.
src/modeling/onnx_export.py - TensorRT engine builder · Builds hardware-compatible local engines.
torch2trt.py
Training
- Stage 1 training
train_stage1.py - Stage 2 training · Refines images with adversarial training.
train_stage2.py - Stage 3 training · Fine-tunes streamable video temporal modules.
train_stage3.py - Portrait video dataset · Consumes portrait video and aligned facial-region artifacts.
src/dataset/portrait_video.py - StyleGAN2 discriminator
src/stylegan2/discriminator.py - Stage 3 config
configs/train/personalive_stage3.yaml
Connections 29
- Offline inference → Inference configs: loads
- Offline inference → Streaming config: uses for streaming
- Online inference → Live video worker: starts
- Online inference → TensorRT live worker: selects when optimized
- Svelte frontend → Browser transport: browser stream
- Browser transport → Live video worker: frames
- Live video worker → Motion extractor: driving frames
- Motion extractor → Pose guider: motion and camera
- Pose guider → Pose-to-image pipeline: pose conditioning
- Pose guider → Pose-to-video pipeline: pose conditioning
- Pose-to-image pipeline → 2D conditioning UNet: denoises with
- Pose-to-video pipeline → 3D reference UNet: denoises with
- Temporal modules → 3D reference UNet: temporal layers
- DDIM scheduler → Pose-to-image pipeline: sampling schedule
- DDIM scheduler → Pose-to-video pipeline: sampling schedule
- PyTorch wrapper → Pose-to-image pipeline: runs
- PyTorch wrapper → Pose-to-video pipeline: runs
- TensorRT live worker → TensorRT wrapper: uses
- TensorRT wrapper → Pose-to-video pipeline: optimized execution
- ONNX export → TensorRT engine builder: exported model
- TensorRT engine builder → TensorRT wrapper: engine
- Portrait video dataset → Stage 1 training: training data
- Stage 1 training → Stage 2 training: checkpoint handoff
- Portrait video dataset → Stage 2 training: training data
- StyleGAN2 discriminator → Stage 2 training: adversarial supervision
- Stage 2 training → Stage 3 training: checkpoint handoff
- Portrait video dataset → Stage 3 training: video training data
- Stage 3 config → Stage 3 training: configures
- Stage 3 training → Temporal modules: fine-tunes