Giter Site home page Giter Site logo

nerfacc's Introduction

nerfacc logo

Core Tests Docs Downloads

https://www.nerfacc.com/

[News] 2023/04/04. If you were using nerfacc <= 0.3.5 and would like to migrate to our latest version (nerfacc >= 0.5.0), Please check the CHANGELOG on how to migrate.

NerfAcc is a PyTorch Nerf acceleration toolbox for both training and inference. It focus on efficient sampling in the volumetric rendering pipeline of radiance fields, which is universal and plug-and-play for most of the NeRFs. With minimal modifications to the existing codebases, Nerfacc provides significant speedups in training various recent NeRF papers. And it is pure Python interface with flexible APIs!

Teaser

Installation

Dependence: Please install Pytorch first.

The easist way is to install from PyPI. In this way it will build the CUDA code on the first run (JIT).

pip install nerfacc

Or install from source. In this way it will build the CUDA code during installation.

pip install git+https://github.com/nerfstudio-project/nerfacc.git

We also provide pre-built wheels covering major combinations of Pytorch + CUDA supported by official 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
torch 1.11.0
torch 1.12.0
torch 1.13.0
torch 2.0.0

For previous version of nerfacc, please check here on the supported pre-built wheels.

Usage

The idea of NerfAcc is to perform efficient volumetric sampling with a computationally cheap estimator to discover surfaces. So NerfAcc can work with any user-defined radiance field. To plug the NerfAcc rendering pipeline into your code and enjoy the acceleration, you only need to define two functions with your radience field.

  • sigma_fn: Compute density at each sample. It will be used by the estimator (e.g., nerfacc.OccGridEstimator, nerfacc.PropNetEstimator) to discover surfaces.
  • rgb_sigma_fn: Compute color and density at each sample. It will be used by nerfacc.rendering to conduct differentiable volumetric rendering. This function will receive gradients to update your radiance field.

An simple example is like this:

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()

Examples:

Before running those example scripts, please check the script about which dataset is needed, and download the dataset first. You could use --data_root to specify the path.

# clone the repo with submodules.
git clone --recursive git://github.com/nerfstudio-project/nerfacc/

Static NeRFs

See full benchmarking here: https://www.nerfacc.com/en/stable/examples/static.html

Instant-NGP on NeRF-Synthetic dataset with better performance in 4.5 minutes.

# 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

Instant-NGP on Mip-NeRF 360 dataset with better performance in 5 minutes.

# 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

Vanilla MLP NeRF on NeRF-Synthetic dataset in an hour.

# Occupancy Grid Estimator
python examples/train_mlp_nerf.py --scene lego --data_root data/nerf_synthetic

TensoRF on Tanks&Temple and NeRF-Synthetic datasets (plugin in the official codebase).

cd benchmarks/tensorf/
# (set up the environment for that repo)
bash script.sh nerfsyn-nerfacc-occgrid 0
bash script.sh tt-nerfacc-occgrid 0

Dynamic NeRFs

See full benchmarking here: https://www.nerfacc.com/en/stable/examples/dynamic.html

T-NeRF on D-NeRF dataset in an hour.

# Occupancy Grid Estimator
python examples/train_mlp_tnerf.py --scene lego --data_root data/dnerf

K-Planes on D-NeRF dataset (plugin in the official codebase).

cd benchmarks/kplanes/
# (set up the environment for that repo)
bash script.sh dnerf-nerfacc-occgrid 0

TiNeuVox on HyperNeRF and D-NeRF datasets (plugin in the official codebase).

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

Camera Optimization NeRFs

See full benchmarking here: https://www.nerfacc.com/en/stable/examples/camera.html

BARF on the NeRF-Synthetic dataset (plugin in the official codebase).

cd benchmarks/barf/
# (set up the environment for that repo)
bash script.sh nerfsyn-nerfacc-occgrid 0

3rd-Party Usages:

Awesome Codebases.

Awesome Papers.

Common Installation Issues

ImportError: .../csrc.so: undefined symbol If you are installing a pre-built wheel, make sure the Pytorch and CUDA version matchs with the nerfacc version (nerfacc.__version__).

Citation

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

nerfacc's People

Contributors

97littleleaf11 avatar 99sphere avatar arterms avatar bennyguo avatar brentyi avatar dozeri83 avatar edwardwli avatar ethanweber avatar frozensilent avatar junchenliu77 avatar linyou avatar liruilong940607 avatar loicmagne avatar lzhnb avatar machenmusik avatar mirmix avatar ph03 avatar sarafridov avatar sauravmaheshkar avatar tancik avatar thomasw21 avatar xiaoming-zhao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nerfacc's Issues

ImportError:cannot import name 'SceneManager' from 'scene_manager'

It works on lego dataset, but ween I try the llff dataset, There is an ImportError, could you please help me.
And I have seen the package in /root/miniconda3/envs/nerfacc/lib/python3.9/site-packages/scene_manager, There is nothing package such as SceneManager.
Thank you very much.

(nerfacc) root@container-0f5011ad3c-f66f17d1:~/autodl-tmp/nerfacc# python examples/train_mlp_nerf.py --scene garden --unbounded
Using unbounded rendering
Traceback (most recent call last):
File "/root/autodl-tmp/nerfacc/examples/train_mlp_nerf.py", line 113, in
from datasets.nerf_360_v2 import SubjectLoader
File "/root/autodl-tmp/nerfacc/examples/datasets/nerf_360_v2.py", line 22, in
from scene_manager import SceneManager
ImportError: cannot import name 'SceneManager' from 'scene_manager' (/root/miniconda3/envs/nerfacc/lib/python3.9/site-packages/scene_manager/init.py)

scene-manager 0.1.0

time.sleep

Could you please help me?

(nerfacc) lhx@lhx:~/NeRF/nerfacc$ /home/lhx/miniconda3/envs/nerfacc/bin/python /home/lhx/NeRF/nerfacc/examples/train_mlp_nerf.py
^CTraceback (most recent call last):
File "/home/lhx/NeRF/nerfacc/examples/train_mlp_nerf.py", line 173, in
occupancy_grid.every_n_step(
File "/home/lhx/miniconda3/envs/nerfacc/lib/python3.9/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/home/lhx/NeRF/nerfacc/nerfacc/grid.py", line 275, in every_n_step
self._update(
File "/home/lhx/miniconda3/envs/nerfacc/lib/python3.9/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/home/lhx/NeRF/nerfacc/nerfacc/grid.py", line 228, in _update
x = contract_inv(
File "/home/lhx/miniconda3/envs/nerfacc/lib/python3.9/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/home/lhx/NeRF/nerfacc/nerfacc/contraction.py", line 102, in contract_inv
ctype = type.to_cpp_version()
File "/home/lhx/NeRF/nerfacc/nerfacc/contraction.py", line 63, in to_cpp_version
return _C.ContractionTypeGetter(self.value)
File "/home/lhx/NeRF/nerfacc/nerfacc/cuda/init.py", line 11, in call_cuda
from ._backend import _C
File "/home/lhx/NeRF/nerfacc/nerfacc/cuda/_backend.py", line 38, in
_C = load_extention(name)
File "/home/lhx/NeRF/nerfacc/nerfacc/cuda/_backend.py", line 25, in load_extention
return load(
File "/home/lhx/miniconda3/envs/nerfacc/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1202, in load
return _jit_compile(
File "/home/lhx/miniconda3/envs/nerfacc/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1439, in _jit_compile
baton.wait()
File "/home/lhx/miniconda3/envs/nerfacc/lib/python3.9/site-packages/torch/utils/file_baton.py", line 42, in wait
time.sleep(self.wait_seconds)
KeyboardInterrupt

Purpose of Gradient Scaling

Gradient scaling is used in train_mlp_nerf.py, train_ngp_nerf.py and train_mlp_dnerf.py without autocasting. Moreover, gradient unscaling is not performed before optimizer.step(). Hence, there isn't any automatic mixed precision training here.

Thus, what's the purpose of the gradient scaling?

CUDA out of memery

I test unbounded dataset garden in the train_mlp_nerf, which works well during training process, but there is something wrong during testing. Is that normal? Thank you very much.
飞书20221104-143539

Cannot compile render_transmittance_cub.cu & pybind.cu

Hi,

First, thank you for your amazing work!

I'm currently working with Vanilla NeuS and NerfAcc but I'm running into a strange issue. When I run my script for the first time, it fails at the compilation of the cuda objects render_transmittance_cub.cu & pybind.cu (following a call to ray_marching() ).

I wonder if someone had the same issue ? I cannot understand where it could come from. I made sure to have all the different requirements and CUDA modules properly installed.

Traceback (most recent call last):
  File "/home/users/c/crettean/improved_NeuS/run.py", line 416, in <module>
    runner.train()
  File "/home/users/c/crettean/improved_NeuS/run.py", line 126, in train
    render_out = self.renderer.render(rays_o, rays_d, near, far,
  File "/home/users/c/crettean/improved_NeuS/models/renderer.py", line 358, in render
    packed_info, t_starts, t_ends = ray_marching(
  File "/opt/ebsofts/PyTorch/1.11.0-foss-2021a-CUDA-11.3.1/lib/python3.9/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/home/users/c/crettean/.local/lib/python3.9/site-packages/nerfacc/ray_marching.py", line 174, in ray_marching
    contraction_type = ContractionType.AABB.to_cpp_version()
  File "/home/users/c/crettean/.local/lib/python3.9/site-packages/nerfacc/contraction.py", line 62, in to_cpp_version
    return _C.ContractionTypeGetter(self.value)
  File "/home/users/c/crettean/.local/lib/python3.9/site-packages/nerfacc/cuda/__init__.py", line 11, in call_cuda
    from ._backend import _C
  File "/home/users/c/crettean/.local/lib/python3.9/site-packages/nerfacc/cuda/_backend.py", line 82, in <module>
    _C = load(
  File "/opt/ebsofts/PyTorch/1.11.0-foss-2021a-CUDA-11.3.1/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1144, in load
    return _jit_compile(
  File "/opt/ebsofts/PyTorch/1.11.0-foss-2021a-CUDA-11.3.1/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1357, in _jit_compile
    _write_ninja_file_and_build_library(
  File "/opt/ebsofts/PyTorch/1.11.0-foss-2021a-CUDA-11.3.1/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1469, in _write_ninja_file_and_build_library
    _run_ninja_build(
  File "/opt/ebsofts/PyTorch/1.11.0-foss-2021a-CUDA-11.3.1/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1756, in _run_ninja_build
    raise RuntimeError(message) from e
RuntimeError: Error building extension 'nerfacc_cuda': [1/6] /opt/ebsofts/CUDA/11.3.1/bin/nvcc  -DTORCH_EXTENSION_NAME=nerfacc_cuda -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1014\" -isystem /opt/ebsofts/PyTorch/1.11.0-foss-2021a-CUDA-11.3.1/lib/python3.9/site-packages/torch/include -isystem /opt/ebsofts/PyTorch/1.11.0-foss-2021a-CUDA-11.3.1/lib/python3.9/site-packages/torch/include/torch/csrc/api/include -isystem /opt/ebsofts/PyTorch/1.11.0-foss-2021a-CUDA-11.3.1/lib/python3.9/site-packages/torch/include/TH -isystem /opt/ebsofts/PyTorch/1.11.0-foss-2021a-CUDA-11.3.1/lib/python3.9/site-packages/torch/include/THC -isystem /opt/ebsofts/CUDA/11.3.1/include -isystem /opt/ebsofts/Python/3.9.5-GCCcore-10.3.0/include/python3.9 -D_GLIBCXX_USE_CXX11_ABI=1 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -gencode=arch=compute_75,code=compute_75 -gencode=arch=compute_75,code=sm_75 --compiler-options '-fPIC' -O3 -std=c++14 -c /home/users/c/crettean/.local/lib/python3.9/site-packages/nerfacc/cuda/csrc/render_transmittance_cub.cu -o render_transmittance_cub.cuda.o 
FAILED: render_transmittance_cub.cuda.o 
/opt/ebsofts/CUDA/11.3.1/bin/nvcc  -DTORCH_EXTENSION_NAME=nerfacc_cuda -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1014\" -isystem /opt/ebsofts/PyTorch/1.11.0-foss-2021a-CUDA-11.3.1/lib/python3.9/site-packages/torch/include -isystem /opt/ebsofts/PyTorch/1.11.0-foss-2021a-CUDA-11.3.1/lib/python3.9/site-packages/torch/include/torch/csrc/api/include -isystem /opt/ebsofts/PyTorch/1.11.0-foss-2021a-CUDA-11.3.1/lib/python3.9/site-packages/torch/include/TH -isystem /opt/ebsofts/PyTorch/1.11.0-foss-2021a-CUDA-11.3.1/lib/python3.9/site-packages/torch/include/THC -isystem /opt/ebsofts/CUDA/11.3.1/include -isystem /opt/ebsofts/Python/3.9.5-GCCcore-10.3.0/include/python3.9 -D_GLIBCXX_USE_CXX11_ABI=1 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -gencode=arch=compute_75,code=compute_75 -gencode=arch=compute_75,code=sm_75 --compiler-options '-fPIC' -O3 -std=c++14 -c /home/users/c/crettean/.local/lib/python3.9/site-packages/nerfacc/cuda/csrc/render_transmittance_cub.cu -o render_transmittance_cub.cuda.o 

Moreover I get this error which could be linked to the previous error :

/home/users/c/crettean/.local/lib/python3.9/site-packages/nerfacc/cuda/csrc/include/helpers_cuda.h:27:75: attention: \ en fin de ligne à la fin du fichier

   27 | #define CUB_WRAPPER(func, ...) do {                                       \
      |                                                                            
/home/users/c/crettean/.local/lib/python3.9/site-packages/nerfacc/cuda/csrc/render_transmittance_cub.cu:8:29: erreur: missing binary operator before token "("
    8 | #if CUB_SUPPORTS_SCAN_BY_KEY()
      |                             ^
/home/users/c/crettean/.local/lib/python3.9/site-packages/nerfacc/cuda/csrc/render_transmittance_cub.cu:18:29: erreur: missing binary operator before token "("
   18 | #if CUB_SUPPORTS_SCAN_BY_KEY()
      |                             ^
/home/users/c/crettean/.local/lib/python3.9/site-packages/nerfacc/cuda/csrc/render_transmittance_cub.cu:61:29: erreur: missing binary operator before token "("
   61 | #if CUB_SUPPORTS_SCAN_BY_KEY()
      |                             ^
/home/users/c/crettean/.local/lib/python3.9/site-packages/nerfacc/cuda/csrc/render_transmittance_cub.cu:98:29: erreur: missing binary operator before token "("
   98 | #if CUB_SUPPORTS_SCAN_BY_KEY()
      |                             ^
/home/users/c/crettean/.local/lib/python3.9/site-packages/nerfacc/cuda/csrc/render_transmittance_cub.cu:124:29: erreur: missing binary operator before token "("
  124 | #if CUB_SUPPORTS_SCAN_BY_KEY()
      |                             ^
/home/users/c/crettean/.local/lib/python3.9/site-packages/nerfacc/cuda/csrc/render_transmittance_cub.cu:155:29: erreur: missing binary operator before token "("
  155 | #if CUB_SUPPORTS_SCAN_BY_KEY()
      | 

Can't using VanillaNeRF lego examples

(nerfacc) user@user-System-Product-Name:~/nerfacc$ python examples/train_mlp_nerf.py --train_split train --scene lego
elapsed_time=29.72s | step=0 | loss=0.07453 | alive_ray_mask=64 | n_rendering_samples=10405 | num_rays=64 |
elapsed_time=246.25s | step=5000 | loss=0.00609 | alive_ray_mask=1902 | n_rendering_samples=67981 | num_rays=6039 |
elapsed_time=526.09s | step=10000 | loss=0.00360 | alive_ray_mask=2662 | n_rendering_samples=65017 | num_rays=8508 |
elapsed_time=810.97s | step=15000 | loss=0.00223 | alive_ray_mask=3250 | n_rendering_samples=63616 | num_rays=10536 |
elapsed_time=1107.14s | step=20000 | loss=0.00186 | alive_ray_mask=3725 | n_rendering_samples=66230 | num_rays=11785 |
elapsed_time=1407.04s | step=25000 | loss=0.00160 | alive_ray_mask=3746 | n_rendering_samples=65570 | num_rays=11769 |
0%| | 0/200 [00:00<?, ?it/s]
Traceback (most recent call last):
File "/home/user/nerfacc/examples/train_mlp_nerf.py", line 233, in
rgb, acc, depth, _ = render_image(
File "/home/user/nerfacc/examples/utils.py", line 88, in render_image
ray_indices, t_starts, t_ends = ray_marching(
File "/home/user/anaconda3/envs/nerfacc/lib/python3.9/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/home/user/anaconda3/envs/nerfacc/lib/python3.9/site-packages/nerfacc/ray_marching.py", line 208, in ray_marching
masks = render_visibility(
File "/home/user/anaconda3/envs/nerfacc/lib/python3.9/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/home/user/anaconda3/envs/nerfacc/lib/python3.9/site-packages/nerfacc/vol_rendering.py", line 511, in render_visibility
packed_info = pack_info(ray_indices, n_rays=n_rays)
File "/home/user/anaconda3/envs/nerfacc/lib/python3.9/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/home/user/anaconda3/envs/nerfacc/lib/python3.9/site-packages/nerfacc/pack.py", line 67, in pack_info
n_rays = int(ray_indices.max()) + 1
RuntimeError: max(): Expected reduction dim to be specified for input.numel() == 0. Specify the reduction dim with the 'dim' argument.

i'm using pytorch 1.12 / cuda 11.3 / ubuntu linux 22.04

Can anybody give me some help?

Got Cutclass error: Error internal at: 345

While running the examples, I got this error after running the train file for 20,000 steps. Sure my GPU architecture is 61, and does not support FullyFusedMLP, but it should still run right?

Screenshot from 2022-10-28 10-40-23

Some marching details related to `advance_to_next_voxel` function

Hi,
First of all, thanks for the great repo!
During code reading, I noticed that there's a slight difference between raymarching here and ngp's implementation when applying dt:

  • ngp's implementation
inline __device__ float advance_to_next_voxel(...) {
	// Regular stepping (may be slower but matches non-empty space)
	float t_target = t + distance_to_next_voxel(pos, dir, idir, res);
	do {
		t += calc_dt(t, cone_angle); // <----- Notice here
	} while (t < t_target);
	return t;
}
  • nerfacc's implementation
inline __device__ __host__ float advance_to_next_voxel(...)
{
    // Regular stepping (may be slower but matches non-empty space)
    float t_target = t + distance_to_next_voxel(xyz, dir, inv_dir, roi_min, roi_max, grid_res);
    float _t = t;
    do
    {
        _t += dt_min; // <----- Notice here
    } while (_t < t_target);
    return _t;
}

When cone_angle is set to nonzero, in ngp's implementation, ngp uses proportional stepping to march to the next voxel, while in here it uses minimum step size linear stepping.

  1. Is this difference made out of consideration of marching's safety ? Are there concerns of steps too large that even marches across the next voxel ?
  2. If you are already using linear stepping rather than proportional one, the number of while loop cycles is actually deterministic. _t can be directly calculated from _t = t + dt_min * (int ((t_target-t) / dt_min) + 1);. No do-while loop is needed anymore.
    The efficiency difference between do-while loop and calculating number of cycles in advance is negligible. During my test, the time difference is within measurement error when N_rays=4096,120k, 1920k.

doc enhancement

This repo contains submodule so one needs either
git clone --recursive or git submodule update --recursive --init after cloning the repo. It is worth nothing in the readme.

About the performance on Lego, using Instant-NGP.

It's a great job. It helps me a lot.
In the case of Instant-NGP, the Lego results had a slightly lower PSNR than in the paper, about 35.69. Which parameter should I adjust to improve my accuracy?
This question makes me very confused and I am looking forward to your reply.

Here is my output:

root@container-a2b311863c-63d7f839:/home/gzx/code/nerfacc# python examples/train_ngp_nerf.py --train_split train --scene lego
elapsed_time=1.67s | step=0 | loss=0.07278 | alive_ray_mask=256 | n_rendering_samples=66200 | num_rays=256 |
elapsed_time=130.57s | step=10000 | loss=0.00058 | alive_ray_mask=16749 | n_rendering_samples=267778 | num_rays=50257 |
elapsed_time=267.00s | step=20000 | loss=0.00037 | alive_ray_mask=16798 | n_rendering_samples=260996 | num_rays=51154 |
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 200/200 [00:41<00:00, 4.81it/s]
evaluation: psnr_avg=35.549825792312625
training stops
root@container-a2b311863c-63d7f839:/home/gzx/code/nerfacc# python examples/train_ngp_nerf.py --train_split train --scene lego
elapsed_time=1.56s | step=0 | loss=0.07278 | alive_ray_mask=256 | n_rendering_samples=66200 | num_rays=256 |
elapsed_time=130.64s | step=10000 | loss=0.00059 | alive_ray_mask=17210 | n_rendering_samples=273457 | num_rays=51594 |
elapsed_time=266.61s | step=20000 | loss=0.00038 | alive_ray_mask=16845 | n_rendering_samples=260156 | num_rays=51493 |
elapsed_time=402.35s | step=30000 | loss=0.00031 | alive_ray_mask=17114 | n_rendering_samples=263116 | num_rays=52361 |
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 200/200 [00:42<00:00, 4.72it/s]
evaluation: psnr_avg=35.69479295730591
training stops

Encounter cuda error when training

Hi, I encounter some cuda errors when I train the example, I tried making batch_size smaller but it doesn't work. Could you please figure out which part matters? Thanks.

python examples/train_mlp_nerf.py --train_split train --scene lego
Traceback (most recent call last):
File "/project/nerfacc/examples/train_mlp_nerf.py", line 169, in
occupancy_grid.every_n_step(
File "/home/anaconda3/envs/nerfacc/lib/python3.9/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/project/nerfacc/nerfacc/grid.py", line 271, in every_n_step
self._update(
File "/home/anaconda3/envs/nerfacc/lib/python3.9/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/project/nerfacc/nerfacc/grid.py", line 229, in _update
occ = occ_eval_fn(x).squeeze(-1)
File "/project/nerfacc/examples/train_mlp_nerf.py", line 171, in
occ_eval_fn=lambda x: radiance_field.query_opacity(
File "/project/nerfacc/examples/radiance_fields/mlp.py", line 229, in query_opacity
density = self.query_density(x)
File "/project/nerfacc/examples/radiance_fields/mlp.py", line 237, in query_density
sigma = self.mlp.query_density(x)
File "/project/nerfacc/examples/radiance_fields/mlp.py", line 149, in query_density
x = self.base(x)
File "/home/anaconda3/envs/nerfacc/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "/project/nerfacc/examples/radiance_fields/mlp.py", line 90, in forward
x = self.hidden_layersi
File "/home/anaconda3/envs/nerfacc/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "/home/anaconda3/envs/nerfacc/lib/python3.9/site-packages/torch/nn/modules/linear.py", line 114, in forward
return F.linear(input, self.weight, self.bias)
RuntimeError: CUDA error: CUBLAS_STATUS_NOT_INITIALIZED when calling cublasCreate(handle)

Support automatic mixed precision (AMP) training?

I try to apply AMP training with nerfacc, but I found that result in much worse rendering results:
Compared to float32 training, there is a 3 point drop in PSNR.

Of course, I fix a data type issue when AMP training.

Selection_394

I wonder if you have plans to support AMP training

How to visualize?

I trained the model and get psnr value successfully.

How to visualize it ? It seems no checkpoint saved during the whole process.

Can nerfacc support batch-wise ops?

In my case, the nerf network may contains B different scenes. Can nerfacc support ray_marching with rays_o, rays_d (shape: B, N, 3) and sigma_fn (B, N, 3 -> B, N, 1)?

code about unbounded

Hi, thanks for your great work, i have some question about the unbounded codes.it's different with the codes in mipnerf 360.
why did you use x = x / 4 + 0.5 after contract sample points to unisphere ?

contract_to_unisphere unbound scene

x[mask] = (2 - 1 / mag[mask]) * (x[mask] / mag[mask]) x = x / 4 + 0.5 # [-inf, inf] is at [0, 1]

looking forward to your reply, thanks! @liruilong940607

Can nerfacc support mipnerf and mipnerf360?

Hi, thanks for your great framework. I'm trying to use nerfacc to accelerate mipnerf and mipnerf360, but this seems harder than I thought, since these two models sample cones instead of points, and need compute covariance after sampling.

I'll be very appreciate it if you can give me some hints!

NAN

Thanks for your sharing.

I tried to run the examples of mlp, but the network output was NAN.
Can you give me some suggestions?

image

Code gets stuck when updating occupancy grid

Hi there, thanks for sharing your work!

When I was running the train_mlp_nerf.py, my code was always stuck at :here. And no Errors or Warnings occur.

Could you please help me about this problem? Any response will be greatly appreciated.

ENV:
torch 1.12.1
cudatoolkit: 11.3
gcc: 10.3.0

How to run on multiple GPUs?

I want to run train_mlp_nerf.py based on our datasets, whose resolution of the images is 2k. I have set the num_rays to a constant value of 1024 and set the occupancy_grid to None.

Now, I run the code under 3 A100s, but the running time of 100 iters of your code is slower than the origin PyTorch-nerf. I consider the reason may be the setting of multiple GPUs.
I want to know how to run your code on multiple GPUs.

Setting up CUDA (This may take a few minutes the first time)Killed

Could you please help me?
(nerfacc)root@container-804a11b7ac-5f6a35c5:~/autodl-tmp# /root/miniconda3/envs/nerf/bin/python /root/autodl-tmp/nerfacc/examples/train_mlp_nerf.py
( ● ) NerfAcc: Setting up CUDA (This may take a few minutes the first time)Killed

torch ==1.12.1+cu102
RTX 2080 Ti

Failed to read the internal and external parameters of the unbounded scene camera

Warning: image_path not found for reconstruction
Traceback (most recent call last):
File "examples/train_ngp_nerf.py", line 102, in
train_dataset = SubjectLoader(
File "D:\ks2\nerfacc\examples\datasets\nerf_360_v2.py", line 186, in init
self.images, self.camtoworlds, self.K = _load_colmap(
File "D:\ks2\nerfacc\examples\datasets\nerf_360_v2.py", line 32, in _load_colmap
manager.load_cameras()
File "D:\ks2\nerfacc\examples\datasets..\pycolmap\pycolmap\scene_manager.py", line 90, in load_cameras
self._load_cameras_bin(input_file)
File "D:\ks2\nerfacc\examples\datasets..\pycolmap\pycolmap\scene_manager.py", line 102, in _load_cameras_bin
num_cameras = struct.unpack('L', f.read(8))[0]
struct.error: unpack requires a buffer of 4 bytes
QQ截图20221107203924

What makes this faster than instant-ngp precisely?

According to the paper, I couldn't find obvious evidence that makes your method faster than instant-ngp, as you stated that most accelerating techniques are borrowed from them. Do you have any special technique that is not described in the paper?

Or is #64 related? Maybe training on the train set you get similar result with instant-ngp only after 5min.

distortion loss

hi, thanks for your great work! i found the the def distortion loss in loss codes, but they are not be used in any codes? did your test the distortion loss in the trainning pipeline? @brentyi @liruilong940607
looking forward to your reply!

Out of the box compatibility with surface-based methods

Thanks for sharing this great tool. Very exciting stuff.

This is more of a question out of curiosity than an issue so please feel free to let me know if it's been asked before. I notice most of the examples shown are for density-based NeRFs. I wonder if this works out of the box with surface-based methods, such as UniSurf and the numerous other works in that direction. If not, what adaptations need to be made for such compatibility to be achieved?

Thanks for your contributions.

Loss Nan

I tried to add a 2 layer MLP before sending the coordinate to the original network,

self.mlp_disp = tcnn.Network(
                n_input_dims=3,
                n_output_dims=3,
                network_config={
                    "otype": "FullyFusedMLP",
                    "activation": "ReLU",
                    "output_activation": "None",
                    "n_neurons": 16,
                    "n_hidden_layers": 2,
                },
            )


def query_density(self, x, return_feat: bool = False):
        if self.unbounded:
            x = contract_to_unisphere(x, self.aabb)
        else:
            aabb_min, aabb_max = torch.split(self.aabb, self.num_dim, dim=-1)
            x = (x - aabb_min) / (aabb_max - aabb_min)
        selector = ((x > 0.0) & (x < 1.0)).all(dim=-1)

        # New mlp here
        x = (x + self.mlp_disp(x)).float()

        x = (
            self.mlp_base(x.view(-1, self.num_dim))
            .view(list(x.shape[:-1]) + [1 + self.geo_feat_dim])
            .to(x)
        )

        ...

However, the loss becomes NaN after a few hundred steps. Any idea why this happens?

Examples do not run

Because the paths are hard-coded like this: "/home/ruilongli/..."

Also where can we find these files?

Build failed with PyTorch <= 1.10

Could not build nerfacc cuda kernels with older PyTorch versions (<= 1.10). Error message:

nerfacc/cuda/csrc/include/helpers_cuda.h:10:10: fatal error: ATen/cuda/cub_definitions.cuh: No such file or directory
   10 | #include <ATen/cuda/cub_definitions.cuh>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

It seems that ATen/cuda/cub_definitions.cuh only exists after PyTorch 1.11. Maybe we should alter helper functions based on the PyTorch version.

initial values for OccupancyGrid

I have a quick question out of curiosity regarding the initial values for OccupancyGrid.

Do the initial values from some prior geometries for OccupancyGrid accelerate the process? did you try it? Thanks in advance!

how to visualize the train step

hello , I want to visualize the predicted image when training to show the efficiency of ngp. Is there any relevant settings in the code ?

Got cutlass error: Error Internal at: 346

When I try running the trainval.py script, I run into the following error after training is completed (during eval). I tried reducing the test_chunk_size as well as the target_sample_batch_size to conserve memory, but the issue still appears.

Got cutlass error: Error Internal at: 346
Could not free memory arena: /tmp/pip-req-build-lnpgfnjz/include/tiny-cuda-nn/gpu_memory.h:478 cudaDeviceSynchronize() failed with error operation not permitted when stream is capturing
Could not free memory arena: /tmp/pip-req-build-lnpgfnjz/include/tiny-cuda-nn/gpu_memory.h:478 cudaDeviceSynchronize() failed with error operation not permitted when stream is capturing
Could not free memory arena: /tmp/pip-req-build-lnpgfnjz/include/tiny-cuda-nn/gpu_memory.h:478 cudaDeviceSynchronize() failed with error operation not permitted when stream is capturing
ubuntu@ip-10-2-1-56:~/data/nerfacc$ python examples/trainval.py ngp --train_split trainval

Command used:
python examples/trainval.py ngp --train_split trainval --test_chunk_size 1024

In addition, I am running on V100, which yields following warning:

Warning: FullyFusedMLP is not supported for the selected architecture 70. Falling back to CutlassMLP. For maximum performance, raise the target GPU architecture to 75+.

How can I train my own c2w transform data?

Hi!
Thanks for your great job!
I am trying to use your code to train a nerf model with my own dataset.
What I want to know the form of the transform matrixes that you used. My data's form is c2w, but I got a wrong result. Are you using w2c?
Thanks again!

How to install dependencies and correspond to the correct version?

When I ran pip install nerfacc, it came up with:

ERROR: Could not find a version that satisfies the requirement nerfacc (from versions: none)
ERROR: No matching distribution found for nerfacc

Is there any other requirement besides installing the correct version of python?

How to rebuild cuda?

I want to modify the cuda code, can you tell me how to recompile it? It seems that there is no setup.py

Obtaining visibility values

Hi,
Is there any way to extract actual visibility values from the rendering process? Currently the visibility test returns a mask of visible / invisible samples, but what I want is to obtain the cumulative product of the alphas along a cast ray.

This doesn't seem to be calculated directly to obtain the weights.

Meaning of accumulated depth

Hi, thanks for this great project! I have a question about depth returned from rendering() , it is computed by

depths = accumulate_along_rays(
        weights,
        ray_indices,
        values=(t_starts + t_ends) / 2.0,
        n_rays=n_rays,
    )

Usually the t_starts and t_ends is the distance along ray, so the returned depth mesuares the point-to-point distance. If I require a point-to-plane depth (to compute a depth loss from some sensor measurements), I need an extra coefficient dot(ray_d, camera_forward) right?

clarity about --aabb

Hi !

As per instant-ngp implementation they say the cube is [0,0,0] to [1,1,1].

I wanted to know about the --aabb parameter, which says that the default="-1.5,-1.5,-1.5,1.5,1.5,1.5". Could you may be help me understand about how the cube is positioned ?

Is it like [-1.5,-1.5,-1.5] to [1.5,1.5,1.5] ?

Thanks

Why results of early_stop_eps=1 are better than early_stop_eps=1e-3?

Hi,

I tested on my datasets. Then I found the network can learn better when early_stop_eps=1 than early_stop_eps=1e-3 in ray_marching function, which makes no sense to me. It seems like the network is hard to train when early_stop_eps=1e-3 since it preserves more samples? I am confused by this result.

Can't run the example after updating to 0.3.1

Hello there, thanks for sharing your amazing work!

It seems that something is wrong after updating to 0.3.1. I run the train_mlp_nerf.py and get this error:

Traceback (most recent call last):
 File "/home/XXX/Code/nerfacc/./examples/train_mlp_nerf.py", line 177, in <module>
    rgb, acc, depth, n_rendering_samples = render_image(
 File "/home/XXX/Code/nerfacc/examples/utils.py", line 88, in render_image
    ray_indices, t_starts, t_ends = ray_marching(
 File "/home/XXX/anaconda3/envs/neuris/lib/python3.9/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
 File "/home/XXX/Code/nerfacc/nerfacc/ray_marching.py", line 177, in ray_marching
    packed_info, ray_indices, t_starts, t_ends = _C.ray_marching(
ValueError: not enough values to unpack (expected 4, got 3)

My code is the newest from this repo. Any response will be greatly appreciated! Thank you!

Support for CUDA capability sm_86

Hi,
Thanks for this repository.
When running the basic examples, using the installation instructions (pip install), I get the following error:
RTX A6000 with CUDA capability sm_86 is not compatible with the current PyTorch installation.
The current PyTorch install supports CUDA capabilities sm_37 sm_50 sm_60 sm_70.

How can I solve this?

NerfAcc: No CUDA toolkit found. NerfAcc will be disabled.

I have a local cuda-toolkit 11.6.2 and Pytorch with cuda 11.6 along with tiny cudnn.
However when I run the examples, I come across this error.

NerfAcc: No CUDA toolkit found. NerfAcc will be disabled.

File "/home/annamalai/nerfacc/cuda/init.py", line 13, in call_cuda
return getattr(_C, name)(*args, **kwargs)

AttributeError: 'NoneType' object has no attribute 'ContractionType'

Although I also get a warning that FullyFused MLP is not supported for the selected architecture.

I'm not sure why this happens.

issue at raymarching

Hi !
I face this error when at the command ray_marching()
Please help me this ... thank you !

File "train.py", line 95, in
main()
File "train.py", line 93, in main
nerf_sim.training()
File "train.py", line 63, in training
self.nerf.render(ray_o, ray_d, rgb_gt, step)
File "/home/yash/Documents/nerf/NeRF/run_NeRF.py", line 64, in render
rgb, acc, depth = self.output.renderer(ray_o,
File "/home/yash/Documents/nerf/NeRF/rendering.py", line 59, in renderer
packed_info, t_start, t_end = self.vol_sampling(ray_o, ray_d, aabb, grid, render_step_size, cone_angle, alpha_thre)
File "/home/yash/Documents/nerf/NeRF/rendering.py", line 46, in vol_sampling
packed_info, t_start, t_end = ray_marching(ray_o,
File "/home/yash/anaconda3/envs/nerf_sim/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/home/yash/anaconda3/envs/nerf_sim/lib/python3.8/site-packages/nerfacc/ray_marching.py", line 156, in ray_marching
grid_roi_aabb = grid.roi_aabb
AttributeError: 'float' object has no attribute 'roi_aabb'

The psnr_avg of `ficus` is abnormal, others are similar to the reported results

Hi Ruilong,

Thanks for the amazaing project. I tested the three methods you provided, and I can get similar results on the corresponding datasets, but only one scene gets lower performance, and the loss is nan. The results are consistent across multiple runs.
Do you have any tips on how to find the cause of the problem.

RTX 3090, torch=1.10.1+cu111, torchvision=0.11.2+cu111
nerfacc == 0.2.0

python examples/train_mlp_nerf.py --train_split train --scene ficus
elapsed_time=1.78s | step=0 | loss=0.00888 | alive_ray_mask=64 | n_rendering_samples=10231 | num_rays=64 |
elapsed_time=163.39s | step=5000 | loss=nan | alive_ray_mask=0 | n_rendering_samples=65611 | num_rays=269 |
elapsed_time=325.57s | step=10000 | loss=nan | alive_ray_mask=0 | n_rendering_samples=60619 | num_rays=260 |
elapsed_time=487.55s | step=15000 | loss=nan | alive_ray_mask=0 | n_rendering_samples=63759 | num_rays=274 |
elapsed_time=649.66s | step=20000 | loss=nan | alive_ray_mask=0 | n_rendering_samples=65520 | num_rays=281 |
elapsed_time=812.03s | step=25000 | loss=nan | alive_ray_mask=0 | n_rendering_samples=66233 | num_rays=273 |
elapsed_time=975.32s | step=30000 | loss=nan | alive_ray_mask=0 | n_rendering_samples=69855 | num_rays=279 |
elapsed_time=1138.03s | step=35000 | loss=nan | alive_ray_mask=0 | n_rendering_samples=65633 | num_rays=276 |
elapsed_time=1300.72s | step=40000 | loss=nan | alive_ray_mask=0 | n_rendering_samples=66092 | num_rays=273 |
elapsed_time=1462.58s | step=45000 | loss=nan | alive_ray_mask=0 | n_rendering_samples=64994 | num_rays=278 |
elapsed_time=1624.28s | step=50000 | loss=nan | alive_ray_mask=0 | n_rendering_samples=72772 | num_rays=288 |
100%|█████████████████████████████████| 200/200 [1:31:58<00:00, 27.59s/it]
evaluation: psnr_avg=14.225740423202515
training stops

image

Question about neus with nerfacc

Hi Ruilong,

It looks for me that, although much faster, the neus with hash encoding is much worse than the vallina MLP version neus (I tried both instant-nsr and instant-nsr-pl , they are both not as good as neus, so I guess hash encoding should be responsible for the degradation of the reconstruction quality ) . Do you have any idea why ?

Have you tried the vallina MLP version neus with your nerfacc, without the hash encoding part ? I think it should be faster than neus , and bettter quality than instant-nsr / instant-nsr-pl.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.