


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 }
}