


https://www.nerfacc.com/
[新聞] 2023/04/04。如果您使用nerfacc <= 0.3.5 ,並且想遷移到我們的最新版本( nerfacc >= 0.5.0 ),請檢查有關如何遷移的變形值。
NERFACC是用於訓練和推理的Pytorch NERF加速工具箱。它專注於輻射場的體積渲染管道中的有效採樣,該輻射場是通用的,對於大多數NERF而言,它是通用的插件。隨著對現有代碼庫的最小修改,NERFACC在培訓各種NERF最近的論文方面提供了重大的加速。它是具有靈活API的純Python接口!

依賴性:請先安裝Pytorch。
寬鬆的方式是從PYPI安裝。這樣,它將在第一次運行(JIT)上構建CUDA代碼。
pip install nerfacc
或從源安裝。這樣,它將在安裝過程中構建CUDA代碼。
pip install git+https://github.com/nerfstudio-project/nerfacc.git
我們還提供了預先建造的車輪,涵蓋了Pytorch + CUDA的主要組合,並由官方Pytorch支持。
# e.g., torch 1.13.0 + cu117
pip install nerfacc -f https://nerfacc-bucket.s3.us-west-2.amazonaws.com/whl/torch-1.13.0_cu117.html
| Windows&Linux | cu113 | cu115 | cu116 | cu117 | cu118 |
|---|---|---|---|---|---|
| 火炬1.11.0 | ✅ | ✅ | |||
| 火炬1.12.0 | ✅ | ✅ | |||
| 火炬1.13.0 | ✅ | ✅ | |||
| 火炬2.0.0 | ✅ | ✅ |
對於先前版本的Nerfacc,請在支持的預製車輪上檢查此處。
NERFACC的想法是使用計算廉價估計器進行有效的體積採樣,以發現表面。因此,nerfacc可以與任何用戶定義的輻射字段一起使用。要將nerfacc渲染管道插入您的代碼並享受加速度,您只需要在射頻字段中定義兩個功能即可。
sigma_fn :每個樣品處的計算密度。估計器(例如nerfacc.OccGridEstimator , nerfacc.PropNetEstimator )將使用它來發現表面。rgb_sigma_fn :在每個樣品處計算顏色和密度。 nerfacc.rendering施用將使用它來進行可微分的容積渲染。此功能將接收梯度以更新您的輻射字段。一個簡單的例子是這樣:
import torch
from torch import Tensor
import nerfacc
radiance_field = ... # network: a NeRF model
rays_o : Tensor = ... # ray origins. (n_rays, 3)
rays_d : Tensor = ... # ray normalized directions. (n_rays, 3)
optimizer = ... # optimizer
estimator = nerfacc . OccGridEstimator (...)
def sigma_fn (
t_starts : Tensor , t_ends : Tensor , ray_indices : Tensor
) -> Tensor :
""" Define how to query density for the estimator."""
t_origins = rays_o [ ray_indices ] # (n_samples, 3)
t_dirs = rays_d [ ray_indices ] # (n_samples, 3)
positions = t_origins + t_dirs * ( t_starts + t_ends )[:, None ] / 2.0
sigmas = radiance_field . query_density ( positions )
return sigmas # (n_samples,)
def rgb_sigma_fn (
t_starts : Tensor , t_ends : Tensor , ray_indices : Tensor
) -> Tuple [ Tensor , Tensor ]:
""" Query rgb and density values from a user-defined radiance field. """
t_origins = rays_o [ ray_indices ] # (n_samples, 3)
t_dirs = rays_d [ ray_indices ] # (n_samples, 3)
positions = t_origins + t_dirs * ( t_starts + t_ends )[:, None ] / 2.0
rgbs , sigmas = radiance_field ( positions , condition = t_dirs )
return rgbs , sigmas # (n_samples, 3), (n_samples,)
# Efficient Raymarching:
# ray_indices: (n_samples,). t_starts: (n_samples,). t_ends: (n_samples,).
ray_indices , t_starts , t_ends = estimator . sampling (
rays_o , rays_d , sigma_fn = sigma_fn , near_plane = 0.2 , far_plane = 1.0 , early_stop_eps = 1e-4 , alpha_thre = 1e-2 ,
)
# Differentiable Volumetric Rendering.
# colors: (n_rays, 3). opacity: (n_rays, 1). depth: (n_rays, 1).
color , opacity , depth , extras = nerfacc . rendering (
t_starts , t_ends , ray_indices , n_rays = rays_o . shape [ 0 ], rgb_sigma_fn = rgb_sigma_fn
)
# Optimize: Both the network and rays will receive gradients
optimizer . zero_grad ()
loss = F . mse_loss ( color , color_gt )
loss . backward ()
optimizer . step ()在運行這些示例腳本之前,請檢查有關需要哪個數據集的腳本,然後先下載數據集。您可以使用--data_root來指定路徑。
# clone the repo with submodules.
git clone --recursive git://github.com/nerfstudio-project/nerfacc/請參閱此處的完整基準測試:https://www.nerfacc.com/en/stable/examples/static.html
在NERF合成數據集上即時NGP,在4.5分鐘內具有更好的性能。
# Occupancy Grid Estimator
python examples/train_ngp_nerf_occ.py --scene lego --data_root data/nerf_synthetic
# Proposal Net Estimator
python examples/train_ngp_nerf_prop.py --scene lego --data_root data/nerf_synthetic在MIP-NERF 360數據集上即時NGP,在5分鐘內具有更好的性能。
# Occupancy Grid Estimator
python examples/train_ngp_nerf_occ.py --scene garden --data_root data/360_v2
# Proposal Net Estimator
python examples/train_ngp_nerf_prop.py --scene garden --data_root data/360_v2一小時內,香草MLP NERF在NERF合成數據集上。
# Occupancy Grid Estimator
python examples/train_mlp_nerf.py --scene lego --data_root data/nerf_syntheticTensorf在坦克和寺廟和NERF合成數據集(官方代碼庫中的插件)上。
cd benchmarks/tensorf/
# (set up the environment for that repo)
bash script.sh nerfsyn-nerfacc-occgrid 0
bash script.sh tt-nerfacc-occgrid 0請參閱此處的完整基準測試:https://www.nerfacc.com/en/stable/examples/dynamic.html
在一個小時內在D-NERF數據集上進行T-NERF。
# Occupancy Grid Estimator
python examples/train_mlp_tnerf.py --scene lego --data_root data/dnerfD-NERF數據集(官方代碼庫中的插件)上的K-Planes。
cd benchmarks/kplanes/
# (set up the environment for that repo)
bash script.sh dnerf-nerfacc-occgrid 0Tineuvox在HyperNerf和D-Nerf數據集(官方代碼庫中的插件)上。
cd benchmarks/tineuvox/
# (set up the environment for that repo)
bash script.sh dnerf-nerfacc-occgrid 0
bash script.sh hypernerf-nerfacc-occgrid 0
bash script.sh hypernerf-nerfacc-propnet 0請參閱此處的完整基準測試:https://www.nerfacc.com/en/stable/examples/camera.html
NERF合成數據集(官方代碼庫中的插件)上的barf。
cd benchmarks/barf/
# (set up the environment for that repo)
bash script.sh nerfsyn-nerfacc-occgrid 0 @article { li2023nerfacc ,
title = { NerfAcc: Efficient Sampling Accelerates NeRFs. } ,
author = { Li, Ruilong and Gao, Hang and Tancik, Matthew and Kanazawa, Angjoo } ,
journal = { arXiv preprint arXiv:2305.04966 } ,
year = { 2023 }
}