Ubuntu22.04复现NeRF_SLAM

cmake版本:3.22.1

cuda版本:11.5

摘要

        这是一个结合单目稠密SLAM和层次化体素神经辐射场的3D场景重建算法,能实时地用图像序列实现准确的辐射场构建,并且不需要位姿或深度输入。论文的核心思想是,使用一个单目稠密SLAM方法来估计相机位姿和稠密深度图以及它们的不确定度,用上述信息作为监督信号来训练NeRF场景表征。

一、更新系统软件源 

 备份配置文件/etc/apt/sources.list

sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
//将软件源配置文件备份

编辑配置文件

sudo vim /etc/apt/sources.list			//编辑配置文件,此时进入命令模式
/***vim的基本使用方法***
i			进入编辑(输入)模式,这时候可以对文件进行更改
Esc   		退出编辑模式,此时进入命令模式
:			命令前带冒号进入底线命令模式
:w		保存文件
:q			退出编辑模式
:wq		保存文件并退出编辑模式
:q!		不保存(强制)退出

参考:Ubuntu20.04更换软件源_ubuntu20.04软件源-CSDN博客

二、查看cuda的版本  

 安装

sudo apt install nvidia-cuda-toolkit

然后使用

nvcc -V

就可以查看cuda的版本:

 三、下载NeRF源码(看第十点,这个是错的

先下载最新的NeRF源码

https://github.com/ToniRV/NeRF-SLAM.git

四、安装Anaconda

Index of /anaconda/archive/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

我安装了最新版本的https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2023.09-0-Linux-x86_64.sh

安装Anaconda3

bash Anaconda3-2022.10-Linux-x86_64.sh

正确的做法是:先按回车,一直按s,就可以下一页,然后就会出现‘yes’ or ‘no’,然后再按回车,就可以安装了。

加环境变量

sudo vim ~/.bashrc
//在弹出的文本末尾加上
//记得更改用户名
export PATH="/home/用户名/anaconda3/bin:$PATH"

 每个人的文档都不是完全一样的,再文档的最后面加入即可。然后:wq保存退出,source一下让它生效。

source ~/.bashrc
//检验下安装成功没
conda --version

五、添加清华镜像源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
conda config --set show_channel_urls yes

六、安装依赖项

创建并激活虚拟环境

conda create -n NeRF_SLAM
source activate NeRF_SLAM

 七、安装cmake3.22.6

要求Cmake版本在3.22以上,参考这篇博客
安装cmake3.22.6,https://cmake.org/files/v3.22/cmake-3.22.6-linux-x86_64.tar.gz,国内源:Index of /files (cmake.org)

删除旧的版本

sudo apt autoremove cmake

可能会出现以下的错误

error8.1        bash:/usr/bin/cmake:是一个目录

error8.2        bash:/usr/bin/cmake:没有那个文件或目录

error8.3        bash:/usr/bin/cmake:符号连接的层数过多

error8.4        ln:无法创建符号链接‘/usr/bin/cmake’:文件已存在

解决方法:

八、安装pytorch

cuda对应的版本可以用nvcc -V查看

注意pytorch要下载cuda对应的版本

// CUDA 11.7
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia 
//Pip install requirements:
pip install -r requirements.txt

 安装过程中会出现:

The following packages will be SUPERSEDED by a higher-priority channel:
 
  ca-certificates                                 pkgs/main --> anaconda/pkgs/main
  certifi                                         pkgs/main --> anaconda/pkgs/main
  conda                                           pkgs/main --> anaconda/pkgs/main
 
 
Proceed ([y]/n)? 

我的选择是yes,参考The following packages will be SUPERCEDED by a higher-priority channel是什么意思? - 思念殇千寻 - 博客园 (cnblogs.com)

 只是替换了源的优先等级

九、开始编译NerRF_SLAM

 在NeRF_SLAM目录下,运行

pip install -r requirements.txt
//安装需要的依赖项
pip install -r ./thirdparty/gtsam/python/requirements.txt
//安装需要的依赖项
pip install -r ./thirdparty/instant-ngp/requirements.txt
//安装需要的依赖项

在NeRF_SLAM运行安装依赖的时候,出现问题:

error: subprocess-exited-with-error × python setup.py egg_info did not run successfully. │ exit code: 1 ╰─> [6 lines of output] Traceback (most recent call last): File "<string>", line 2, in <module> File "<pip-setuptools-caller>", line 34, in <module> File "/tmp/pip-install-rd_djx6m/torch-scatter_be63210475ac42c2bcea49ffe6107bcb/setup.py", line 8, in <module> import torch ModuleNotFoundError: No module named 'torch' [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details.

解决方法:

检查torch是否正确安装:首先确保你的环境中已经安装了PyTorch,并且PyTorch的版本与torch-scatter兼容。你可以使用pipconda来安装PyTorch,具体取决于你的环境和需求。

例如,使用conda安装PyTorch:

conda install pytorch torchvision torchaudio -c pytorch

进入NeRF_SLAM的目录下,运行

出现error

ERROR: Ignored the following versions that require a different python version: 1.21.2 Requires-Python >=3.7,<3.11; 1.21.3 Requires-Python >=3.7,<3.11; 1.21.4 Requires-Python >=3.7,<3.11; 1.21.5 Requires-Python >=3.7,<3.11; 1.21.6 Requires-Python >=3.7,<3.11
ERROR: Could not find a version that satisfies the requirement numpy~=1.21.2 (from versions: 1.3.0, 1.4.1, 1.5.0, 1.5.1, 1.6.0, 1.6.1, 1.6.2, 1.7.0, 1.7.1, 1.7.2, 1.8.0, 1.8.1, 1.8.2, 1.9.0, 1.9.1, 1.9.2, 1.9.3, 1.10.0.post2, 1.10.1, 1.10.2, 1.10.4, 1.11.0, 1.11.1, 1.11.2, 1.11.3, 1.12.0, 1.12.1, 1.13.0, 1.13.1, 1.13.3, 1.14.0, 1.14.1, 1.14.2, 1.14.3, 1.14.4, 1.14.5, 1.14.6, 1.15.0, 1.15.1, 1.15.2, 1.15.3, 1.15.4, 1.16.0, 1.16.1, 1.16.2, 1.16.3, 1.16.4, 1.16.5, 1.16.6, 1.17.0, 1.17.1, 1.17.2, 1.17.3, 1.17.4, 1.17.5, 1.18.0, 1.18.1, 1.18.2, 1.18.3, 1.18.4, 1.18.5, 1.19.0, 1.19.1, 1.19.2, 1.19.3, 1.19.4, 1.19.5, 1.20.0, 1.20.1, 1.20.2, 1.20.3, 1.21.0, 1.21.1, 1.22.0, 1.22.1, 1.22.2, 1.22.3, 1.22.4, 1.23.0rc1, 1.23.0rc2, 1.23.0rc3, 1.23.0, 1.23.1, 1.23.2, 1.23.3, 1.23.4, 1.23.5, 1.24.0rc1, 1.24.0rc2, 1.24.0, 1.24.1, 1.24.2, 1.24.3, 1.24.4, 1.25.0rc1, 1.25.0, 1.25.1, 1.25.2, 1.26.0b1, 1.26.0rc1, 1.26.0, 1.26.1)
ERROR: No matching distribution found for numpy~=1.21.2

(错误的)   解决方法:

conda install numpy=1.21.2

如果这样子做后面就会报错:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
pandas 2.1.1 requires numpy>=1.22.4; python_version < "3.11", but you have numpy 1.21.6 which is incompatible.

(正确的)解决方法:

conda install numpy=1.22.4

编译instant-ngp(这一步是最难的

自己见机行事!!!!!!!我把我用到的,都放在下面参考了

进入到下面的这一步,安装instant-ngp出现错误了

cmake ./thirdparty/instant-ngp -B build_ngp

我一直报错:

CMake Error at CMakeLists.txt:42 (message):
  Some instant-ngp dependencies are missing.  If you forgot the "--recursive"
  flag when cloning this project, this can be fixed by calling "git submodule
  update --init --recursive".

参考1:Ubuntu 安装 Ceres-Solver_查看ceres是否按扎u安装_李常颢的博客-CSDN博客

参考2:安装 — 谷神星求解器 (ceres-solver.org) 

参考3: ubuntu20.04 nerf Instant-ngp-CSDN博客

参考4:如果不能安装cere2.2.0,就安装cere2.0.0http://ceres-solver.org/ceres-solver-2.0.0.tar.gz

参考5: Ubuntu22.04 安装ceres-solver,cmake编译报错有tbb_stddef.h-CSDN博客

我傻了,最后我不知道怎么就好了,最后用的instant-ngp是:NVlabs/instant-ngp: Instant neural graphics primitives: lightning fast NeRF and more (github.com)

烦死了!!!!!困扰了我两三天!!!!! 

cmake --build build_ngp --config RelWithDebInfo -j2

 好的!还是不行

编译gtsam

 先下载https://github.com/ToniRV/gtsam-1.git

 然后替换掉NeRF_SLAM/thirdparty目录下的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
cd python
python setup.py install

这一个不难,就是时间比较久

ok!我从头开始!因为我一开始的NeRF_SLAM是从windows下载之后,ssh到linux上面的,我发现这样子做可能会导致出现一些问题!就是有些依赖没下载到!所以这一次!

十、重新下载源码

git clone https://github.com/ToniRV/NeRF-SLAM.git --recurse-submodules
git submodule update --init --recursive

 我觉得!成功在望!!!!!!

真是不一样的!下载出来的thirdparty里面的instant-ngp和gtsam都不是空白文件夹!!

这样子,就只需要替换掉gtsam就行了

 毁灭吧,去*吧

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值