LivePortrait Documentation

Python library by @KlingAIResearch focused on face-animation, image-animation, video-editing. Includes documentation and AI agent context with 18k stars.

18,299 stars Python Python 1 file Β· ~17,147 tokens #face-animation#image-animation#video-editing#video-generation
RAW Doc

File: README.md

LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control

πŸ”₯ Updates

  • 2025/06/01: 🌍 Over the past year, LivePortrait has πŸš€ become an efficient portrait-animation (humans, cats and dogs) solution adopted by major video platformsβ€”Kuaishou, Douyin, Jianying, WeChat Channelsβ€”as well as numerous startups and creators. πŸŽ‰
  • 2025/01/01: 🐢 We updated a new version of the Animals model with more data, see here.
  • 2024/10/18: ❗ We have updated the versions of the transformers and gradio libraries to avoid security vulnerabilities. Details here.
  • 2024/08/29: πŸ“¦ We update the Windows one-click installer and support auto-updates, see changelog.
  • 2024/08/19: πŸ–ΌοΈ We support image driven mode and regional control. For details, see here.
  • 2024/08/06: 🎨 We support precise portrait editing in the Gradio interface, inspired by ComfyUI-AdvancedLivePortrait. See here.
  • 2024/08/05: πŸ“¦ Windows users can now download the one-click installer for Humans mode and Animals mode now! For details, see here.
  • 2024/08/02: 😸 We released a version of the Animals model, along with several other updates and improvements. Check out the details here!
  • 2024/07/25: πŸ“¦ Windows users can now download the package from HuggingFace. Simply unzip and double-click run_windows.bat to enjoy!
  • 2024/07/24: 🎨 We support pose editing for source portraits in the Gradio interface. We’ve also lowered the default detection threshold to increase recall. Have fun!
  • 2024/07/19: ✨ We support 🎞️ portrait video editing (aka v2v)! More to see here.
  • 2024/07/17: 🍎 We support macOS with Apple Silicon, modified from jeethu's PR #143.
  • 2024/07/10: πŸ’ͺ We support audio and video concatenating, driving video auto-cropping, and template making to protect privacy. More to see here.
  • 2024/07/09: πŸ€— We released the HuggingFace Space, thanks to the HF team and Gradio!
  • 2024/07/04: 😊 We released the initial version of the inference code and models. Continuous updates, stay tuned!
  • 2024/07/04: πŸ”₯ We released the homepage and technical report on arXiv.

Introduction πŸ“–

This repo, named LivePortrait, contains the official PyTorch implementation of our paper LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control.
We are actively updating and improving this repository. If you find any bugs or have suggestions, welcome to raise issues or submit pull requests (PR) πŸ’–.

Getting Started 🏁

1. Clone the code and prepare the environment πŸ› οΈ

[!Note]
Make sure your system has git, conda, and FFmpeg installed. For details on FFmpeg installation, see how to install FFmpeg.

bash
git clone https://github.com/KlingTeam/LivePortrait
cd LivePortrait

# create env using conda
conda create -n LivePortrait python=3.10
conda activate LivePortrait

For Linux 🐧 or Windows πŸͺŸ Users

X-Pose, required by Animals mode, is a dependency that needs to be installed. The step of Check your CUDA versions is optional if you only want to run Humans mode.

Check your CUDA versions

Firstly, check your current CUDA version by:

bash
nvcc -V # example versions: 11.1, 11.8, 12.1, etc.

Then, install the corresponding torch version. Here are examples for different CUDA versions. Visit the PyTorch Official Website for installation commands if your CUDA version is not listed:

bash
# for CUDA 11.1
pip install torch==1.10.1+cu111 torchvision==0.11.2 torchaudio==0.10.1 -f https://download.pytorch.org/whl/cu111/torch_stable.html
# for CUDA 11.8
pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu118
# for CUDA 12.1
pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu121
# ...

Note: On Windows systems, some higher versions of CUDA (such as 12.4, 12.6, etc.) may lead to unknown issues. You may consider downgrading CUDA to version 11.8 for stability. See the downgrade guide by @dimitribarbot.

Finally, install the remaining dependencies:

bash
pip install -r requirements.txt

For macOS ο£Ώ with Apple Silicon Users

The X-Pose dependency does not support macOS, so you can skip its installation. While Humans mode works as usual, Animals mode is not supported. Use the provided requirements file for macOS with Apple Silicon:

bash
# for macOS with Apple Silicon users
pip install -r requirements_macOS.txt

2. Download pretrained weights πŸ“₯

The easiest way to download the pretrained weights is from HuggingFace:

bash
# !pip install -U "huggingface_hub[cli]"
huggingface-cli download KlingTeam/LivePortrait --local-dir pretrained_weights --exclude "*.git*" "README.md" "docs"

If you cannot access to Huggingface, you can use hf-mirror to download:

bash
# !pip install -U "huggingface_hub[cli]"
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download KlingTeam/LivePortrait --local-dir pretrained_weights --exclude "*.git*" "README.md" "docs"

Alternatively, you can download all pretrained weights from Google Drive or Baidu Yun. Unzip and place them in ./pretrained_weights.

Ensuring the directory structure is as or contains this.

3. Inference πŸš€

Fast hands-on (humans) πŸ‘€

bash
# For Linux and Windows users
python inference.py

# For macOS users with Apple Silicon (Intel is not tested). NOTE: this maybe 20x slower than RTX 4090
PYTORCH_ENABLE_MPS_FALLBACK=1 python inference.py

If the script runs successfully, you will get an output mp4 file named animations/s6--d0_concat.mp4. This file includes the following results: driving video, input image or video, and generated result.

Or, you can change the input by specifying the -s and -d arguments:

bash
# source input is an image
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d0.mp4

# source input is a video ✨
python inference.py -s assets/examples/source/s13.mp4 -d assets/examples/driving/d0.mp4

# more options to see
python inference.py -h

Fast hands-on (animals) 🐱🐢

Animals mode is ONLY tested on Linux and Windows with NVIDIA GPU.

You need to build an OP named MultiScaleDeformableAttention first (refer to the Check your CUDA versions if needed), which is used by X-Pose, a general keypoint detection framework.

bash
cd src/utils/dependencies/XPose/models/UniPose/ops
python setup.py build install
cd - # equal to cd ../../../../../../../

Then

bash
python inference_animals.py -s assets/examples/source/s39.jpg -d assets/examples/driving/wink.pkl --driving_multiplier 1.75 --no_flag_stitching

If the script runs successfully, you will get an output mp4 file named animations/s39--wink_concat.mp4.

Driving video auto-cropping πŸ“’πŸ“’πŸ“’

[!IMPORTANT]
To use your own driving video, we recommend: ⬇️

  • Crop it to a 1:1 aspect ratio (e.g., 512x512 or 256x256 pixels), or enable auto-cropping by --flag_crop_driving_video.
  • Focus on the head area, similar to the example videos.
  • Minimize shoulder movement.
  • Make sure the first frame of driving video is a frontal face with neutral expression.

Below is an auto-cropping case by --flag_crop_driving_video:

bash
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d13.mp4 --flag_crop_driving_video

If you find the results of auto-cropping is not well, you can modify the --scale_crop_driving_video, --vy_ratio_crop_driving_video options to adjust the scale and offset, or do it manually.

Motion template making

You can also use the auto-generated motion template files ending with .pkl to speed up inference, and protect privacy, such as:

bash
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d5.pkl # portrait animation
python inference.py -s assets/examples/source/s13.mp4 -d assets/examples/driving/d5.pkl # portrait video editing

4. Gradio interface πŸ€—

We also provide a Gradio interface for a better experience, just run by:

bash
# For Linux and Windows users (and macOS with Intel??)
python app.py # humans mode

# For macOS with Apple Silicon users, Intel not supported, this maybe 20x slower than RTX 4090
PYTORCH_ENABLE_MPS_FALLBACK=1 python app.py # humans mode

We also provide a Gradio interface of animals mode, which is only tested on Linux with NVIDIA GPU:

bash
python app_animals.py # animals mode 🐱🐢

You can specify the --server_port, --share, --server_name arguments to satisfy your needs!

πŸš€ We also provide an acceleration option --flag_do_torch_compile. The first-time inference triggers an optimization process (about one minute), making subsequent inferences 20-30% faster. Performance gains may vary with different CUDA versions.

bash
# enable torch.compile for faster inference
python app.py --flag_do_torch_compile

Note: This method is not supported on Windows and macOS.

Or, try it out effortlessly on HuggingFace πŸ€—

5. Inference speed evaluation πŸš€πŸš€πŸš€

We have also provided a script to evaluate the inference speed of each module:

bash
# For NVIDIA GPU
python speed.py

The results are here.

Community Resources πŸ€—

Discover the invaluable resources contributed by our community to enhance your LivePortrait experience.

Community-developed Projects

Repo Description Author / Links
AVTR-1 Real-time conversational talking-head model using dyadic audio conditioning and a LivePortrait-style portrait-warping renderer. @avaturn-live
ditto-talkinghead Real-time audio-driven talking head. ArXiv, Homepage
FasterLivePortrait Faster real-time version using TensorRT. @warmshao
AdvancedLivePortrait-WebUI Dedicated gradio based WebUI started from ComfyUI-AdvancedLivePortrait. @jhj0517
FacePoke A real-time head transformation app, controlled by your mouse! @jbilcke-hf
FaceFusion FaceFusion 3.0 integregates LivePortrait as expression_restorer and face_editor processors. @henryruhs
sd-webui-live-portrait WebUI extension of LivePortrait, adding atab to the original Stable Diffusion WebUI to benefit from LivePortrait features. @dimitribarbot
ComfyUI-LivePortraitKJ A ComfyUI node to use LivePortrait, with MediaPipe as as an alternative to Insightface. @kijai
ComfyUI-AdvancedLivePortrait A faster ComfyUI node with real-time preview that has inspired many other community-developed tools and projects. @PowerHouseMan
comfyui-liveportrait A ComfyUI node to use LivePortrait, supporting multi-faces, expression interpolation etc, with a tutorial. @shadowcz007

Playgrounds, πŸ€— HuggingFace Spaces and Others

Video Tutorials

And so MANY amazing contributions from our community, too many to list them all πŸ’–

Acknowledgements πŸ’

We would like to thank the contributors of FOMM, Open Facevid2vid, SPADE, InsightFace and X-Pose repositories, for their open research and contributions.

Ethics Considerations πŸ›‘οΈ

Portrait animation technologies come with social risks, particularly the potential for misuse in creating deepfakes. To mitigate these risks, it’s crucial to follow ethical guidelines and adopt responsible usage practices. At present, the synthesized results contain visual artifacts that may help in detecting deepfakes. Please note that we do not assume any legal responsibility for the use of the results generated by this project.

Citation πŸ’–

If you find LivePortrait useful for your project or research, welcome to 🌟 this repo and cite our work using the following BibTeX:

bibtex
@article{guo2024liveportrait,
  title   = {LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control},
  author  = {Guo, Jianzhu and Zhang, Dingyun and Liu, Xiaoqiang and Zhong, Zhizhou and Zhang, Yuan and Wan, Pengfei and Zhang, Di},
  journal = {arXiv preprint arXiv:2407.03168},
  year    = {2024}
}

Long live in arXiv.

Contact πŸ“§

Jianzhu Guo (郭建珠); [email protected]

Star History 🌟

Click to view Star chart


File: Readme.md

LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control

πŸ”₯ Updates

  • 2025/06/01: 🌍 Over the past year, LivePortrait has πŸš€ become an efficient portrait-animation (humans, cats and dogs) solution adopted by major video platformsβ€”Kuaishou, Douyin, Jianying, WeChat Channelsβ€”as well as numerous startups and creators. πŸŽ‰
  • 2025/01/01: 🐢 We updated a new version of the Animals model with more data, see here.
  • 2024/10/18: ❗ We have updated the versions of the transformers and gradio libraries to avoid security vulnerabilities. Details here.
  • 2024/08/29: πŸ“¦ We update the Windows one-click installer and support auto-updates, see changelog.
  • 2024/08/19: πŸ–ΌοΈ We support image driven mode and regional control. For details, see here.
  • 2024/08/06: 🎨 We support precise portrait editing in the Gradio interface, inspired by ComfyUI-AdvancedLivePortrait. See here.
  • 2024/08/05: πŸ“¦ Windows users can now download the one-click installer for Humans mode and Animals mode now! For details, see here.
  • 2024/08/02: 😸 We released a version of the Animals model, along with several other updates and improvements. Check out the details here!
  • 2024/07/25: πŸ“¦ Windows users can now download the package from HuggingFace. Simply unzip and double-click run_windows.bat to enjoy!
  • 2024/07/24: 🎨 We support pose editing for source portraits in the Gradio interface. We’ve also lowered the default detection threshold to increase recall. Have fun!
  • 2024/07/19: ✨ We support 🎞️ portrait video editing (aka v2v)! More to see here.
  • 2024/07/17: 🍎 We support macOS with Apple Silicon, modified from jeethu's PR #143.
  • 2024/07/10: πŸ’ͺ We support audio and video concatenating, driving video auto-cropping, and template making to protect privacy. More to see here.
  • 2024/07/09: πŸ€— We released the HuggingFace Space, thanks to the HF team and Gradio!
  • 2024/07/04: 😊 We released the initial version of the inference code and models. Continuous updates, stay tuned!
  • 2024/07/04: πŸ”₯ We released the homepage and technical report on arXiv.

Introduction πŸ“–

This repo, named LivePortrait, contains the official PyTorch implementation of our paper LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control.
We are actively updating and improving this repository. If you find any bugs or have suggestions, welcome to raise issues or submit pull requests (PR) πŸ’–.

Getting Started 🏁

1. Clone the code and prepare the environment πŸ› οΈ

[!Note]
Make sure your system has git, conda, and FFmpeg installed. For details on FFmpeg installation, see how to install FFmpeg.

bash
git clone https://github.com/KlingTeam/LivePortrait
cd LivePortrait

# create env using conda
conda create -n LivePortrait python=3.10
conda activate LivePortrait

For Linux 🐧 or Windows πŸͺŸ Users

X-Pose, required by Animals mode, is a dependency that needs to be installed. The step of Check your CUDA versions is optional if you only want to run Humans mode.

Check your CUDA versions

Firstly, check your current CUDA version by:

bash
nvcc -V # example versions: 11.1, 11.8, 12.1, etc.

Then, install the corresponding torch version. Here are examples for different CUDA versions. Visit the PyTorch Official Website for installation commands if your CUDA version is not listed:

bash
# for CUDA 11.1
pip install torch==1.10.1+cu111 torchvision==0.11.2 torchaudio==0.10.1 -f https://download.pytorch.org/whl/cu111/torch_stable.html
# for CUDA 11.8
pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu118
# for CUDA 12.1
pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu121
# ...

Note: On Windows systems, some higher versions of CUDA (such as 12.4, 12.6, etc.) may lead to unknown issues. You may consider downgrading CUDA to version 11.8 for stability. See the downgrade guide by @dimitribarbot.

Finally, install the remaining dependencies:

bash
pip install -r requirements.txt

For macOS ο£Ώ with Apple Silicon Users

The X-Pose dependency does not support macOS, so you can skip its installation. While Humans mode works as usual, Animals mode is not supported. Use the provided requirements file for macOS with Apple Silicon:

bash
# for macOS with Apple Silicon users
pip install -r requirements_macOS.txt

2. Download pretrained weights πŸ“₯

The easiest way to download the pretrained weights is from HuggingFace:

bash
# !pip install -U "huggingface_hub[cli]"
huggingface-cli download KlingTeam/LivePortrait --local-dir pretrained_weights --exclude "*.git*" "README.md" "docs"

If you cannot access to Huggingface, you can use hf-mirror to download:

bash
# !pip install -U "huggingface_hub[cli]"
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download KlingTeam/LivePortrait --local-dir pretrained_weights --exclude "*.git*" "README.md" "docs"

Alternatively, you can download all pretrained weights from Google Drive or Baidu Yun. Unzip and place them in ./pretrained_weights.

Ensuring the directory structure is as or contains this.

3. Inference πŸš€

Fast hands-on (humans) πŸ‘€

bash
# For Linux and Windows users
python inference.py

# For macOS users with Apple Silicon (Intel is not tested). NOTE: this maybe 20x slower than RTX 4090
PYTORCH_ENABLE_MPS_FALLBACK=1 python inference.py

If the script runs successfully, you will get an output mp4 file named animations/s6--d0_concat.mp4. This file includes the following results: driving video, input image or video, and generated result.

Or, you can change the input by specifying the -s and -d arguments:

bash
# source input is an image
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d0.mp4

# source input is a video ✨
python inference.py -s assets/examples/source/s13.mp4 -d assets/examples/driving/d0.mp4

# more options to see
python inference.py -h

Fast hands-on (animals) 🐱🐢

Animals mode is ONLY tested on Linux and Windows with NVIDIA GPU.

You need to build an OP named MultiScaleDeformableAttention first (refer to the Check your CUDA versions if needed), which is used by X-Pose, a general keypoint detection framework.

bash
cd src/utils/dependencies/XPose/models/UniPose/ops
python setup.py build install
cd - # equal to cd ../../../../../../../

Then

bash
python inference_animals.py -s assets/examples/source/s39.jpg -d assets/examples/driving/wink.pkl --driving_multiplier 1.75 --no_flag_stitching

If the script runs successfully, you will get an output mp4 file named animations/s39--wink_concat.mp4.

Driving video auto-cropping πŸ“’πŸ“’πŸ“’

[!IMPORTANT]
To use your own driving video, we recommend: ⬇️

  • Crop it to a 1:1 aspect ratio (e.g., 512x512 or 256x256 pixels), or enable auto-cropping by --flag_crop_driving_video.
  • Focus on the head area, similar to the example videos.
  • Minimize shoulder movement.
  • Make sure the first frame of driving video is a frontal face with neutral expression.

Below is an auto-cropping case by --flag_crop_driving_video:

bash
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d13.mp4 --flag_crop_driving_video

If you find the results of auto-cropping is not well, you can modify the --scale_crop_driving_video, --vy_ratio_crop_driving_video options to adjust the scale and offset, or do it manually.

Motion template making

You can also use the auto-generated motion template files ending with .pkl to speed up inference, and protect privacy, such as:

bash
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d5.pkl # portrait animation
python inference.py -s assets/examples/source/s13.mp4 -d assets/examples/driving/d5.pkl # portrait video editing

4. Gradio interface πŸ€—

We also provide a Gradio interface for a better experience, just run by:

bash
# For Linux and Windows users (and macOS with Intel??)
python app.py # humans mode

# For macOS with Apple Silicon users, Intel not supported, this maybe 20x slower than RTX 4090
PYTORCH_ENABLE_MPS_FALLBACK=1 python app.py # humans mode

We also provide a Gradio interface of animals mode, which is only tested on Linux with NVIDIA GPU:

bash
python app_animals.py # animals mode 🐱🐢

You can specify the --server_port, --share, --server_name arguments to satisfy your needs!

πŸš€ We also provide an acceleration option --flag_do_torch_compile. The first-time inference triggers an optimization process (about one minute), making subsequent inferences 20-30% faster. Performance gains may vary with different CUDA versions.

bash
# enable torch.compile for faster inference
python app.py --flag_do_torch_compile

Note: This method is not supported on Windows and macOS.

Or, try it out effortlessly on HuggingFace πŸ€—

5. Inference speed evaluation πŸš€πŸš€πŸš€

We have also provided a script to evaluate the inference speed of each module:

bash
# For NVIDIA GPU
python speed.py

The results are here.

Community Resources πŸ€—

Discover the invaluable resources contributed by our community to enhance your LivePortrait experience.

Community-developed Projects

Repo Description Author / Links
AVTR-1 Real-time conversational talking-head model using dyadic audio conditioning and a LivePortrait-style portrait-warping renderer. @avaturn-live
ditto-talkinghead Real-time audio-driven talking head. ArXiv, Homepage
FasterLivePortrait Faster real-time version using TensorRT. @warmshao
AdvancedLivePortrait-WebUI Dedicated gradio based WebUI started from ComfyUI-AdvancedLivePortrait. @jhj0517
FacePoke A real-time head transformation app, controlled by your mouse! @jbilcke-hf
FaceFusion FaceFusion 3.0 integregates LivePortrait as expression_restorer and face_editor processors. @henryruhs
sd-webui-live-portrait WebUI extension of LivePortrait, adding atab to the original Stable Diffusion WebUI to benefit from LivePortrait features. @dimitribarbot
ComfyUI-LivePortraitKJ A ComfyUI node to use LivePortrait, with MediaPipe as as an alternative to Insightface. @kijai
ComfyUI-AdvancedLivePortrait A faster ComfyUI node with real-time preview that has inspired many other community-developed tools and projects. @PowerHouseMan
comfyui-liveportrait A ComfyUI node to use LivePortrait, supporting multi-faces, expression interpolation etc, with a tutorial. @shadowcz007

Playgrounds, πŸ€— HuggingFace Spaces and Others

Video Tutorials

And so MANY amazing contributions from our community, too many to list them all πŸ’–

Acknowledgements πŸ’

We would like to thank the contributors of FOMM, Open Facevid2vid, SPADE, InsightFace and X-Pose repositories, for their open research and contributions.

Ethics Considerations πŸ›‘οΈ

Portrait animation technologies come with social risks, particularly the potential for misuse in creating deepfakes. To mitigate these risks, it’s crucial to follow ethical guidelines and adopt responsible usage practices. At present, the synthesized results contain visual artifacts that may help in detecting deepfakes. Please note that we do not assume any legal responsibility for the use of the results generated by this project.

Citation πŸ’–

If you find LivePortrait useful for your project or research, welcome to 🌟 this repo and cite our work using the following BibTeX:

bibtex
@article{guo2024liveportrait,
  title   = {LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control},
  author  = {Guo, Jianzhu and Zhang, Dingyun and Liu, Xiaoqiang and Zhong, Zhizhou and Zhang, Yuan and Wan, Pengfei and Zhang, Di},
  journal = {arXiv preprint arXiv:2407.03168},
  year    = {2024}
}

Long live in arXiv.

Contact πŸ“§

Jianzhu Guo (郭建珠); [email protected]

Star History 🌟

Click to view Star chart


File: readme.md

LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control

πŸ”₯ Updates

  • 2025/06/01: 🌍 Over the past year, LivePortrait has πŸš€ become an efficient portrait-animation (humans, cats and dogs) solution adopted by major video platformsβ€”Kuaishou, Douyin, Jianying, WeChat Channelsβ€”as well as numerous startups and creators. πŸŽ‰
  • 2025/01/01: 🐢 We updated a new version of the Animals model with more data, see here.
  • 2024/10/18: ❗ We have updated the versions of the transformers and gradio libraries to avoid security vulnerabilities. Details here.
  • 2024/08/29: πŸ“¦ We update the Windows one-click installer and support auto-updates, see changelog.
  • 2024/08/19: πŸ–ΌοΈ We support image driven mode and regional control. For details, see here.
  • 2024/08/06: 🎨 We support precise portrait editing in the Gradio interface, inspired by ComfyUI-AdvancedLivePortrait. See here.
  • 2024/08/05: πŸ“¦ Windows users can now download the one-click installer for Humans mode and Animals mode now! For details, see here.
  • 2024/08/02: 😸 We released a version of the Animals model, along with several other updates and improvements. Check out the details here!
  • 2024/07/25: πŸ“¦ Windows users can now download the package from HuggingFace. Simply unzip and double-click run_windows.bat to enjoy!
  • 2024/07/24: 🎨 We support pose editing for source portraits in the Gradio interface. We’ve also lowered the default detection threshold to increase recall. Have fun!
  • 2024/07/19: ✨ We support 🎞️ portrait video editing (aka v2v)! More to see here.
  • 2024/07/17: 🍎 We support macOS with Apple Silicon, modified from jeethu's PR #143.
  • 2024/07/10: πŸ’ͺ We support audio and video concatenating, driving video auto-cropping, and template making to protect privacy. More to see here.
  • 2024/07/09: πŸ€— We released the HuggingFace Space, thanks to the HF team and Gradio!
  • 2024/07/04: 😊 We released the initial version of the inference code and models. Continuous updates, stay tuned!
  • 2024/07/04: πŸ”₯ We released the homepage and technical report on arXiv.

Introduction πŸ“–

This repo, named LivePortrait, contains the official PyTorch implementation of our paper LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control.
We are actively updating and improving this repository. If you find any bugs or have suggestions, welcome to raise issues or submit pull requests (PR) πŸ’–.

Getting Started 🏁

1. Clone the code and prepare the environment πŸ› οΈ

[!Note]
Make sure your system has git, conda, and FFmpeg installed. For details on FFmpeg installation, see how to install FFmpeg.

bash
git clone https://github.com/KlingTeam/LivePortrait
cd LivePortrait

# create env using conda
conda create -n LivePortrait python=3.10
conda activate LivePortrait

For Linux 🐧 or Windows πŸͺŸ Users

X-Pose, required by Animals mode, is a dependency that needs to be installed. The step of Check your CUDA versions is optional if you only want to run Humans mode.

Check your CUDA versions

Firstly, check your current CUDA version by:

bash
nvcc -V # example versions: 11.1, 11.8, 12.1, etc.

Then, install the corresponding torch version. Here are examples for different CUDA versions. Visit the PyTorch Official Website for installation commands if your CUDA version is not listed:

bash
# for CUDA 11.1
pip install torch==1.10.1+cu111 torchvision==0.11.2 torchaudio==0.10.1 -f https://download.pytorch.org/whl/cu111/torch_stable.html
# for CUDA 11.8
pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu118
# for CUDA 12.1
pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu121
# ...

Note: On Windows systems, some higher versions of CUDA (such as 12.4, 12.6, etc.) may lead to unknown issues. You may consider downgrading CUDA to version 11.8 for stability. See the downgrade guide by @dimitribarbot.

Finally, install the remaining dependencies:

bash
pip install -r requirements.txt

For macOS ο£Ώ with Apple Silicon Users

The X-Pose dependency does not support macOS, so you can skip its installation. While Humans mode works as usual, Animals mode is not supported. Use the provided requirements file for macOS with Apple Silicon:

bash
# for macOS with Apple Silicon users
pip install -r requirements_macOS.txt

2. Download pretrained weights πŸ“₯

The easiest way to download the pretrained weights is from HuggingFace:

bash
# !pip install -U "huggingface_hub[cli]"
huggingface-cli download KlingTeam/LivePortrait --local-dir pretrained_weights --exclude "*.git*" "README.md" "docs"

If you cannot access to Huggingface, you can use hf-mirror to download:

bash
# !pip install -U "huggingface_hub[cli]"
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download KlingTeam/LivePortrait --local-dir pretrained_weights --exclude "*.git*" "README.md" "docs"

Alternatively, you can download all pretrained weights from Google Drive or Baidu Yun. Unzip and place them in ./pretrained_weights.

Ensuring the directory structure is as or contains this.

3. Inference πŸš€

Fast hands-on (humans) πŸ‘€

bash
# For Linux and Windows users
python inference.py

# For macOS users with Apple Silicon (Intel is not tested). NOTE: this maybe 20x slower than RTX 4090
PYTORCH_ENABLE_MPS_FALLBACK=1 python inference.py

If the script runs successfully, you will get an output mp4 file named animations/s6--d0_concat.mp4. This file includes the following results: driving video, input image or video, and generated result.

Or, you can change the input by specifying the -s and -d arguments:

bash
# source input is an image
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d0.mp4

# source input is a video ✨
python inference.py -s assets/examples/source/s13.mp4 -d assets/examples/driving/d0.mp4

# more options to see
python inference.py -h

Fast hands-on (animals) 🐱🐢

Animals mode is ONLY tested on Linux and Windows with NVIDIA GPU.

You need to build an OP named MultiScaleDeformableAttention first (refer to the Check your CUDA versions if needed), which is used by X-Pose, a general keypoint detection framework.

bash
cd src/utils/dependencies/XPose/models/UniPose/ops
python setup.py build install
cd - # equal to cd ../../../../../../../

Then

bash
python inference_animals.py -s assets/examples/source/s39.jpg -d assets/examples/driving/wink.pkl --driving_multiplier 1.75 --no_flag_stitching

If the script runs successfully, you will get an output mp4 file named animations/s39--wink_concat.mp4.

Driving video auto-cropping πŸ“’πŸ“’πŸ“’

[!IMPORTANT]
To use your own driving video, we recommend: ⬇️

  • Crop it to a 1:1 aspect ratio (e.g., 512x512 or 256x256 pixels), or enable auto-cropping by --flag_crop_driving_video.
  • Focus on the head area, similar to the example videos.
  • Minimize shoulder movement.
  • Make sure the first frame of driving video is a frontal face with neutral expression.

Below is an auto-cropping case by --flag_crop_driving_video:

bash
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d13.mp4 --flag_crop_driving_video

If you find the results of auto-cropping is not well, you can modify the --scale_crop_driving_video, --vy_ratio_crop_driving_video options to adjust the scale and offset, or do it manually.

Motion template making

You can also use the auto-generated motion template files ending with .pkl to speed up inference, and protect privacy, such as:

bash
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d5.pkl # portrait animation
python inference.py -s assets/examples/source/s13.mp4 -d assets/examples/driving/d5.pkl # portrait video editing

4. Gradio interface πŸ€—

We also provide a Gradio interface for a better experience, just run by:

bash
# For Linux and Windows users (and macOS with Intel??)
python app.py # humans mode

# For macOS with Apple Silicon users, Intel not supported, this maybe 20x slower than RTX 4090
PYTORCH_ENABLE_MPS_FALLBACK=1 python app.py # humans mode

We also provide a Gradio interface of animals mode, which is only tested on Linux with NVIDIA GPU:

bash
python app_animals.py # animals mode 🐱🐢

You can specify the --server_port, --share, --server_name arguments to satisfy your needs!

πŸš€ We also provide an acceleration option --flag_do_torch_compile. The first-time inference triggers an optimization process (about one minute), making subsequent inferences 20-30% faster. Performance gains may vary with different CUDA versions.

bash
# enable torch.compile for faster inference
python app.py --flag_do_torch_compile

Note: This method is not supported on Windows and macOS.

Or, try it out effortlessly on HuggingFace πŸ€—

5. Inference speed evaluation πŸš€πŸš€πŸš€

We have also provided a script to evaluate the inference speed of each module:

bash
# For NVIDIA GPU
python speed.py

The results are here.

Community Resources πŸ€—

Discover the invaluable resources contributed by our community to enhance your LivePortrait experience.

Community-developed Projects

Repo Description Author / Links
AVTR-1 Real-time conversational talking-head model using dyadic audio conditioning and a LivePortrait-style portrait-warping renderer. @avaturn-live
ditto-talkinghead Real-time audio-driven talking head. ArXiv, Homepage
FasterLivePortrait Faster real-time version using TensorRT. @warmshao
AdvancedLivePortrait-WebUI Dedicated gradio based WebUI started from ComfyUI-AdvancedLivePortrait. @jhj0517
FacePoke A real-time head transformation app, controlled by your mouse! @jbilcke-hf
FaceFusion FaceFusion 3.0 integregates LivePortrait as expression_restorer and face_editor processors. @henryruhs
sd-webui-live-portrait WebUI extension of LivePortrait, adding atab to the original Stable Diffusion WebUI to benefit from LivePortrait features. @dimitribarbot
ComfyUI-LivePortraitKJ A ComfyUI node to use LivePortrait, with MediaPipe as as an alternative to Insightface. @kijai
ComfyUI-AdvancedLivePortrait A faster ComfyUI node with real-time preview that has inspired many other community-developed tools and projects. @PowerHouseMan
comfyui-liveportrait A ComfyUI node to use LivePortrait, supporting multi-faces, expression interpolation etc, with a tutorial. @shadowcz007

Playgrounds, πŸ€— HuggingFace Spaces and Others

Video Tutorials

And so MANY amazing contributions from our community, too many to list them all πŸ’–

Acknowledgements πŸ’

We would like to thank the contributors of FOMM, Open Facevid2vid, SPADE, InsightFace and X-Pose repositories, for their open research and contributions.

Ethics Considerations πŸ›‘οΈ

Portrait animation technologies come with social risks, particularly the potential for misuse in creating deepfakes. To mitigate these risks, it’s crucial to follow ethical guidelines and adopt responsible usage practices. At present, the synthesized results contain visual artifacts that may help in detecting deepfakes. Please note that we do not assume any legal responsibility for the use of the results generated by this project.

Citation πŸ’–

If you find LivePortrait useful for your project or research, welcome to 🌟 this repo and cite our work using the following BibTeX:

bibtex
@article{guo2024liveportrait,
  title   = {LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control},
  author  = {Guo, Jianzhu and Zhang, Dingyun and Liu, Xiaoqiang and Zhong, Zhizhou and Zhang, Yuan and Wan, Pengfei and Zhang, Di},
  journal = {arXiv preprint arXiv:2407.03168},
  year    = {2024}
}

Long live in arXiv.

Contact πŸ“§

Jianzhu Guo (郭建珠); [email protected]

Star History 🌟

Click to view Star chart


File: assets/docs/changelog/2024-07-10.md

2024/07/10

First, thank you all for your attention, support, sharing, and contributions to LivePortrait! ❀️
The popularity of LivePortrait has exceeded our expectations. If you encounter any issues or other problems and we do not respond promptly, please accept our apologies. We are still actively updating and improving this repository.

Updates

  • **Audio and video concatenating: ** If the driving video contains audio, it will automatically be included in the generated video. Additionally, the generated video will maintain the same FPS as the driving video. If you run LivePortrait on Windows, you need to install ffprobe and ffmpeg exe, see issue #94.

  • **Driving video auto-cropping: ** Implemented automatic cropping for driving videos by tracking facial landmarks and calculating a global cropping box with a 1:1 aspect ratio. Alternatively, you can crop using video editing software or other tools to achieve a 1:1 ratio. Auto-cropping is not enbaled by default, you can specify it by --flag_crop_driving_video.

  • **Motion template making: ** Added the ability to create motion templates to protect privacy. The motion template is a .pkl file that only contains the motions of the driving video. Theoretically, it is impossible to reconstruct the original face from the template. These motion templates can be used to generate videos without needing the original driving video. By default, the motion template will be generated and saved as a .pkl file with the same name as the driving video, e.g., d0.mp4 -> d0.pkl. Once generated, you can specify it using the -d or --driving option.

About driving video

Others

  • If you encounter a black box problem, disable half-precision inference by using --no_flag_use_half_precision, reported by issue #40, #48, #62.

File: assets/docs/changelog/2024-07-19.md

2024/07/19

Once again, we would like to express our heartfelt gratitude for your love, attention, and support for LivePortrait! πŸŽ‰
We are excited to announce the release of an implementation of Portrait Video Editing (aka v2v) today! Special thanks to the hard work of the LivePortrait team: Dingyun Zhang, Zhizhou Zhong, and Jianzhu Guo.

Updates

  • Portrait video editing (v2v): Implemented a version of Portrait Video Editing (aka v2v). Ensure you have pykalman package installed, which has been added in requirements_base.txt. You can specify the source video using the -s or --source option, adjust the temporal smoothness of motion with --driving_smooth_observation_variance, enable head pose motion transfer with --flag_video_editing_head_rotation, and ensure the eye-open scalar of each source frame matches the first source frame before animation with --flag_source_video_eye_retargeting.

  • More options in Gradio: We have upgraded the Gradio interface and added more options. These include Cropping Options for Source Image or Video and Cropping Options for Driving Video, providing greater flexibility and control.

Community Contributions


File: assets/docs/changelog/2024-07-24.md

2024/07/24

Updates

  • Portrait pose editing: You can change the relative pitch, relative yaw, and relative roll in the Gradio interface to adjust the pose of the source portrait.
  • Detection threshold: We have added a --det_thresh argument with a default value of 0.15 to increase recall, meaning more types of faces (e.g., monkeys, human-like) will be detected. You can set it to other values, e.g., 0.5, by using python app.py --det_thresh 0.5.

File: assets/docs/changelog/2024-08-02.md

2024/08/02

Animals Singing Dance Monkey 🎀

πŸŽ‰ We are excited to announce the release of a new version featuring animals mode, along with several other updates. Special thanks to the dedicated efforts of the LivePortrait team. πŸ’ͺ We also provided an one-click installer for Windows users, checkout the details here.

Updates on Animals mode

We are pleased to announce the release of the animals mode, which is fine-tuned on approximately 230K frames of various animals (mostly cats and dogs). The trained weights have been updated in the liveportrait_animals subdirectory, available on HuggingFace or Google Drive. You should download the weights before running. There are two ways to run this mode.

Please note that we have not trained the stitching and retargeting modules for the animals model due to several technical issues. This may be addressed in future updates. Therefore, we recommend disabling stitching by setting the --no_flag_stitching option when running the model. Additionally, paste-back is also not recommended.

Install X-Pose

We have chosen X-Pose as the keypoints detector for animals. This relies on transformers==4.22.0 and pillow>=10.2.0 (which are already updated in requirements.txt) and requires building an OP named MultiScaleDeformableAttention.

Refer to the PyTorch installation for Linux and Windows users.

Next, build the OP MultiScaleDeformableAttention by running:

bash
cd src/utils/dependencies/XPose/models/UniPose/ops
python setup.py build install
cd - # this returns to the previous directory

To run the model, use the inference_animals.py script:

bash
python inference_animals.py -s assets/examples/source/s39.jpg -d assets/examples/driving/wink.pkl --no_flag_stitching --driving_multiplier 1.75

Alternatively, you can use Gradio for a more user-friendly interface. Launch it with:

bash
python app_animals.py # --server_port 8889 --server_name "0.0.0.0" --share

[!WARNING]
X-Pose is only for Non-commercial Scientific Research Purposes, you should remove and replace it with other detectors if you use it for commercial purposes.

Updates on Humans mode

  • Driving Options: We have introduced an expression-friendly driving option to reduce head wobbling, now set as the default. While it may be less effective with large head poses, you can also select the pose-friendly option, which is the same as the previous version. This can be set using --driving_option or selected in the Gradio interface. Additionally, we added a --driving_multiplier option to adjust driving intensity, with a default value of 1, which can also be set in the Gradio interface.

  • Retargeting Video in Gradio: We have implemented a video retargeting feature. You can specify a target lip-open ratio to adjust the mouth movement in the source video. For instance, setting it to 0 will close the mouth in the source video 🀐.

Others

Below are some screenshots of the new features and improvements:

The Gradio Interface of Animals Mode
Driving Options and Multiplier
The Feature of Retargeting Video

File: assets/docs/changelog/2024-08-05.md

One-click Windows Installer

Download the installer from HuggingFace

bash
# !pip install -U "huggingface_hub[cli]"
huggingface-cli download cleardusk/LivePortrait-Windows LivePortrait-Windows-v20240806.zip --local-dir ./

If you cannot access to Huggingface, you can use hf-mirror to download:

bash
# !pip install -U "huggingface_hub[cli]"
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download cleardusk/LivePortrait-Windows LivePortrait-Windows-v20240806.zip --local-dir ./

Alternatively, you can manually download it from the HuggingFace page.

Then, simply unzip the package LivePortrait-Windows-v20240806.zip and double-click run_windows_human.bat for the Humans mode, or run_windows_animal.bat for the Animals mode.


File: assets/docs/changelog/2024-08-06.md

Precise Portrait Editing

Inspired by ComfyUI-AdvancedLivePortrait (@PowerHouseMan), we have implemented a version of Precise Portrait Editing in the Gradio interface. With each adjustment of the slider, the edited image updates in real-time. You can click the πŸ”„ Reset button to reset all slider parameters. However, the performance may not be as fast as the ComfyUI plugin.


File: assets/docs/changelog/2024-08-19.md

Image Driven and Regional Control

You can now use an image as a driving signal to drive the source image or video! Additionally, we have refined the driving options to support expressions, pose, lips, eyes, or all (all is consistent with the previous default method), which we name it regional control. The control is becoming more and more precise! 🎯

Please note that image-based driving or regional control may not perform well in certain cases. Feel free to try different options, and be patient. 😊

[!Note]
We recognize that the project now offers more options, which have become increasingly complex, but due to our limited team capacity and resources, we haven’t fully documented them yet. We ask for your understanding and will work to improve the documentation over time. Contributions via PRs are welcome! If anyone is considering donating or sponsoring, feel free to leave a message in the GitHub Issues or Discussions. We will set up a payment account to reward the team members or support additional efforts in maintaining the project. πŸ’–

CLI Usage

It's very simple to use an image as a driving reference. Just set the -d argument to the driving image:

bash
python inference.py -s assets/examples/source/s5.jpg -d assets/examples/driving/d30.jpg

To change the animation_region option, you can use the --animation_region argument to exp, pose, lip, eyes, or all. For example, to only drive the lip region, you can run by:

bash
# only driving the lip region
python inference.py -s assets/examples/source/s5.jpg -d assets/examples/driving/d0.mp4 --animation_region lip

Gradio Interface

More Detailed Explanation

flag_relative_motion:
When using an image as the driving input, setting --flag_relative_motion to true will apply the motion deformation between the driving image and its canonical form. If set to false, the absolute motion of the driving image is used, which may amplify expression driving strength but could also cause identity leakage. This option corresponds to the relative motion toggle in the Gradio interface. Additionally, if both source and driving inputs are images, the output will be an image. If the source is a video and the driving input is an image, the output will be a video, with each frame driven by the image's motion. The Gradio interface automatically saves and displays the output in the appropriate format.

animation_region:
This argument offers five options:

  • exp: Only the expression of the driving input influences the source.
  • pose: Only the head pose drives the source.
  • lip: Only lip movement drives the source.
  • eyes: Only eye movement drives the source.
  • all: All motions from the driving input are applied.

You can also select these options directly in the Gradio interface.

Editing the Lip Region of the Source Video to a Neutral Expression:
In response to requests for a more neutral lip region in the Retargeting Video of the Gradio interface, we've added a keeping the lip silent option. When selected, the animated video's lip region will adopt a neutral expression. However, this may cause inter-frame jitter or identity leakage, as it uses a mode similar to absolute driving. Note that the neutral expression may sometimes feature a slightly open mouth.

Others:
When both source and driving inputs are videos, the output motion may be a blend of both, due to the default setting of --flag_relative_motion. This option uses relative driving, where the motion offset of the current driving frame relative to the first driving frame is added to the source frame's motion. In contrast, --no_flag_relative_motion applies the driving frame's motion directly as the final driving motion.

For CLI usage, to retain only the driving video's motion in the output, use:

bash
python inference.py --no_flag_relative_motion

In the Gradio interface, simply uncheck the relative motion option. Note that absolute driving may cause jitter or identity leakage in the animated video.


File: assets/docs/changelog/2025-01-01.md

2025/01/01

We’re thrilled that cats 🐱 are now speaking and singing across the internet! 🎢

In this update, we’ve improved the Animals model with more data. While you might notice only a slight improvement for cats (if at all 😼), dogs have gotten a slightly better upgrade. For example, the model is now better at recognizing their mouths instead of mistaking them for noses. 🐢

Before vs. After (v1.1)

The new version (v1.1) Animals Model has been updated on HuggingFace. The new version is enabled by default.

[!IMPORTANT]
Note: Make sure to update your weights to use the new version.

If you prefer to use the original version, simply modify the configuration in inference_config.py

python
version_animals = "" # old version
# version_animals = "_v1.1" # new (v1.1) version

File: assets/docs/directory-structure.md

The directory structure of `pretrained_weights`

text
pretrained_weights
β”œβ”€β”€ insightface
β”‚   └── models
β”‚       └── buffalo_l
β”‚           β”œβ”€β”€ 2d106det.onnx
β”‚           └── det_10g.onnx
β”œβ”€β”€ liveportrait
β”‚   β”œβ”€β”€ base_models
β”‚   β”‚   β”œβ”€β”€ appearance_feature_extractor.pth
β”‚   β”‚   β”œβ”€β”€ motion_extractor.pth
β”‚   β”‚   β”œβ”€β”€ spade_generator.pth
β”‚   β”‚   └── warping_module.pth
β”‚   β”œβ”€β”€ landmark.onnx
β”‚   └── retargeting_models
β”‚       └── stitching_retargeting_module.pth
└── liveportrait_animals
    β”œβ”€β”€ base_models
    β”‚   β”œβ”€β”€ appearance_feature_extractor.pth
    β”‚   β”œβ”€β”€ motion_extractor.pth
    β”‚   β”œβ”€β”€ spade_generator.pth
    β”‚   └── warping_module.pth
    β”œβ”€β”€ retargeting_models
    β”‚   └── stitching_retargeting_module.pth
    └── xpose.pth