NeRF-SLAM部署运行(3060Ti)

记录在部署运行期间遇到的一些问题,分享给大家~

一、环境

RTX 3060 Ti、8G显存(其实是不够用,只能简单跑跑demo)、Ubuntu18.04

二、部署

1. 下载代码
git clone https://github.com/jrpowers/NeRF-SLAM.git --recurse-submodules
git submodule update --init --recursive
cd thirdparty/instant-ngp/ && git checkout feature/nerf_slam

这里clone的不是原作者的code,而是jrpowers的code,因为官方给的代码在安装部署过程中遇到了不少问题,所以先跳过,给大家介绍成功的流程,下文会介绍部分官方代码在部署过程中遇到的问题及对应的解决方法。

2. 安装CUDA 11.7 和PyTorch

这里我用的是anaconda,如何使用conda请参照ubuntu下anaconda的安装、配置与使用_ubuntu怎么使用anaconda_zllz0907的博客-CSDN博客

conda create -n nerf python=3.9
conda install -c "nvidia/label/cuda-11.7.0" cuda-toolkit
pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117
3. 安装requirements
pip install -r requirements.txt
pip install -r ./thirdparty/gtsam/python/requirements.txt
4. 编译ngp(确保cmake版本>3.22)
cmake ./thirdparty/instant-ngp -B build_ngp
cmake --build build_ngp --config RelWithDebInfo -j
5. 编译gtsam

官方代码在编译gtsam时大概率会遇到问题

cmake ./thirdparty/gtsam -DGTSAM_BUILD_PYTHON=1 -B build_gtsam 
cmake --build build_gtsam --config RelWithDebInfo -j
cd build_gtsam
make python-install

如果设备性能有限,或者编译时遇到cplusplus internal相关的问题,将上述第二行编译指令后的-j改为-j8或者更小的-j6,降低在编译时的并行数量。

6. 安装
python setup.py install

三、运行

1. 下载数据集
./scripts/download_replica_sample.bash
2. 运行
python ./examples/slam_demo.py --dataset_dir=./datasets/Replica/office0 --dataset_name=nerf --buffer=100 --slam --parallel_run --img_stride=2 --fusion='nerf' --multi_gpu --gui

注意download_replica_sample.bash中的数据下载地址是Datasets,而运行地址是小写字母datasets,需改成一致。

如果运行时出现检测不到CUDA设备或者无gui画面时,错误如下:

RuntimeError: Could not allocate memory: 
/thirdparty/instant-ngp/dependencies/tiny-cuda-nn/include/tiny-cuda-nn/gpu_memory.h:123 cudaMalloc(&rawptr, n_bytes+DEBUG_GUARD_SIZE*2) 
failed with error no CUDA-capable device is detected

将上述运行指令中的--multi_gpu选项去掉即可。

3. 其他模式运行

跳过SLAM,用位姿真值和深度运行。3060Ti 8G现存可以运行这种模式

./scripts/download_cube.bash 
python ./examples/slam_demo.py --dataset_dir=./datasets/nerf-cube-diorama-dataset/room --dataset_name=nerf --buffer=100 --img_stride=1 --fusion='nerf' --gui

运行画面如下:

四、官方代码问题解决记录

1. gtsam编译问题

在执行cmake --build build_gtsam --config RelWithDebInfo后遇到

#0 3.429 pyparsing.exceptions.ParseException: Expected string_end, found 'namespace'  (at char 1249), (line:46, col:1)
#0 3.450 make[2]: *** [python/CMakeFiles/pybind_wrap_gtsam_unstable.dir/build.make:76: python/gtsam_unstable.cpp] Error 1
#0 3.450 make[1]: *** [CMakeFiles/Makefile2:32340: python/CMakeFiles/pybind_wrap_gtsam_unstable.dir/all] Error 2

解决:

将thirdparty中的gtsam代码替换为https://github.com/ToniRV/gtsam-1下的代码,重新执行编译步骤即可。

2. 路径问题

download_replica_sample.bash中的数据下载地址是Datasets,而运行地址是小写字母datasets.

3. 运行时报错
 File "/NeRF-SLAM/./examples/../slam/vio_slam.py", line 65, in initial_state
    naive_pose = gtsam.Pose3.identity()
AttributeError: type object 'gtsam.gtsam.Pose3' has no attribute 'identity'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "anaconda3/envs/zl/lib/python3.9/multiprocessing/spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "anaconda3/envs/zl/lib/python3.9/multiprocessing/spawn.py", line 126, in _main
    self = reduction.pickle.load(from_parent)
  File "anaconda3/envs/zl/lib/python3.9/multiprocessing/synchronize.py", line 110, in __setstate__
    self._semlock = _multiprocessing.SemLock._rebuild(*state)
FileNotFoundError: [Errno 2] No such file or directory
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "anaconda3/envs/zl/lib/python3.9/multiprocessing/spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "anaconda3/envs/zl/lib/python3.9/multiprocessing/spawn.py", line 126, in _main
    self = reduction.pickle.load(from_parent)
  File "anaconda3/envs/zl/lib/python3.9/multiprocessing/synchronize.py", line 110, in __setstate__
    self._semlock = _multiprocessing.SemLock._rebuild(*state)
FileNotFoundError: [Errno 2] No such file or directory

重新卸载安装其他版本的gtsam也没解决,于是跳转至前文介绍的部署流程了。

相关推荐
jndingxin1 小时前
OpenCV特征检测(1)检测图像中的线段的类LineSegmentDe()的使用
人工智能·opencv·计算机视觉
Zhangci]2 小时前
Opencv图像预处理(三)
人工智能·opencv·计算机视觉
大耳朵爱学习4 小时前
掌握Transformer之注意力为什么有效
人工智能·深度学习·自然语言处理·大模型·llm·transformer·大语言模型
qq_15321452644 小时前
【2023工业异常检测文献】SimpleNet
图像处理·人工智能·深度学习·神经网络·机器学习·计算机视觉·视觉检测
极客代码5 小时前
OpenCV Python 深度指南
开发语言·人工智能·python·opencv·计算机视觉
simplesin5 小时前
OpenCV 1
人工智能·opencv·计算机视觉
DisonTangor6 小时前
阿里通义千问开源Qwen2.5系列模型:Qwen2-VL-72B媲美GPT-4
人工智能·计算机视觉
豆浩宇6 小时前
Halcon OCR检测 免训练版
c++·人工智能·opencv·算法·计算机视觉·ocr
嵌入式杂谈6 小时前
OpenCV计算机视觉:探索图片处理的多种操作
人工智能·opencv·计算机视觉
红米煮粥6 小时前
图像处理-掩码
图像处理·opencv·计算机视觉