记录在部署运行期间遇到的一些问题,分享给大家~
RTX 3060 Ti、8G显存(其实是不够用,只能简单跑跑demo)、Ubuntu18.04
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,因为官方给的代码在安装部署过程中遇到了不少问题,所以先跳过,给大家介绍成功的流程,下文会介绍部分官方代码在部署过程中遇到的问题及对应的解决方法。
这里我用的是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
pip install -r requirements.txt
pip install -r ./thirdparty/gtsam/python/requirements.txt
cmake ./thirdparty/instant-ngp -B build_ngp
cmake --build build_ngp --config RelWithDebInfo -j
官方代码在编译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,降低在编译时的并行数量。
python setup.py install
./scripts/download_replica_sample.bash
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选项去掉即可。
跳过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
运行画面如下:
在执行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下的代码,重新执行编译步骤即可。
download_replica_sample.bash中的数据下载地址是Datasets,而运行地址是小写字母datasets.
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 "", line 1, in
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 "", line 1, in
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也没解决,于是跳转至前文介绍的部署流程了。