本文参考&致谢:
【3DGS】Ubuntu20.04系统搭建3D Gaussian Splatting及可视化环境_ubuntu 3dgs安装-CSDN博客
Ubuntu20.04 3DGS复现全流程_ubuntu20.04安装3dgs-CSDN博客
代码来源:
基础环境:
1. ubuntu 20.04,架构x86_64
hostnamectl
(base) root@test:~$ hostnamectl
Icon name: computer-desktop
Chassis: desktop
Operating System: Ubuntu 20.04.6 LTS
Kernel: Linux 5.15.0-117-generic
Architecture: x86-64
2. g++和gcc,输入g++ -v和gcc -v
g++ -v
gcc -v
(base) root@test:~$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ......
Thread model: posix
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.2)
(base) root@test:~$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ..........
Thread model: posix
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.2)
3. 显卡驱动版本535.183.01,
nvidia-smi
4. CUDA版本11.8
nvcc -V
(base) root@test:~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:33:58_PDT_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0
CUDA如果已下载,跳过以下的下载过程:
(1) CUDA11.8版本下载
下载地址https://developer.nvidia.com/cuda-11-8-0-download-archive
(2) 输入图中的命令sudo sh cuda_11.8.0_520.61.05_linux.run后,等待一会,出现以下命令框,选择continue
(3) 输入accept
(4) 如果已安装显卡驱动(见上)且驱动版本满足CUDA11.8的要求,要取消勾选Driver
(5) 等待安装。安装成功后,输入以下命令:
ls /usr/local/
(base) root@test:~$ ls /usr/local/
bin cuda cuda-11.8 etc games include lib man sbin share src sunlogin
(6) 可以看到已经成功安装cuda-11.8,但还需要配置环境变量
vim ~/.bashrc
(base) root@test:~$ vim ~/.bashrc
(7) 添加以下环境变量内容(重要)
export PATH=/usr/local/cuda-11.8/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
(8) 添加完后,输入nvcc -V,可看到cuda版本信息
nvcc -V
(base) root@test:~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:33:58_PDT_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0
(9) 输入which nvcc,可看到nvcc安装位置
which nvcc
(base) root@test:~$ which nvcc
/usr/local/cuda-11.8/bin/nvcc
至此,CUDA安装成功
配置3D Gaussian Splatting环境
1. 拉取github代码,注意带上--recursive后缀(会拉取子模块的代码)。
git clone https://github.com/graphdeco-inria/gaussian-splatting --recursive
2. 拉取后查看以下两个文件夹中 是否是非空
gaussian-splatting/submodules/diff-gaussian-rasterization
gaussian-splatting/submodules/diff-gaussian-rasterization/third_party/glm
3. 查看environment.yaml文件 原内容
name: gaussian_splatting
channels:
- pytorch
- conda-forge
- defaults
dependencies:
- cudatoolkit=11.6
- plyfile
- python=3.7.13
- pip=22.3.1
- pytorch=1.12.1
- torchaudio=0.12.1
- torchvision=0.13.1
- tqdm
- pip:
- submodules/diff-gaussian-rasterization
- submodules/simple-knn
4. 本文不采用以上配置,因为在执行pip submodules时,可能会卡住。
(1) 分别执行命令:
cd gaussian-splatting
conda create -n gaussian_splatting python=3.8
conda activate gaussian_splatting
(2) 安装torch,Previous PyTorch Versions | PyTorch
pip install torch==2.0.0 torchvision==0.15.1 torchaudio==2.0.1 --index-url https://download.pytorch.org/whl/cu118
经过漫长地等待,输入以下命令验证torch 和CUDA可用
python
import torch
print(torch.cuda.is_available())
exit()
(gaussian_splatting) root@test:~/postg/thesis/gaussian-splatting$ python
Python 3.7.13 (default, Oct 18 2022, 18:57:03)
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print(torch.cuda.is_available())
True>>> exit()
(3) 执行安装子模块,这一步容易报错
pip install submodules/diff-gaussian-rasterization
pip install submodules/simple-knn
可能会报错,报错信息:
cc1plus: fatal error: cuda_runtime.h: No such file or directory
gcc: fatal error: cannot execute ‘cc1plus’: execvp: No such file or directory
先查看是否已安装c语言编译环境(见上)
gcc -v
g++ -v
如果已安装,再查看是否已配置bashrc中的环境变量(见上)
export PATH=/usr/local/cuda-11.8/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
(4) 执行安装剩余包
pip install plyfile tqdm
下载数据集并训练
参考 下面链接中的【下载数据集并训练】【3DGS】Ubuntu20.04系统搭建3D Gaussian Splatting及可视化环境_ubuntu 3dgs安装-CSDN博客
下载后的数据集 tandt_db.zip 如下,并新建data文件夹,将 tandt_db.zip 其中的truck文件复制到data文件夹中
python train.py -s data/truck/ data/output
会自动生成输出结果文件夹,结果的树结构如下
(base) root@test:~/postg/thesis/gaussian-splatting/data$ tree output
output
├── cameras.json
├── cfg_args
├── input.ply
└── point_cloud
├── iteration_30000
│ └── point_cloud.ply
└── iteration_7000
└── point_cloud.ply4 directories, 5 files
可视化结果
gaussian-splatting文件夹中SIBR_viewers是用来可视化结果的应用,可用于ubuntu下的可视化
ubuntu下的可视化配置麻烦(以后实现),本文直接在Windows下进行可视化,将 结果文件 output 打包为zip并复制到Windows系统下(可通过mobaxterm软件进行传递,且无需打包)。注意,Windows下的显卡算力要大于7.0,https://developer.nvidia.com/cuda-gpus 查看
Windows下的可视化SIBR_viewers应用下载https://repo-sam.inria.fr/fungraph/3d-gaussian-splatting/binaries/viewers.zip
将output文件移动至viewers下
cmd命令
.\bin\SIBR_gaussianViewer_app.exe -m .\output
等待,即可视化成功