这里写自定义目录标题
Nerfstudio 安装和使用记录
参考网站:https://docs.nerf.studio/en/latest/quickstart/installation.html
安装
因为服务器无法联网,采用本地安装的方法进行安装:
conda create --name nerfstudio -y python=3.8
conda activate nerfstudio
python -m pip install --upgrade pip
pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 -f https://download.pytorch.org/whl/torch_stable.html
这个链接无法在服务器联网安装,服务器一般不连外网
pip install git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch
可以去官网github下载
https://github.com/NVlabs/tiny-cuda-nn/
另外fmt 和 cutlass github 是给的超链接,因此上面的链接并没有下载 这两个包,需要手动下载和安装。
如果报错 ld: cannot find -lcuda
export LIBRARY_PATH="/usr/local/cuda-11.3/lib64/stubs:$LIBRARY_PATH"
cd bindings/torch
python setup.py install
安装nerfstudio:
git clone git@github.com:nerfstudio-project/nerfstudio.git
cd nerfstudio
pip install --upgrade pip setuptools
pip install -e .
运行速度 Bug:
是否在训练的时候 加入Mask 是很影响训练速度的;
没加之前 180 K 光线;
添加之后 40K 光线;
将 Mask 放置在 GPU 上面可以缓解速度的问题。
训练
下面这些配置是有顺序,更改顺序可能会报错。比如把 --viewer.skip-openrelay True 加在命令行的最后,会报错。应该跟在–viewer 的后面
在之前的权重上继续进行训练,加上 --load_dir 参数指定 ckpt 权重的 路径
ns-train nerfacto --data posters_v3/ --vis viewer --viewer.skip-openrelay True --viewer.websocket-port 7008
ns-train nerfacto --data kitti360/ --load_dir ckpt_path --vis viewer --viewer.skip-openrelay True --viewer.websocket-port 7008
打开电脑浏览器的 localhost:7008,可以查看viewer中的训练过程。
ns-train nerfacto --data posters_v3/ --vis viewer --viewer.skip-openrelay True --viewer.websocket-port 7008 --load-dir ./nerfstudio-main/outputs/posters_v3/nerfacto/2022-12-29_142632/nerfstudio_models/
加上==–logdir== 参数可以从预加载模型开始训练
出现 Address already in use 的错误的时候,原因是因为Port已经被占据,执行以下命令。
netstat -tunlp
kill -9 pid_number
运行原始的nerf (vanilla-nerf):
## Viewer
ns-train vanilla-nerf --data nerf_synthetic/kitti360 --vis viewer --viewer.skip-openrelay True --viewer.websocket-port 7007
## Tensorboad
ns-train vanilla-nerf --data nerf_synthetic/kitti360 --vis tensorboard
导出TSDF的Geometry
ns-export tsdf --load-config CONFIG.yml --output-dir OUTPUT_DIR
ns-extract-mesh --load-config outputs/../config.yml --output-path meshes/xxx.ply
**导出 3DGS 的 Splat **
ns-export gaussian-splat --load-config outputs/config.yml --output-dir data/splat1.ply
**使用命令行修改 Dataparser 的参数,在-data 后指定 **
ns-train neuralsplat --descriptor optimized_xyz --data /data1/smiao/General3DGS_sky/seq_04_nerfacto_0382_25_fine_xyz/
nerfstudio-data --pcd-ration=1
添加Camera 之后的 Render 命令
这里采用 nohup 的后端执行命令,即使关闭 Terminal 也照样执行程序代码。
nohup ns-render --load-config outputs/datasets-kitti360_mono_priors/monosdf/2023-02-06_125735/config.yml --traj filename --camera-path-filename outputs/datasets-kitti360_mono_priors/monosdf/2023-02-06_125735/camera_path.json --output-path renders/monosdf_output.mp4 &
Nerfstudio 代码笔记大致梳理
Pipeline 如下:

- DataParser 是什么?
DataParser 将各种形式的数据集作为输入,并且读取各个数据类别的Meta数据,返回的参数是DataparserOutputs
- DataManager 是什么?
DataManger 返回的是RayBundle 和 RayGT 。对于大多数的NerfPaper ,NerfStudio 设立了 VanillaDataManger. 其随机在DataManger中随机采样了一些像素点。生成了Training Ray 的颜色和Gt 的颜色
每一次采样的 光线数量 由参数 --pipeline.datamanager.train-num-rays-per-batch 来指定,默认数值是1024
Code:
ray_bundle, batch = self.datamanager.next_train(step) Ray_bundle (1024)
具体如何从DataManger 中进行Random Sample pixel 来生成 pixel_batch?
在Sample 函数中,输入的是img_batch 参数,是一个Dict,包含image_idx 列表和 image (batch,H,W,C)的Tensor。
在 pixel_sampler.py 代码中,调用sample_method 均匀采样pixel。具体算法是生成均匀采样的随机数t(batch,3) 和 tensor([num_images, image_height, image_width]) 进行相乘,返回一个Tensor.
indices = torch.floor(
torch.rand((batch_size, 3), device=device)
* torch.tensor([num_images, image_height, image_width], device=device)
).long()
- Model是什么?
Model 是实际执行的 Nerf-based 算法。Model读取RayBundle 对象返回的是每一条Ray对应的 rendered color
一般包含的模块有:
# Fields
# Ray Samplers
# Colliders
# Renderers
# Losses
# Metrics
- Field 是什么?
Field 是 Model 模块中的一个重要的Component 。在大多数经典的应用当中,输入是3D 的Location 和 View direction 输出是 density 和 color 数值。
- Pipeline 是什么?
在Nerfstudio 的代码中,Pipeline 包含Nerf方法所有的代码。在代码中有一个 Vanilla Implementation 类,负责从DataManger 中读取数据然后feed到Model当中。
升级 nerfstudio 的torch
torch 2.0 比torch1.12 更快。
- 需要先在 sdfstudio 中的 pyproject.toml 文件中注释掉 torch 的版本要求 和 funtorch 的 版本要求。 funtorch 在 torch 2.0 的 版本中已经被 移除了,不需要进行 额外的安装了。
# from functorch import jacrev, vmap
from torch.func import jacrev, vmap
- 更正 torch 的版本之后,需要重新 安装tinycudann
gsplat or nerfacc 运行的时候找不到 cuda 的问题
使用源码 安装可以解决这个问题,
Basestudio: 备份 Nerfstudio 的在KITTI360的标准版作为 Baseline 的快速复现。
在184 服务器上备份了 basestudio 的文件夹和对应的环境,在KITTI360 上进行测试, 正常运行 splatfacto, nerfacto 和 instant-ngp, 其中 instant-ngp 在街景上的结果略微差了一点。
导出的 3DGS 如果需要video可视化, 我进行了以下的评测:
如果为了实现 鼠标拖动的丝滑,那么我推荐使用 Threejs作为可视化的工具,转动起来很丝滑:
https://github.com/mkkellogg/GaussianSplats3D?tab=readme-ov-file
如果为了实现 Forward Motion的丝滑,那么我推荐使用 webGL GS作为可视化的工具,转动起来很丝滑:
https://antimatter15.com/splat/
键盘上的四个箭头 ”⬆ ⬇ ➡ ⬅“,可以控制相机的 在两个平面的 平移, 然后 拖动鼠标 或者 'q, e’两个按键 可以控制 鼠标的旋转。 如果要控制 相机在高, 那么需要 控制 相机的 俯仰角+往前开或者往后开即可。
SuperSplat 可以实现 Splats 在场景的删除 和 meshlab 删除点云一样
打开 supersplat 的网站:
https://superspl.at/editor
必须在点云模式下,可以实现高斯的删除:

选择 方形区域, 点击 选择上面的 删除 选项,即可删除 场景的 红色的 Splats
6701

被折叠的 条评论
为什么被折叠?



