1. Windows环境下wild-gaussian-splatting与dust3r项目配置全攻略
最近在Windows平台上折腾wild-gaussian-splatting和dust3r这两个3D重建项目时,遇到了不少坑。特别是当你的开发环境是VS2022+CUDA11.8+MSVC14.38+UE5.3.2这套组合时,问题会更加棘手。本文将详细记录整个配置过程,重点解决RTX 2000 Ada显卡在Windows下的编译问题,以及项目运行中的各种疑难杂症。
1.1 环境准备与项目克隆
首先需要准备好基础环境,这里假设你已经安装好了以下组件:
- Visual Studio 2022(确保安装了C++开发工具集)
- CUDA 11.8
- Anaconda或Miniconda
- Git
项目克隆步骤如下:
bash复制git clone https://github.com/nerlfield/wild-gaussian-splatting
cd wild-gaussian-splatting
git clone --recursive https://github.com/naver/dust3r
git clone --recursive https://github.com/naver/mast3r
注意:这里使用的是nerlfield维护的wild-gaussian-splatting分支,而不是官方版本,因为后续与高斯泼溅(Gaussian Splatting)的集成需要这个特定版本。
1.2 基础依赖安装
进入项目目录后,先安装基础Python依赖:
bash复制pip install ipywidgets==8.0.2 jupyterlab==3.4.2 lovely-tensors==0.1.15
cd dust3r
pip install -r requirements.txt
pip install -r requirements_optional.txt
cd mast3r
pip install -r dust3r/requirements.txt
pip install -r dust3r/requirements_optional.txt
接下来需要下载预训练权重文件,分别放入dust3r和mask3r下的checkpoints文件夹中:
- DUSt3R权重:https://download.europe.naverlabs.com/ComputerVision/DUSt3R/DUSt3R_ViTLarge_BaseDecoder_512_dpt.pth
- MASt3R权重:https://download.europe.naverlabs.com/ComputerVision/MASt3R/MASt3R_ViTLarge_BaseDecoder_512_catmlpdpt_metric.pth
1.3 关键难点:curope模块编译
curope模块的编译是整个安装过程中最具挑战性的部分,特别是在Windows环境下。以下是详细步骤:
- 使用"x64 Native Tools Command Prompt for VS 2022"(管理员权限运行)
- 激活conda环境并进入crope目录:
bash复制conda activate gaussian_splatting
cd /d x:\xxxxxx\wild-gaussian-splatting\dust3r\croco\models\curope
- 修改setup.py文件,关键修改是针对RTX 2000 Ada显卡的架构支持:
python复制# 修改CUDA架构设置
cuda_arch_flags = [
'-gencode', 'arch=compute_86,code=sm_86', # 将sm_89改为sm_86以兼容CUDA 11.8
]
# Windows MSVC编译器参数
cxx_args = ['/O2'] if os.name == 'nt' else ['-O3']
# NVCC编译器参数
nvcc_args = [
'-O3',
'--use_fast_math',
'--ptxas-options=-v'
] + cuda_arch_flags
- 设置必要的环境变量:
bash复制set DISTUTILS_USE_SDK=1
set MSSdk=1
set NVCC_FLAGS="-allow-unsupported-compiler"
set CUDA_HOME=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8
set CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8
set PATH=D:\ProgramData\anaconda3\envs\gaussian_splatting\Scripts;%PATH%
set USE_NINJA=1
- 验证工具链:
bash复制where ninja
where nvcc
where cl
- 清理并重新编译:
bash复制if exist build rd /s /q build
python setup.py build_ext --inplace
常见问题:如果编译失败,请检查:
- CUDA路径是否正确
- Visual Studio工具链是否配置正确
- 显卡架构设置是否匹配你的显卡型号
2. 项目运行与调试
2.1 运行DUSt3R推理
项目提供了几个Jupyter notebook用于不同阶段的处理。首先运行DUSt3R推理:
bash复制jupyter notebook ./notebooks/00_dust3r_inference.ipynb
这里可能会遇到第一个坑:官方dust3r仓库的inference.py不包含load_model方法。解决方案是使用nerlfield修改过的版本:
bash复制cd wild-gaussian-splatting
rm -rf dust3r
git clone https://github.com/nerlfield/dust3r.git
2.2 运行MASt3R推理
MASt3R的推理过程与DUSt3R类似:
bash复制jupyter notebook ./notebooks/00_mast3r_inference.ipynb
这个步骤通常比较顺利,只要权重文件放置正确,一般不会出现问题。
2.3 高斯泼溅拟合
这是整个流程中最复杂的部分,需要运行:
bash复制jupyter notebook ./notebooks/01_gaussian_splatting_fitting.ipynb
这里会遇到几个关键问题:
- readColmapSceneInfo函数参数不匹配:
- 官方版本:readColmapSceneInfo(path, images, depths, eval, train_test_exp, llffhold=8)
- 作者修改版:readColmapSceneInfo(path, images, eval, llffhold=8)
解决方案是使用nerlfield修改过的高斯泼溅版本:
bash复制cd wild-gaussian-splatting
rm -rf gaussian-splatting
git clone https://github.com/nerlfield/gaussian-splatting.git
- 渲染参数缺失问题:
在GaussianRasterizationSettings中需要添加antialiasing=False参数:
python复制raster_settings = GaussianRasterizationSettings(
image_height=int(viewpoint_camera.image_height),
image_width=int(viewpoint_camera.image_width),
tanfovx=tanfovx,
tanfovy=tanfovy,
bg=bg_color,
scale_modifier=scaling_modifier,
viewmatrix=viewpoint_camera.world_view_transform,
projmatrix=viewpoint_camera.full_proj_transform,
sh_degree=pc.active_sh_degree,
campos=viewpoint_camera.camera_center,
prefiltered=False,
debug=pipe.debug,
antialiasing=False, # 关键添加
)
- 渲染器输出处理:
需要修改rasterizer_output的处理逻辑:
python复制if len(rasterizer_output) == 2:
rendered_image, radii = rasterizer_output
else:
rendered_image, radii = rasterizer_output[0], rasterizer_output[1]
3. 结果可视化
成功运行上述步骤后,可以使用SIBR_viewer查看结果:
bash复制.\gaussian-splatting\SIBR_viewers\install\bin\SIBR_gaussianViewer_app -m ./notebooks/output/your_output_folder
4. 常见问题与解决方案
4.1 CUDA相关错误
-
不支持的编译器版本:
错误信息通常包含"unsupported Microsoft Visual Studio version"。解决方案:- 确保使用CUDA 11.8对应的VS2022工具集
- 设置NVCC_FLAGS="-allow-unsupported-compiler"
-
显卡架构不匹配:
错误信息可能包含"sm_89 not supported"。解决方案:- 修改setup.py中的cuda_arch_flags,使用sm_86代替sm_89
4.2 Python环境问题
-
依赖冲突:
- 建议使用conda创建独立环境
- 严格按照requirements.txt安装指定版本
-
Jupyter内核问题:
- 确保在正确的conda环境中运行jupyter
- 可以使用
ipython kernel install --user --name=gaussian_splatting注册内核
4.3 性能优化建议
-
内存管理:
- DUSt3R的内存使用随图像数量呈平方级增长
- 对于512x384的图像,L4实例最多处理32张
-
显卡选择:
- 推荐使用至少8GB显存的NVIDIA显卡
- 对于Ada架构显卡,需要特别注意CUDA版本兼容性
5. 项目整合与UE5对接
虽然本文主要关注Windows环境下的配置,但这些技术栈与Unreal Engine 5.3.2的整合也值得注意:
-
数据管道:
- DUSt3R/MASt3R生成的3D点云可以导入UE5
- 高斯泼溅结果可以通过插件集成到UE5场景中
-
实时渲染优化:
- 在UE5中可以考虑使用Nanite或Lumen技术增强渲染效果
- 对于移动平台,可能需要简化高斯泼溅模型
整个配置过程虽然复杂,但成功运行后的3D重建效果令人印象深刻。特别是在Windows环境下完成这一系列配置,对于需要在本地开发3D重建应用的研究者和开发者来说,这套解决方案具有很高的实用价值。