LivePortrait是一个由快手可灵团队开发的高级人工智能肖像动画框架,其主要功能是使静态照片中的面部能够模仿动态视频中的表情变化,从而让照片看起来像是活生生的人在做表情。
LivePortrait采用了基于隐式关键点的方法,而不是传统的扩散方法,来从单一的源图像生成高质量且生动的视频动画,平衡了计算效率和可控性。
LivePortrait在 NVIDIA RTX 4090 GPU 上使用 PyTorch 可以达到每帧 12.8 毫秒的处理速度,这使得它非常适合实时应用。
LivePortrait支持多种风格,包括现实主义、油画、雕塑和 3D 渲染,适用于从创意内容到专业视频制作的不同应用场景。
LivePortrait的github项目地址:https://github.com/KwaiVGI/LivePortrait。
一、环境安装
1、python环境
建议安装python版本在3.10以上。
2、pip库安装
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
3、模型下载:
git lfs install
git clone https://huggingface.co/KwaiVGI/LivePortrait
二、功能测试
1、命令行运行测试:
(1)python代码调用测试
# coding: utf-8
import os.path as osp
import tyro
import subprocess
from src.config.argument_config import ArgumentConfig
from src.config.inference_config import InferenceConfig
from src.config.crop_config import CropConfig
from src.live_portrait_pipeline import LivePortraitPipeline
def partial_fields(target_class, kwargs):
    """Create an instance of target_class with kwargs filtered to only those attributes that exist in target_class."""
    return target_class(**{k: v for k, v in kwargs.items() if hasattr(target_class, k)})
def fast_check_ffmpeg():
    """Check if FFmpeg is installed by attempting to run 'ffmpeg -version' command."""
    try:
        subprocess.run(["ffmpeg", "-version"], capture_output=True, check=True)
        return True
    except subprocess.CalledProcessError:
        return False
    except FileNotFoundError:  # FFmpeg binary not found
        return False
def fast_check_args(args: ArgumentConfig):
    """Perform quick checks on the provided arguments to ensure required files exist."""
    if not osp.exists(args.source_image):
        raise FileNotFoundError(f"source image not found: {args.source_image}")
    if not osp.exists(args.driving_info):
        raise FileNotFoundError(f"driving info not found: {args.driving_info}")
def main():
    # Set tyro theme
    tyro.extras.set_accent_color("bright_cyan")
    # Parse command-line arguments
    args = tyro.cli(ArgumentConfig)
    # Provide default values for source_image and driving_info if they aren't set by command-line arguments
    args.source_image = args.source_image or "assets/examples/source/s0.jpg"
    args.driving_info = args.driving_info or "assets/examples/driving/d0.mp4"
    # Check if FFmpeg is installed
    if not fast_check_ffmpeg():
        raise ImportError(
            "FFmpeg is not installed. Please install FFmpeg before running this script. https://ffmpeg.org/download.html"
        )
    # Perform quick argument checks
    fast_check_args(args)
    # Configure inference and cropping
    inference_cfg = partial_fields(InferenceConfig, args.__dict__)
    crop_cfg = partial_fields(CropConfig, args.__dict__)
    # Initialize LivePortraitPipeline with the specified configurations
    live_portrait_pipeline = LivePortraitPipeline(
        inference_cfg=inference_cfg,
        crop_cfg=crop_cfg
    )
    # Run the live portrait pipeline
    live_portrait_pipeline.execute(args)
if __name__ == "__main__":
    main()(2)web端测试
未完......
更多详细的内容欢迎关注:杰哥新技术




















