K8S
基础
示例
开发
让一幅肖像活起来! LivePortrait

让一幅肖像活起来! LivePortrait (opens in a new tab)

准备

在部署完 JupyterLab 后使用浏览器打开 JupyterLab URL 地址

部署

以下所有操作均在 JupyterLab 中完成。可以参考官方部署步骤 (opens in a new tab)

  1. 部署 Conda (opens in a new tab):为了持久化 Conda 及库需要安装在挂载的 PVC /workspace

    mkdir -p /workspace/miniconda3
    wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /workspace/miniconda3/miniconda.sh
    bash /workspace/miniconda3/miniconda.sh -b -u -p ~/miniconda3
    rm -rf /workspace/miniconda3/miniconda.sh

    由于容器不持久化 rootfs (挂载 PVC 以外的目录), 需要每次容器启动后执行一次添加环境

    /workspace/miniconda3/bin/conda init bash
    pip config set global.index-url https://mirrors.bfsu.edu.cn/pypi/web/simple

    初始化环境后,打开一个新的终端或执行 source ~/.bashrc

  2. 安装依赖库:由于容器不持久化 rootfs, 需要容器每次启动后再执行一遍

    apt update && apt install -y tmux libgl1
  3. 下载并安装 LivePortrait

    cd /workspace
     
    git clone https://github.com/KwaiVGI/LivePortrait
    cd LivePortrait
     
    # create env using conda
    conda create -n LivePortrait python==3.9.18
    conda activate LivePortrait
    # install dependencies with pip
    pip install -r requirements.txt
  4. 下载模型

    Google Drive (opens in a new tab) 或者 Baidu Yun (opens in a new tab) 下载模型到本地后,再使用 JupyterLab 上传或者 File Browser 上传。最后解压到代码仓库的 pretrained_weights 目录下,文件结构如下:

    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
  5. 推理

    python inference.py

    生成的视频在 animations/s6--d0_concat.mp4 下, 您可以通过 JupyterLab 下载视频到本地预览或者使用 File Browser 在线预览。

    更多示例通过 -s 设置图片来源,-d 设置驱动视频来源(可以先使用仓库自带示例)

    python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d0.mp4
     
    # or disable pasting back
    python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d0.mp4 --no_flag_pasteback
     
    # more options to see
    python inference.py -h
  6. 提供临时在线服务

    tmux
    python app.py --server_port 8080

    使用 tmux 是防止终端退出服务退出,可以直接关闭终端或者 Crtl+b+d 退出终端,再次使用 tmux a 进入

    🥳🎉这时可以在浏览器打开 APP URL 地址进行使用!