一张可打印的速查表,覆盖安装、训练、评估、导出的核心命令和参数。
conda create -n nerfstudio -y python=3.8
conda activate nerfstudio
pip install torch==2.1.2+cu118 torchvision==0.16.2+cu118 \
--extra-index-url https://download.pytorch.org/whl/cu118
conda install -c "nvidia/label/cuda-11.8.0" cuda-toolkit
pip install ninja git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch
pip install nerfstudio
ns-install-cli
| 命令 | 用途 |
|---|---|
ns-download-data nerfstudio --capture-name=poster | 下载示例数据集 |
ns-process-data images --data images/ --output-dir data/ | 从图片生成训练数据 |
ns-process-data video --data video.mp4 --output-dir data/ | 从视频抽帧生成数据 |
# 基础训练
ns-train nerfacto --data data/custom/
# 显存受限
ns-train nerfacto \
--pipeline.datamanager.train-num-rays-per-batch 2048 \
--data data/custom/
# 从 checkpoint 恢复
ns-train nerfacto --data data/custom/ \
--load-dir outputs/.../nerfstudio_models/
# 多 GPU
ns-train nerfacto --machine.num-devices 2 \
--pipeline.datamanager.train-num-rays-per-batch 2048 \
--data data/custom/
ns-eval --load-config outputs/.../config.yml --output-path eval.json
| 指标 | 范围 | 解读 |
|---|---|---|
| PSNR | 越高越好,>30 优秀 | 像素级误差,对异常值敏感 |
| SSIM | [0,1],越接近 1 越好 | 结构相似性,接近人眼感知 |
| LPIPS | [0,1],越接近 0 越好 | 感知损失,最贴近主观感受 |
# 渲染视频
ns-render --load-config outputs/.../config.yml --traj spiral
# 导出点云
ns-export pointcloud --load-config outputs/.../config.yml
# 导出网格
ns-export mesh --load-config outputs/.../config.yml
# 启动 Viewer
ns-viewer --load-config outputs/.../config.yml
| 参数 | 路径 | 默认值 | 调整场景 |
|---|---|---|---|
| rays per batch | pipeline.datamanager.train-num-rays-per-batch | 4096 | 显存不足/过剩 |
| hash levels | pipeline.model.num-levels | 16 | 场景复杂度 |
| hidden dim | pipeline.model.hidden-dim | 64 | 精度/速度 trade-off |
| max iterations | max-num-iterations | 30000 | 训练时间限制 |
| learning rate | optimizers.fields.lr | 1e-2 | 训练不稳定 |
| save interval | trainer.steps-per-save | 2000 | 磁盘空间 |
确认 nvcc --version 与 PyTorch CUDA 版本一致。不一致时重新安装对应版本 PyTorch。
弱纹理/重复纹理/动态物体导致。增加拍摄角度、避免纯色区域、移除动态元素。
更换端口 --viewer.websocket-port 7008;远程机器需配置 SSH 端口转发。
检查 transforms.json 格式;尝试降低学习率;确认数据路径正确。
增加迭代次数;提高 num-levels;检查 COLMAP 位姿质量。
场景中有移动物体。使用三脚架拍摄,移除动态元素。