Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement LivePortrait #1512

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Conversion of MediaPipe from TFLite to PyTorch done by George Grigorev
in June 2020. Website: https://github.com/thepowerfuldeez/facemesh.pytorch

This work is licensed under the same terms as MediaPipe (Apache License 2.0)
https://github.com/google/mediapipe/blob/master/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The code of InsightFace is released under the MIT License.
The models of InsightFace are for non-commercial research purposes only.

If you want to use the LivePortrait project for commercial purposes, you
should remove and replace InsightFace's detection models to fully comply with
the MIT license.
21 changes: 21 additions & 0 deletions generative_adversarial_networks/live_portrait/LICENSE_LIVEPORTRAIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Kuaishou Visual Generation and Interaction Center

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
87 changes: 87 additions & 0 deletions generative_adversarial_networks/live_portrait/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# LivePortrait

## Input

- Source Portrait

<img src="s6.jpg" height="256px"/>

(Image from https://github.com/KwaiVGI/LivePortrait/blob/main/assets/examples/source/s6.jpg)

- Driving Video

<img src="images/d0.png" height="256px"/>
<img src="images/d1.png" height="256px"/>
<img src="images/d2.png" height="256px"/>

(Video from https://github.com/KwaiVGI/LivePortrait/blob/main/assets/examples/driving/d0.mp4)

## Output

- Animated Video

<img src="images/a0.png" height="256px"/>
<img src="images/a1.png" height="256px"/>
<img src="images/a2.png" height="256px"/>

## Usage
Automatically downloads the onnx and prototxt files on the first run.
It is necessary to be connected to the Internet while downloading.

For the sample image,
```bash
$ python3 live_portrait.py
```

If you want to specify the source image, put the image path after the `--input` option.
The driving video can be specified with the `--driving` option.
You can use `--savepath` option to change the name of the output file to save.
```bash
$ python3 live_portrait.py --input SOURCE_IMAGE --driving DRIVING_VIDEO --savepath SAVE_IMAGE_PATH
```

By adding the `--video` option, you can input the video.
If you pass `0` as an argument to VIDEO_PATH, you can use the webcam input instead of the video file.
```bash
$ python3 live_portrait.py --video VIDEO_PATH
```

If you specify the `--composite` option, the driving frame and source image and animated frame to be drawn together.
```bash
$ python3 live_portrait.py --composite
```

## Reference

- [LivePortrait](https://github.com/KwaiVGI/LivePortrait)
- [hugging face - KwaiVGI/LivePortrait](https://huggingface.co/spaces/KwaiVGI/LivePortrait)

## Framework

Pytorch

## Model Format

- landmark.onnx.prototxt

ONNX opset=13

- appearance_feature_extractor.onnx.prototxt
- motion_extractor.onnx.prototxt
- spade_generator.onnx.prototxt
- stitching.onnx.prototxt

ONNX opset=17

- warping_module.onnx.prototxt

ONNX opset=20

## Netron

[appearance_feature_extractor.onnx.prototxt](https://netron.app/?url=https://storage.googleapis.com/ailia-models/live_portrait/appearance_feature_extractor.onnx.prototxt)
[motion_extractor.onnx.prototxt](https://netron.app/?url=https://storage.googleapis.com/ailia-models/live_portrait/motion_extractor.onnx.prototxt)
[warping_module.onnx.prototxt](https://netron.app/?url=https://storage.googleapis.com/ailia-models/live_portrait/warping_module.onnx.prototxt)
[spade_generator.onnx.prototxt](https://netron.app/?url=https://storage.googleapis.com/ailia-models/live_portrait/spade_generator.onnx.prototxt)
[stitching.onnx.prototxt](https://netron.app/?url=https://storage.googleapis.com/ailia-models/live_portrait/stitching.onnx.prototxt)
[landmark.onnx.prototxt](https://netron.app/?url=https://storage.googleapis.com/ailia-models/live_portrait/landmark.onnx.prototxt)
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading