Windows部署GeneFace++的关键要点
一 环境与硬件准备
- 操作系统与权限:建议使用Windows 10/11 64位,以管理员权限安装驱动与构建工具。
- Python与虚拟环境:安装Python 3.8/3.9(3.6+亦可),用conda或venv创建隔离环境,避免依赖冲突。
- GPU与驱动:如需加速,准备NVIDIA RTX显卡,安装最新NVIDIA驱动;后续按项目选择匹配的CUDA/cuDNN与PyTorch版本。
- 编译与多媒体工具:安装Visual Studio Build Tools 2019/2022(含C++桌面开发)、CMake、Git、ffmpeg(含ffplay/ffprobe)。
- 资源规划:至少8–16GB内存、10GB+磁盘空间(模型与依赖体积较大)。
二 标准安装流程
- 获取代码
- 使用git克隆官方仓库(或下载源码包):git clone && cd GeneFace++。
- 创建并激活虚拟环境
- conda create -n geneface_env python=3.8 -y && conda activate geneface_env
- 安装Python依赖
- 有requirements.txt时:pip install -r requirements.txt
- 无则先装核心:pip install numpy opencv-python torch torchvision
- 编译扩展(如有C++/CUDA)
- mkdir build && cd build
- cmake .. -G "Visual Studio 16 2019" -A x64 -DPYTHON_EXECUTABLE=<你的python路径>
- cmake --build . --config Release
- 安装Python包(若提供setup.py)
- 验证安装
- python -c "import torch; print(torch.__version__, torch.cuda.is_available())"
三 GPU与CUDA版本匹配
四 Windows常见问题与排查
- 构建失败(cl.exe/找不到头文件):确认安装了Visual Studio Build Tools与Windows SDK,并在“x64 Native Tools Command Prompt”中执行CMake/构建。
- 缺少ffmpeg:安装并将ffmpeg的bin目录加入PATH,确保能运行ffprobe。
- 路径与权限:项目路径避免中文与空格;以管理员权限运行命令行/安装器。
- 显存不足:降低分辨率/批量大小,或改用CPU模式验证流程后再上GPU。
- 依赖冲突:使用独立虚拟环境;必要时用pip check与conda list排查版本冲突。
五 可选方案与性能建议
- 无GPU或构建困难时,可先在CPU环境完成流程验证与小规模测试,再切换到GPU。
- 对稳定性要求高时,可考虑在WSL2(Ubuntu 22.04)中部署:
- 启用WSL2(PowerShell管理员):dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart 与 dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart,重启后 wsl --set-default-version 2,再安装Ubuntu 22.04。
- 在WSL2中按Linux流程安装Python、PyTorch、CMake与项目依赖,通常更贴近官方开发环境。