安装docker

安装 nvidia-container-runtime

apt-get install nvidia-container-runtime
which nvidia-container-runtime-hook  #查看安装成功是否与安装位置
docker run -it --rm --gpus all ubuntu nvidia-smi  #运行测试
#centos版:
curl -s -L https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo | \
      sudo tee /etc/yum.repos.d/nvidia-container-toolkit.repo
sudo yum install -y nvidia-container-toolkit


#Debian版:
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o         /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
  && curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
    sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
    sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list \
  && \

sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit

配置docker runtime 运行时

  • vi /etc/docker/daemon.json
which nvidia-container-runtime-hook  #查看nvidia-container-runtime文件位置
#daemon.json
{
"default-runtime": "nvidia",
"runtimes": {
        "nvidia": {
            "path": "/usr/bin/nvidia-container-runtime",
            "runtimeArgs": []
         }    
    }
}
sudo systemctl daemon-reload
sudo systemctl restart docker

docker-compose中添加gpu引用

version: “3.9”
services:
  demo:
    image: continuumio/anaconda3:2021.05
    runtime: nvidia
    #command: nvidia-smi
   deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia  #驱动
              count: "all" #1 或"all"  #数量
              capabilities: [gpu]    #指定需要支持的功能;可以配置多个不同功能
              #device_ids: ['0', '3'] #gpu id和 count二选一              
              #capabilities: [gpu, utility] #支持多种功能

容器中检测显卡是否可用

nvidia-smi  #查看显卡
nvidia-smi -q #查看详细信息
nvidia-smi pmon #查看每秒使用状态

进入容器安装插件

sed -i "s@/deb.debian.org@/mirrors.tencentyun.com@g" /etc/apt/sources.list   
sed -i "s@/security.debian.org@/mirrors.tencentyun.com@g" /etc/apt/sources.list 
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu113

conda install ffmpeg 
pip install -r requirements.txt
#安装不成功时,可手工安装
pip install  gfpgan==1.3.8  #阿里云可以装

运行合成命令

python inference.py --driven_audio temp/aa.wav  --source_image temp/aa.jpg --result_dir results/  --still --preprocess full --enhancer gfpgan
python inference.py --driven_audio temp/bb.mp3  --source_image temp/bb.jpg --result_dir results/  --still --preprocess full --enhancer gfpgan
python inference.py --driven_audio temp/bb.mp3  --source_image temp/f2.jpg --result_dir results/  --preprocess full --enhancer gfpgan
--still
python inference.py --driven_audio temp/aa.wav  --source_image temp/aa.jpg --result_dir results/   --preprocess full --enhancer gfpgan
python inference.py --driven_audio temp/aa.wav  --source_image temp/aa.jpg --result_dir results/   --preprocess crop --enhancer gfpgan

错误处理:

  • ImportError: libGL.so.1: cannot open shared object file: No such file or directory
安装依赖项 libgl1
apt-get update && apt-get install libgl1 -y
安装cv2依赖
apt-get install libsm6 libxext6  -y