Ubuntu20.04复现instant-nsr-pl和unisurf(nerf表面重建应用)

ps:主要是复现nerf曲面重建的应用,instant-nsr-pl和instant-ngp相似,都可以快速的进行训练,instant-nsr-pl借鉴了neus和instant-ngp,使表面重建更加的快速,得到的模型效果也十分不错。unisurf是nerf表面重建应用比较早的一篇文章,为了进一步研究神经隐式曲面重建也复现了一下,便于后续的学习。


目录

一、复现instant-nsr-pl

1、环境配置

2、训练

NeRF-Synthetic数据集训练

DTU 数据集训练

3、测试

二、复现unisurf

1、环境配置

2、训练

数据集获取:

从头开始训练模型(以DTU数据集scan0024为例): 

从训练过的模型中提取网格:

从预训练模型中提取网格


一、复现instant-nsr-pl

参考链接:https://github.com/bennyguo/instant-nsr-pl

下载项目:

git clone https://github.com/bennyguo/instant-nsr-pl

1、环境配置

安装tiny-cuda-nn扩展:

pip install git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch
pytorch>=1.10
pytorch-lightning<2
omegaconf==2.2.3
nerfacc==0.3.3
matplotlib
opencv-python
imageio
imageio-ffmpeg
scipy
PyMCubes
pyransac3d
torch_efficient_distloss
tensorboard
trimesh

---------------------------------------------------------------------------------
简洁安装:
cd instant-nsr-pl
pip install -r requirements.txt

2、训练

数据集准备:下载 NeRF-Synthetic 数据并将其放在load/. 文件结构应该类似于load/nerf_synthetic/lego.

NeRF-Synthetic数据集训练 

数据集下载链接:https://drive.google.com/drive/folders/128yBriW1IG_3NJ5Rp7APSTZsJqdJdfc1

# train NeRF
python launch.py --config configs/nerf-blender.yaml --gpu 0 --train dataset.scene=lego tag=example

# train NeuS with mask(有掩码监督)
python launch.py --config configs/neus-blender.yaml --gpu 0 --train dataset.scene=lego tag=example
# train NeuS without mask(无掩码监督)
python launch.py --config configs/neus-blender.yaml --gpu 0 --train dataset.scene=lego tag=example system.loss.lambda_mask=0.0

DTU数据集训练 

数据集下载链接:https://drive.google.com/drive/folders/1Nlzejs4mfPuJYORLbDEUDWlc9IZIbU0C

# train NeuS on DTU without mask(无掩码监督)
python launch.py --config configs/neus-dtu.yaml --gpu 0 --train
# train NeuS on DTU with mask(有掩码监督)
python launch.py --config configs/neus-dtu-wmask.yaml --gpu 0 --train
# train NeuS on DTU with mask using tricks from Neuralangelo (experimental)
python launch.py --config configs/neuralangelo-dtu-wmask.yaml --gpu 0 --train

无掩码监督scan0063 无掩码监督scan00624
有掩码监督scan0024 using tricks from Neuralangelo

渲染的视频:

instant-nsr-pl

ps:如果想换个场景进行训练的话需要修改configs文件夹里对应的.yaml文件中的root_dir

3、测试

以DTU数据集scan0024有掩码监督为例

(nsr) wxy@wxy:~/instant-nsr-pl$ python launch.py --config configs/neus-dtu-wmask.yaml --resume exp/neus-dtu-wmask-dtu_scan24/@20230625-170809/ckpt/epoch=0-step=20000.ckpt --gpu 0 --test
有掩码监督测试下scan0024结果

 


 

二、复现unisurf

参考链接: https://github.com/autonomousvision/unisurf

下载项目: 

git clone https://github.com/autonomousvision/unisurf

1、环境配置

可以创建一个名为unisurf的 anaconda 环境

conda env create -f environment.yaml
conda activate unisurf

接下来,编译扩展模块。

python setup.py build_ext --inplace

或者手动创建环境安装所需要的包:

name: unisurf
channels:
  - pytorch
  - conda-forge
  - anaconda
  - defaults
dependencies:
  - python
  - pytorch 
  - torchvision 
  - torchaudio 
  - cudatoolkit=10.2
  - cffi
  - cython
  - imageio
  - numpy
  - scipy
  - matplotlib
  - pandas
  - tensorboard
  - yaml
  - pillow
  - wheel
  - pip
  - tqdm
  - pip:
    - ipdb
    - ipython
    - ipython-genutils
    - jedi
    - opencv-python
    - scikit-image
    - pyyaml
    - trimesh

2、训练

数据集获取:

要下载预处理的数据,请运行以下脚本:
source ./download_dataset.sh

从头开始训练模型(以DTU数据集scan0024为例): 

python train.py configs/DTU/scan0024.yaml
训练五十万次后得到渲染的视图

在训练过程中也可以使用tensorboard来观察损失的变化

tensorboard --logdir ./out --port 6006

从训练的模型中提取网格:

需要修改scan0024.yaml文件中的内容,在configs/DTU/scan0024.yaml中要设置一下extraction的路径,在scan0024.yaml的最后添加以下内容:

extraction:
  model_file: /home/wxy/unisurf/out/DTU/scan0024/model_500000.pt

之后在终端运行以下命令:

python extract_mesh.py configs/DTU/scan0024.yaml 
训练五十万次后得到的mesh

从预训练模型中提取网格

如果只想从预先训练的模型中快速提取网格,可以使用以下命令运行:

python extract_mesh.py configs/DTU_pre/scan0065.yaml 

所有的输出均在out文件夹中,预训练提取的网格在out/scan0065/中   

从预训练模型中提取的mesh

猜你喜欢

转载自blog.csdn.net/weixin_59961223/article/details/131381690
今日推荐