该存储库包含:
新闻:重点是静态场景的静态内部重建的干净而改进的版本已分为nerf_template,因为该存储库很难维护。
Instant-NGP互动培训/渲染乐高:
也是第一个交互式可变形-NERF的实现:
NGP_PL:Pytorch+CUDA接受了pytorch-lightning训练。
JNERF:基于Jittor的NERF基准。
Hashnerf-Pytorch:纯Pytorch实现。
Dreamfields-Torch:Pytorch+CUDA实现了基于此存储库的梦想字段的零击文本引导对象生成。
git clone --recursive https://github.com/ashawkey/torch-ngp.git
cd torch-ngppip install -r requirements.txt
# (optional) install the tcnn backbone
pip install git+https://github.com/NVlabs/tiny-cuda-nn/ # subdirectory=bindings/torchconda env create -f environment.yml
conda activate torch-ngp默认情况下,我们使用load在运行时构建扩展名。但是,这有时可能会带来不便。因此,我们还提供了setup.py来构建每个扩展:
# install all extension modules
bash scripts/install_ext.sh
# if you want to install manually, here is an example:
cd raymarching
python setup.py build_ext --inplace # build ext only, do not install (only can be used in the parent directory)
pip install . # install to python path (you still need the raymarching/ folder, since this only install the built extension.)当前, --ff仅支持使用CUDA架构>= 70 GPU。对于具有较低体系结构的GPU,仍然可以使用--tcnn ,但是与最近的GPU相比,速度将较慢。
我们使用与Instant-NGP,EG,Armadillo和Fox相同的数据格式。请下载并将它们放在./data下。
我们还支持自捕获的数据集并将其他格式(例如LLFF,坦克和寺庙,MIP-NERF 360)转换为NERF兼容格式,并在以下代码块中提供详细信息。
nerf_synthetic
坦克和神庙:[转换脚本]
llff:[转换脚本]
MIP-NERF 360:[转换脚本]
(动态)d-nerf
(动态)Hyper-nerf:[转换脚本]
首次运行将需要一些时间来编译CUDA扩展。
# ## Instant-ngp NeRF
# train with different backbones (with slower pytorch ray marching)
# for the colmap dataset, the default dataset setting `--bound 2 --scale 0.33` is used.
python main_nerf.py data/fox --workspace trial_nerf # fp32 mode
python main_nerf.py data/fox --workspace trial_nerf --fp16 # fp16 mode (pytorch amp)
python main_nerf.py data/fox --workspace trial_nerf --fp16 --ff # fp16 mode + FFMLP (this repo's implementation)
python main_nerf.py data/fox --workspace trial_nerf --fp16 --tcnn # fp16 mode + official tinycudann's encoder & MLP
# use CUDA to accelerate ray marching (much more faster!)
python main_nerf.py data/fox --workspace trial_nerf --fp16 --cuda_ray # fp16 mode + cuda raymarching
# preload data into GPU, accelerate training but use more GPU memory.
python main_nerf.py data/fox --workspace trial_nerf --fp16 --preload
# one for all: -O means --fp16 --cuda_ray --preload, which usually gives the best results balanced on speed & performance.
python main_nerf.py data/fox --workspace trial_nerf -O
# test mode
python main_nerf.py data/fox --workspace trial_nerf -O --test
# construct an error_map for each image, and sample rays based on the training error (slow down training but get better performance with the same number of training steps)
python main_nerf.py data/fox --workspace trial_nerf -O --error_map
# use a background model (e.g., a sphere with radius = 32), can supress noises for real-world 360 dataset
python main_nerf.py data/firekeeper --workspace trial_nerf -O --bg_radius 32
# start a GUI for NeRF training & visualization
# always use with `--fp16 --cuda_ray` for an acceptable framerate!
python main_nerf.py data/fox --workspace trial_nerf -O --gui
# test mode for GUI
python main_nerf.py data/fox --workspace trial_nerf -O --gui --test
# for the blender dataset, you should add `--bound 1.0 --scale 0.8 --dt_gamma 0`
# --bound means the scene is assumed to be inside box[-bound, bound]
# --scale adjusts the camera locaction to make sure it falls inside the above bounding box.
# --dt_gamma controls the adaptive ray marching speed, set to 0 turns it off.
python main_nerf.py data/nerf_synthetic/lego --workspace trial_nerf -O --bound 1.0 --scale 0.8 --dt_gamma 0
python main_nerf.py data/nerf_synthetic/lego --workspace trial_nerf -O --bound 1.0 --scale 0.8 --dt_gamma 0 --gui
# for the LLFF dataset, you should first convert it to nerf-compatible format:
python scripts/llff2nerf.py data/nerf_llff_data/fern # by default it use full-resolution images, and write `transforms.json` to the folder
python scripts/llff2nerf.py data/nerf_llff_data/fern --images images_4 --downscale 4 # if you prefer to use the low-resolution images
# then you can train as a colmap dataset (you'll need to tune the scale & bound if necessary):
python main_nerf.py data/nerf_llff_data/fern --workspace trial_nerf -O
python main_nerf.py data/nerf_llff_data/fern --workspace trial_nerf -O --gui
# for the Tanks&Temples dataset, you should first convert it to nerf-compatible format:
python scripts/tanks2nerf.py data/TanksAndTemple/Family # write `trainsforms_{split}.json` for [train, val, test]
# then you can train as a blender dataset (you'll need to tune the scale & bound if necessary)
python main_nerf.py data/TanksAndTemple/Family --workspace trial_nerf_family -O --bound 1.0 --scale 0.33 --dt_gamma 0
python main_nerf.py data/TanksAndTemple/Family --workspace trial_nerf_family -O --bound 1.0 --scale 0.33 --dt_gamma 0 --gui
# for custom dataset, you should:
# 1. take a video / many photos from different views
# 2. put the video under a path like ./data/custom/video.mp4 or the images under ./data/custom/images/*.jpg.
# 3. call the preprocess code: (should install ffmpeg and colmap first! refer to the file for more options)
python scripts/colmap2nerf.py --video ./data/custom/video.mp4 --run_colmap # if use video
python scripts/colmap2nerf.py --images ./data/custom/images/ --run_colmap # if use images
python scripts/colmap2nerf.py --video ./data/custom/video.mp4 --run_colmap --dynamic # if the scene is dynamic (for D-NeRF settings), add the time for each frame.
# 4. it should create the transform.json, and you can train with: (you'll need to try with different scale & bound & dt_gamma to make the object correctly located in the bounding box and render fluently.)
python main_nerf.py data/custom --workspace trial_nerf_custom -O --gui --scale 2.0 --bound 1.0 --dt_gamma 0.02
# ## Instant-ngp SDF
python main_sdf.py data/armadillo.obj --workspace trial_sdf
python main_sdf.py data/armadillo.obj --workspace trial_sdf --fp16
python main_sdf.py data/armadillo.obj --workspace trial_sdf --fp16 --ff
python main_sdf.py data/armadillo.obj --workspace trial_sdf --fp16 --tcnn
python main_sdf.py data/armadillo.obj --workspace trial_sdf --fp16 --test
# ## TensoRF
# almost the same as Instant-ngp NeRF, just replace the main script.
python main_tensoRF.py data/fox --workspace trial_tensoRF -O
python main_tensoRF.py data/nerf_synthetic/lego --workspace trial_tensoRF -O --bound 1.0 --scale 0.8 --dt_gamma 0
# ## CCNeRF
# training on single objects, turn on --error_map for better quality.
python main_CCNeRF.py data/nerf_synthetic/chair --workspace trial_cc_chair -O --bound 1.0 --scale 0.67 --dt_gamma 0 --error_map
python main_CCNeRF.py data/nerf_synthetic/ficus --workspace trial_cc_ficus -O --bound 1.0 --scale 0.67 --dt_gamma 0 --error_map
python main_CCNeRF.py data/nerf_synthetic/hotdog --workspace trial_cc_hotdog -O --bound 1.0 --scale 0.67 --dt_gamma 0 --error_map
# compose, use a larger bound and more samples per ray for better quality.
python main_CCNeRF.py data/nerf_synthetic/hotdog --workspace trial_cc_hotdog -O --bound 2.0 --scale 0.67 --dt_gamma 0 --max_steps 2048 --test --compose
# compose + gui, only about 1 FPS without dynamic resolution... just for quick verification of composition results.
python main_CCNeRF.py data/nerf_synthetic/hotdog --workspace trial_cc_hotdog -O --bound 2.0 --scale 0.67 --dt_gamma 0 --test --compose --gui
# ## D-NeRF
# almost the same as Instant-ngp NeRF, just replace the main script.
# use deformation to model dynamic scene
python main_dnerf.py data/dnerf/jumpingjacks --workspace trial_dnerf_jumpingjacks -O --bound 1.0 --scale 0.8 --dt_gamma 0
python main_dnerf.py data/dnerf/jumpingjacks --workspace trial_dnerf_jumpingjacks -O --bound 1.0 --scale 0.8 --dt_gamma 0 --gui
# use temporal basis to model dynamic scene
python main_dnerf.py data/dnerf/jumpingjacks --workspace trial_dnerf_basis_jumpingjacks -O --bound 1.0 --scale 0.8 --dt_gamma 0 --basis
python main_dnerf.py data/dnerf/jumpingjacks --workspace trial_dnerf_basis_jumpingjacks -O --bound 1.0 --scale 0.8 --dt_gamma 0 --basis --gui
# for the hypernerf dataset, first convert it into nerf-compatible format:
python scripts/hyper2nerf.py data/split-cookie --downscale 2 # will generate transforms*.json
python main_dnerf.py data/split-cookie/ --workspace trial_dnerf_cookies -O --bound 1 --scale 0.3 --dt_gamma 0检查scripts目录以获取更多提供的示例。
使用乐高数据集上的默认设置进行了测试。在这里,速度是指V100上的iterations per second 。
| 模型 | 分裂 | psnr | 火车速度 | 测试速度 |
|---|---|---|---|---|
| Instant-NGP(纸) | trainval? | 36.39 | - | - |
instant -ngp( -O ) | 火车(30k步骤) | 34.15 | 97 | 7.8 |
instant -ngp( -O --error_map ) | 火车(30k步骤) | 34.88 | 50 | 7.8 |
instant -ngp( -O ) | Trainval(40k步骤) | 35.22 | 97 | 7.8 |
instant -ngp( -O --error_map ) | Trainval(40k步骤) | 36.00 | 50 | 7.8 |
| tensorf(纸) | 火车(30k步骤) | 36.46 | - | - |
tensorf( -O ) | 火车(30k步骤) | 35.05 | 51 | 2.8 |
tensorf( -O --error_map ) | 火车(30k步骤) | 35.84 | 14 | 2.8 |
问:如何选择网络骨干?
答:使用Pytorch的本机混合精度的-O标志适用于大多数情况。我没有发现--tcnn和--ff的明显改进,它们需要额外的建筑物。另外,某些新功能可能仅适用于默认-O模式。
问:我的数据集中的CUDA不记忆。
答:您可以尝试关闭--preload将所有图像加载到GPU中以进行加速(如果使用-O ,将其更改为--fp16 --cuda_ray )。另一个解决方案是在NeRFDataset中手动设置downscale ,以降低图像分辨率。
问:如何调整bound和scale ?
答:您可以从较大的bound (例如16)或小scale (例如0.3)开始,以确保对象落入边界框中。 GUI模式可用于互动缩小bound以找到合适的值。删除这条线将可视化相机的姿势,并且在本期中可以找到一些好的示例。
问:现实数据集的嘈杂的新颖观点。
答:您可以尝试将bg_radius设置为一个大价值,例如32。它训练额外的环境图,以对现实照片中的背景进行建模。更大的bound也将有所帮助。 firekeperer数据集中bg_radius的一个示例: 
[0, 1]中界定并以(0.5, 0.5, 0.5)为中心,而是假设场景在框中[-bound, bound] ,并以(0, 0, 0)为中心。因此, aabb_scale的功能被此处的bound替换。trunc_exp作为密度激活而不是softplus 。 Alpha蒙版修剪被Instant-NGP的密度网格采样器取代,该密度抽样器具有相同的加速逻辑。如果您觉得这项工作有用,将通过以下方式赞赏引用:
@misc{torch-ngp,
Author = {Jiaxiang Tang},
Year = {2022},
Note = {https://github.com/ashawkey/torch-ngp},
Title = {Torch-ngp: a PyTorch implementation of instant-ngp}
}
@article{tang2022compressible,
title = {Compressible-composable NeRF via Rank-residual Decomposition},
author = {Tang, Jiaxiang and Chen, Xiaokang and Wang, Jingbo and Zeng, Gang},
journal = {arXiv preprint arXiv:2205.14870},
year = {2022}
}
信用托马斯·穆勒(ThomasMüller
@misc{tiny-cuda-nn,
Author = {Thomas M"uller},
Year = {2021},
Note = {https://github.com/nvlabs/tiny-cuda-nn},
Title = {Tiny {CUDA} Neural Network Framework}
}
@article{mueller2022instant,
title = {Instant Neural Graphics Primitives with a Multiresolution Hash Encoding},
author = {Thomas M"uller and Alex Evans and Christoph Schied and Alexander Keller},
journal = {arXiv:2201.05989},
year = {2022},
month = jan
}
NERF的框架从nerf_pl:
@misc{queianchen_nerf,
author = {Quei-An, Chen},
title = {Nerf_pl: a pytorch-lightning implementation of NeRF},
url = {https://github.com/kwea123/nerf_pl/},
year = {2020},
}
官方的Tensorf实施:
@article{TensoRF,
title={TensoRF: Tensorial Radiance Fields},
author={Chen, Anpei and Xu, Zexiang and Geiger, Andreas and Yu, Jingyi and Su, Hao},
journal={arXiv preprint arXiv:2203.09517},
year={2022}
}
Nerf Gui是由Dearpygui开发的。