Ubuntu 18 installation nerfstudio tutorial, stepping on the pit record

Write it first! ! ! Configuring nerfstudio requires cuda, but there is no cuda, please don’t read further. The official cuda requirement is 11.3 or 11.7. I use Alibaba Cloud’s 11.4 pro-test and it is available.

1. Configuration environment

install anaconda3

Go to the official website or mirror to download the execution file of anaconda3

Official website: anaconda official website

Tsinghua Mirror: Tsinghua University Open Source Software Mirror Station

After downloading, execute the following code:

bash Anaconda3-2023.03-1-Linux-x86_64.sh

Wait for the word (base) to appear after the installation is complete, and then follow the nerfstudio documentation to create a virtual environment:

conda create --name nerfstudio -y python=3.8
conda activate nerfstudio
python -m pip install --upgrade pip

After creating the environment, you need to install torch. Here we take cuda11.3 as an example:

pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 -f https://download.pytorch.org/whl/torch_stable.html

If it is cuda11.7 use this command:

pip uninstall torch torchvision functorch

pip install torch==1.13.1 torchvision functorch --extra-index-url https://download.pytorch.org/whl/cu117

Update from 2023.6.20

The update of the nerfstudio official document has been adapted to cuda11.8. If it is a new graphics card (such as 4090, etc.), you can use cuda11.8

cuda11.8 and pytorch2.0.1 are installed as follows:

pip uninstall torch torchvision functorch tinycudann

pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 --extra-index-url https://download.pytorch.org/whl/cu118

Install tinycudann

pip install ninja git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch

Notice! When installing tinycudann, it may be impossible to pull from github due to domestic reasons, and it will appear

"The TLS connection was non-properly terminated." Such an error, I use the following command:

git config --global --unset http.proxy 
git config --global --unset https.proxy

But sometimes there will be problems, I also refer to this article: Zhihu

After installing tinycudann, you can install nerfstudio according to the documentation:

pip install nerfstudio

Notice! When using the above command, it will automatically uninstall the above torch and install other versions (unless you are 11.3), otherwise after executing the above command, execute the following command to reinstall torch1.12:

pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 -f https://download.pytorch.org/whl/torch_stable.html

2023.6.20 update:

According to the pytorch2.0.1 update document, the api of functorch has been changed and no additional installation is required. Therefore, if you have installed cuda11.7/11.8+pytorch2.0.1, you don’t need to install functorch

If it is cuda11.3+torch1.12, you need to install a new dependency after the installation is complete:

pip install functorch==0.2.1

Notice! Do not use pip install functorch directly, it will automatically uninstall torch, just install the specified version directly.

So far the basic framework of nerfstudio has been installed.

You can try it with the demo of the official document:

# Download some test data:
ns-download-data nerfstudio --capture-name=poster

# Train model
ns-train nerfacto --data data/nerfstudio/poster

When executing the first line of command, because the data is fetched directly from the google drive, the server in China may have an error. My server is in a foreign country, so it can be used directly. If it doesn’t work, don’t worry, it may not be you Wrong! !

Here I take mine as an example. After running successfully, the following screen appears:

Then we use the link given to view the results remotely on our computer using the viewer.

First copy the above link into our browser (our link may be different, please refer to your own)

We also need to connect our computer to a remote server. My own computer is Windows, and here is the method:

 Open the powershell of windows

Enter as follows, username is the username of the server remote-machine-ip is the public IP address of the server

ssh -L 7007:localhost:7007 <username>@<remote-machine-ip>

After the link is completed, open the webpage and you can see the demo:

 Of course, I know that you may want to use your own data, so the official method is also given:

 Since I am using image data, I have to install colmap and ffmpeg again.

Install ffmpeg and execute the following command:

sudo apt install ffmpeg

2. Install colmap

Installing colmap is the most troublesome. The official document gives the method of installing colmap:

sudo apt install colmap

But after my test, after I install colmap using this method, "Shader not supported by your hardware!" and "SiftGPU not fully supported!" will appear during feature extraction

So I refer to this article: CSDN  re-download and compile colmap 

According to the official documentation, do the following:

sudo apt-get install \
    git \
    cmake \
    ninja-build \
    build-essential \
    libboost-program-options-dev \
    libboost-filesystem-dev \
    libboost-graph-dev \
    libboost-system-dev \
    libboost-test-dev \
    libeigen3-dev \
    libflann-dev \
    libfreeimage-dev \
    libmetis-dev \
    libgoogle-glog-dev \
    libgflags-dev \
    libsqlite3-dev \
    libglew-dev \
    qtbase5-dev \
    libqt5opengl5-dev \
    libcgal-dev \
    libceres-dev

In addition, if you are using the Ubuntu 18 version like me, you need to add additional commands:

sudo apt-get install libcgal-qt5-dev

sudo apt -y install liblz4-dev

Notice! ! ! !

Then rename the anaconda folder! Rename the anaconda folder! Rename the anaconda folder!

This is to prevent the anaconda environment from affecting the subsequent compilation. After the modification, re-enter the terminal. At this time, if the previous (base) is gone, it proves that it has been changed.

update cmake

The above command has automatically installed cmake, but it is installed cmake3.10. If you use this version to compile later, there will be problems. After my test, using cmake 3.26.0 can pass. Then update cmake.

First download the new version of cmake:

wget https://cmake.org/files/v3.26/cmake-3.26.0-linux-x86_64.tar.gz

Unzip:

tar zxvf cmake-3.26.0-linux-x86_64.tar.gz

Delete the old version of cmake (here you can choose to delete directly or copy the file away and delete it):

sudo rm -rf /usr/bin/cmake  #(删除原本cmake 也可复制保存) 

Notice! My cmake is under this file, please find the file directory of your own cmake!

Create a soft link:

sudo ln -s /root/cmake-3.26.0-linux-x86_64/bin/cmake /usr/bin/cmake

Notice! : /root/cmake-3.26.0-linux-x86_64/bin/cmake is the cmake path after decompression  

/usr/bin/cmake is the original cmake path

Then enter cmake --version to view the version of cmake

compile colmap

First clone the source file:

git clone https://github.com/colmap/colmap.git

Then:

cd colmap
git checkout dev
mkdir build
cd build

Notice! What I need is the cuda version of colmap, so I need to specify my cuda. ​​According to the official documentation and the method of referring to Zhihu , enter the following command in the build directory, /usr/local/cuda/bin/nvcc needs to be changed to your own cuda file directory

sudo cmake .. -D CMAKE_CUDA_COMPILER="/usr/local/cuda-11.4/bin/nvcc" ../CMakeLists.txt -D CMAKE_CUDA_ARCHITECTURES='native'

After waiting for completion, a Makefile file will be generated in the build directory. In this file directory, execute the following command:

make
sudo make install

The make command takes a long time, so you need to wait patiently. Wait until 100% and then execute sudo make install

Then try the colmap command:

 Successful installation.

3. Use your own data

The official documentation gives commands to use your own data, as follows:

ns-process-data {video,images,polycam,record3d} --data {DATA_PATH} --output-dir {PROCESSED_DATA_DIR}

The first parameter is to specify the input data format such as image video, etc.,

The second parameter is the specified source data location

The third parameter is to specify the position of the data processed by colmap

Taking my own data as an example, I use image data for:

ns-process-data images --data /root/data/pt007 --output-dir /root/processed_data/pt007

After the processing is completed, use the following command to perform nerf 3D reconstruction:

ns-train nerfacto --data {PROCESSED_DATA_DIR}

 If you need to rebuild the mesh model, you need to add:

ns-train nerfacto --pipeline.model.predict-normals True --data {PROCESSED_DATA_DIR}

Reference article:

1. Git error: The TLS connection was non-properly terminated._Blue Rain Feiyang 7 Blog-CSDN Blog

2. Linux Colmap error "Shader not supported by your hardware!" and "SiftGPU .....

3. Install other versions of cmake or upgrade cmake on Linux

4. The configuration of COLMAP3.8 under Ubuntu18.04- Know about

5、nvcc fatal : Unknown option 'fPIC' · Issue #1753 · colmap/colmap · GitHub

6. Jizhi Development | The method to solve the slow or failed git clone on linux-Knowledge

7、nerf studio

8、Installation — COLMAP 3.8-dev documentation

So far, the installation and use of nerfstudio have been completed, and it took me two or three days to complete the configuration. I feel that the network is a big problem, and domestic git clones are often prone to errors. In addition, there are few wrong guidelines in the document, and there are few people who use nerfstudio, so I will record my own installation and stepping on the pit to help everyone.

Guess you like

Origin blog.csdn.net/JimKudou/article/details/130564808