Ubuntu22.04 reproduces NeRF_SLAM

cmake version: 3.22.1

cuda version: 11.5

Abstract

This is a 3D scene reconstruction algorithm that combines monocular dense SLAM and hierarchical voxel neural radiation fields. It can achieve accurate radiation field construction using image sequences in real time and does not require pose or depth input. The core idea of the paper is to use a monocular dense SLAM method to estimate the camera pose and dense depth map and their uncertainty, and use the above information as a supervision signal to train the NeRF scene representation.

1. Update system software source

Backup configuration file /etc/apt/sources.list

sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
//Back up the software source configuration file

Edit configuration file

sudo vim /etc/apt/sources.list //Edit the configuration file and enter the command mode
/***Basic usage of vim***
i enters editing (input) mode, at which time you can make changes to the file
Esc exits editing mode and enters command mode
: Enter the bottom line command mode with a colon before the command.
:w save file
:q exit edit mode
:wq Save file and exit edit mode
:q! Quit without saving (forced)

Reference: Ubuntu20.04 replacement software source_ubuntu20.04 software source-CSDN blog

2. Check the cuda version

Install

sudo apt install nvidia-cuda-toolkit

and then use

nvcc -V

You can check the cuda version:

3. Download the NeRF source code (see point 10, this is wrong)

Download the latest NeRF source code first

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

4. Install Anaconda

Index of /anaconda/archive/ | Tsinghua University Open Source Software Mirror Station | Tsinghua Open Source Mirror

I installed the latest version of https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2023.09-0-Linux-x86_64.sh

Install Anaconda3

bash Anaconda3-2022.10-Linux-x86_64.sh

The correct approach is: press Enter first, and then keep pressing s to go to the next page. Then ‘yes’ or ‘no’ will appear, and then press Enter again to install.

Add environment variables

sudo vim ~/.bashrc
//Add at the end of the pop-up text
//Remember to change username
export PATH="/home/username/anaconda3/bin:$PATH"

Everyone’s document is not exactly the same, just add it at the end of the document. Then: wq save and exit, source it to take effect.

source ~/.bashrc
//Check whether the installation is successful or not
conda --version

5. Add Tsinghua mirror source

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

6. Install dependencies

Create and activate a virtual environment

conda create -n NeRF_SLAM
source activate NeRF_SLAM

7. Install cmake3.22.6

Cmake version is required to be above 3.22, please refer to this blog
Install cmake3.22.6, https://cmake.org/files/v3.22/cmake-3.22.6-linux-x86_64.tar.gz, domestic source: Index of /files (cmake.org)

Delete old version

sudo apt autoremove cmake

The following errors may occur

error8.1 bash: /usr/bin/cmake: is a directory

error8.2 bash: /usr/bin/cmake: No such file or directory

error8.3 bash: /usr/bin/cmake: too many levels of symbolic links

error8.4 ln: cannot create symbolic link ‘/usr/bin/cmake’: file already exists

Solution:

8. Install pytorch

The version corresponding to cuda can be viewed with nvcc -V

Note that pytorch needs to download the version corresponding to 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

During the installation process, this will appear:

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)? 

My choice is yes, refer to What does The following packages will be SUPERCEDED by a higher-priority channel mean? – Missing Qianxun – Blog Garden (cnblogs.com)

Just replaces the priority of the source

9. Start compiling NerRF_SLAM

In the NeRF_SLAM directory, run

pip install -r requirements.txt
//Install required dependencies
pip install -r ./thirdparty/gtsam/python/requirements.txt
//Install required dependencies
pip install -r ./thirdparty/instant-ngp/requirements.txt
//Install required dependencies

When NeRF_SLAM runs and installs dependencies, a problem occurs:

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 ““, line 2, in File ““, line 34, in File “/tmp/pip-install-rd_djx6m/torch-scatter_be63210475ac42c2bcea49ffe6107bcb/setup.py”, line 8, in 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.

Solution:

Check whether torch is installed correctly: First make sure that PyTorch has been installed in your environment, and that the version of PyTorch is compatible with torch-scatter. You can install PyTorch using pip or conda, depending on your environment and needs.

For example, use conda to install PyTorch:

conda install pytorch torchvision torchaudio -c pytorch

Enter the NeRF_SLAM directory and run

error occurs

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
(wrong) solution:

conda install numpy=1.21.2

If you do this, you will get an error later:

ERROR: pip’s dependency resolver does not currently take into account all the packages that are installed. This behavior 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.
(Correct) solution:

conda install numpy=1.22.4

Compile instant-ngp (this step is the most difficult)

Play it by ear! ! ! ! ! ! ! I put all the ones I used below for reference.

Entering the next step, an error occurred when installing instant-ngp.

cmake ./thirdparty/instant-ngp -B build_ngp

I keep getting errors:

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”.

Reference 1: Ubuntu installation Ceres-Solver_Check whether ceres is installed according to z_Li Changhao’s blog-CSDN blog

Reference 2: Installation – Ceres Solver (ceres-solver.org)

Reference 3: ubuntu20.04 nerf Instant-ngp-CSDN Blog

Reference 4: If you cannot install cere2.2.0, install cere2.0.0 http://ceres-solver.org/ceres-solver-2.0.0.tar.gz

Reference 5: Ubuntu22.04 installs ceres-solver, cmake compilation error reports tbb_stddef.h-CSDN Blog

I was stupid. I didn’t know how to fix it in the end. The instant-ngp I finally used was: NVlabs/instant-ngp: Instant neural graphics primitives: lightning fast NeRF and more (github.com)

So annoying! ! ! ! ! It troubled me for two or three days! ! ! ! !

cmake --build build_ngp --config RelWithDebInfo -j2

OK! Or not

Compile gtsam

First download https://github.com/ToniRV/gtsam-1.git

Then replace gtsam in the NeRF_SLAM/thirdparty directory and change the name to gtsam

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

This one is not difficult, but it takes a long time

OK! I start from scratch! Because I originally downloaded NeRF_SLAM from windows and ssh it to linux, I found that doing this might cause some problems! It’s just that some dependencies were not downloaded! So this time!

10. Re-download the source code

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

I think! Success is in sight! ! ! ! ! !

What a difference! Neither instant-ngp nor gtsam in the downloaded thirdparty are blank folders! !

In this way, you only need to replace gtsam.

Destroy, go*