Downloads · 30 days
0
camenduru/instant-ngp
instant-ngp is a machine learning model from camenduru. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
<img src="docs/assetsreadme/fox.gif" height="342"/ <img src="docs/assetsreadme/robot5.gif" height="342"/
Downloads · 30 days
0
Access
Public
Updated Dec 29, 2022
Repo size
1.1 GB
Likes
6
Public
Click a slice to open those files.
.lib99 MB · 17%
From the Hugging Face model README
<img src="docs/assets_readme/fox.gif" height="342"/> <img src="docs/assets_readme/robot5.gif" height="342"/>
Ever wanted to train a NeRF model of a fox in under 5 seconds? Or fly around a scene captured from photos of a factory robot? Of course you have!
Here you will find an implementation of four neural graphics primitives, being neural radiance fields (NeRF), signed distance functions (SDFs), neural images, and neural volumes. In each case, we train and render a MLP with multiresolution hash input encoding using the tiny-cuda-nn framework.
Instant Neural Graphics Primitives with a Multiresolution Hash Encoding
Thomas Müller, Alex Evans, Christoph Schied, Alexander Keller
ACM Transactions on Graphics (SIGGRAPH), July 2022
Project page / Paper / Video / Presentation / Real-Time Live / BibTeX
To get started with NVIDIA Instant NeRF, check out the blog post and SIGGRAPH tutorial.
For business inquiries, please submit the NVIDIA research licensing form.
If you have Windows and if you do not need Python bindings, you can download one of the following binary releases and then jump directly to the usage instructions. These releases are automatically regenerated whenever the code gets updated, so you can be sure that they have the latest features.
If you use Linux, or want the Python bindings, or if your GPU is not listed above (e.g. Hopper, Volta, or Maxwell generations), use the following step-by-step instructions to compile instant-ngp yourself.
pip install -r requirements.txt.If you are using Debian based Linux distribution, install the following packages
sudo apt-get install build-essential git python3-dev python3-pip libopenexr-dev libxi-dev \
libglfw3-dev libglew-dev libomp-dev libxinerama-dev libxcursor-dev
Alternatively, if you are using Arch or Arch derivatives, install the following packages
sudo pacman -S base-devel cmake openexr libxi glfw openmp libxinerama libxcursor
We also recommend installing CUDA and OptiX in /usr/local/ and adding the CUDA installation to your PATH.
For example, if you have CUDA 11.4, add the following to your ~/.bashrc
export PATH="/usr/local/cuda-11.4/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda-11.4/lib64:$LD_LIBRARY_PATH"
For Arch and derivatives,
sudo pacman -S cuda
Begin by cloning this repository and all its submodules using the following command:
$ git clone --recursive https://github.com/nvlabs/instant-ngp
$ cd instant-ngp
Then, use CMake to build the project: (on Windows, this must be in a developer command prompt)
instant-ngp$ cmake . -B build
instant-ngp$ cmake --build build --config RelWithDebInfo -j
If compilation fails inexplicably or takes longer than an hour, you might be running out of memory. Try running the above command without -j in that case.
If this does not help, please consult this list of possible fixes before opening an issue.
If the build succeeds, you can now run the code via the build/instant-ngp executable or the scripts/run.py script described below.
If automatic GPU architecture detection fails, (as can happen if you have multiple GPUs installed), set the TCNN_CUDA_ARCHITECTURES environment variable for the GPU you would like to use. The following table lists the values for common GPUs. If your GPU is not listed, consult this exhaustive list.
| H100 | 40X0 | 30X0 | A100 | 20X0 | TITAN V / V100 | 10X0 / TITAN Xp | 9X0 | K80 |
|---|---|---|---|---|---|---|---|---|
| 90 | 89 | 86 | 80 | 75 | 70 | 61 | 52 | 37 |
This codebase comes with an interactive GUI that includes many features beyond our academic publication:
NeRF->Mesh and SDF->Mesh conversion.Let's start using instant-ngp; more information about the GUI and other scripts follow these test scenes.
One test scene is provided in this repository, using a small number of frames from a casually captured phone video:
instant-ngp$ ./build/instant-ngp --scene data/nerf/fox
On Windows you need to reverse the slashes here (and below), i.e.:
instant-ngp> .\build\instant-ngp --scene data\nerf\fox
<img src="docs/assets_readme/fox.png"/>
Alternatively, download any NeRF-compatible scene (e.g. from the NeRF authors' drive, the SILVR dataset, or the DroneDeploy dataset). Now you can run:
instant-ngp$ ./build/instant-ngp --scene data/nerf_synthetic/lego/transforms_train.json
To prepare your own dataset for use with our NeRF implementation, click here. See also this video for a guided walkthrough.
instant-ngp$ ./build/instant-ngp --scene data/sdf/armadillo.obj
<img src="docs/assets_readme/armadillo.png"/>
instant-ngp$ ./build/instant-ngp --scene data/image/albert.exr
<img src="docs/assets_readme/albert.png"/>
To reproduce the gigapixel results, download, for example, the Tokyo image and convert it to .bin using the scripts/convert_image.py script. This custom format improves compatibility and loading speed when resolution is high. Now you can run:
instant-ngp$ ./build/instant-ngp --scene data/image/tokyo.bin
Download the nanovdb volume for the Disney cloud, which is derived from here (CC BY-SA 3.0).
instant-ngp$ ./build/instant-ngp --mode volume --scene data/volume/wdas_cloud_quarter.nvdb
<img src="docs/assets_readme/cloud.png"/>
Here are the main keyboard controls for the instant-ngp application.
| Key | Meaning |
|---|---|
| WASD | Forward / pan left / backward / pan right. |
| Spacebar / C | Move up / down. |
| = or + / - or _ | Increase / decrease camera velocity. |
| E / Shift+E | Increase / decrease exposure. |
| T | Toggle training. After around two minutes training tends to settle down, so can be toggled off. |
| R | Reload network from file. |
| Shift+R | Reset camera. |
| O | Toggle visualization or accumulated error map. |
| G | Toggle visualization of the ground truth. |
| M | Toggle multi-view visualization of layers of the neural model. See the paper's video for a little more explanation. |
| , / . | Shows the previous / next visualized layer; hit M to escape. |
| 1-8 | Switches among various render modes, with 2 being the standard one. You can see the list of render mode names in the control interface. |
There are many controls in the instant-ngp GUI. First, note that this GUI can be moved and resized, as can the "Camera path" GUI (which first must be expanded to be used).
Some popular user controls in instant-ngp are:
The "Camera path" GUI lets you set frames along a path. "Add from cam" is the main button you'll want to push, then saving out the camera keyframes using "Save" to create a base_cam.json file. There is a bit more information about the GUI in this post and in this (bit dated) video.
To conduct controlled experiments in an automated fashion, all features from the interactive GUI (and more!) have Python bindings that can be easily instrumented.
For an example of how the ./build/instant-ngp application can be implemented and extended from within Python, see ./scripts/run.py, which supports a superset of the command line arguments that ./build/instant-ngp does.
Here is a typical command line using scripts/run.py to generate a 5-second flythrough of the fox dataset to the (default) file video.mp4, after using the GUI to save a (default) NeRF snapshot base.msgpack and a set of camera key frames: (see this video for a guided walkthrough)
instant-ngp$ python scripts/run.py --mode nerf --scene data/nerf/fox --load_snapshot data/nerf/fox/base.msgpack --video_camera_path data/nerf/fox/base_cam.json --video_n_seconds 5 --video_fps 60 --width 1920 --height 1080
If you'd rather build new models from the hash encoding and fast neural networks, consider the tiny-cuda-nn's PyTorch extension.
Happy hacking!
Q: How can I run instant-ngp in headless mode?
A: Use ./build/instant-ngp --no-gui or python scripts/run.py. You can also compile without GUI via cmake -DNGP_BUILD_WITH_GUI=off ...
Q: Does this codebase run on Google Colab?
A: Yes. See this example inspired on the notebook created by user @myagues. Caveat: this codebase requires large amounts of GPU RAM and might not fit on your assigned GPU. It will also run slower on older GPUs.
Q: Is there a Docker container?
A: Yes. We bundle a Visual Studio Code development container, the .devcontainer/Dockerfile of which you can also use stand-alone.
If you want to run the container without using VSCode:
docker-compose -f .devcontainer/docker-compose.yml build instant-ngp
xhost local:root
docker-compose -f .devcontainer/docker-compose.yml run instant-ngp /bin/bash
Then run the build commands above as normal.
Q: How can I edit and train the underlying hash encoding or neural network on a new task?
A: Use tiny-cuda-nn's PyTorch extension.
Q: How can I save the trained model and load it again later?
A: Two options:
load_snapshot / save_snapshot (see scripts/run.py for example usage).Q: Can this codebase use multiple GPUs at the same time?
A: No. To select a specific GPU to run on, use the CUDA_VISIBLE_DEVICES environment variable. To optimize the compilation for that specific GPU use the TCNN_CUDA_ARCHITECTURES environment variable.
Q: What is the coordinate system convention?
A: See this helpful diagram by user @jc211.
Q: The NeRF reconstruction of my custom dataset looks bad; what can I do?
A: There could be multiple issues:
aabb_scale) might have been tuned suboptimally. We recommend starting with aabb_scale=16 and then increasing or decreasing it by factors of two until you get optimal quality.Q: Why are background colors randomized during NeRF training?
A: Transparency in the training data indicates a desire for transparency in the learned model. Using a solid background color, the model can minimize its loss by simply predicting that background color, rather than transparency (zero density). By randomizing the background colors, the model is forced to learn zero density to let the randomized colors "shine through".
Q: How to mask away NeRF training pixels (e.g. for dynamic object removal)?
A: For any training image xyz.* with dynamic objects, you can provide a dynamic_mask_xyz.png in the same folder. This file must be in PNG format, where non-zero pixel values indicate masked-away regions.
Before investigating further, make sure all submodules are up-to-date and try compiling again.
instant-ngp$ git submodule sync --recursive
instant-ngp$ git submodule update --init --recursive
If instant-ngp still fails to compile, update CUDA as well as your compiler to the latest versions you can install on your system. It is crucial that you update both, as newer CUDA versions are not always compatible with earlier compilers and vice versa. If your problem persists, consult the following table of known issues.
*After each step, delete the build folder and let CMake regenerate it before trying again.*
| Problem | Resolution |
|---|---|
| CMake error: No CUDA toolset found / CUDA_ARCHITECTURES is empty for target "cmTC_0c70f" | Windows: the Visual Studio CUDA integration was not installed correctly. Follow these instructions to fix the problem without re-installing CUDA. (#18) |
Linux: Environment variables for your CUDA installation are probably incorrectly set. You may work around the issue using cmake . -B build -DCMAKE_CUDA_COMPILER=/usr/local/cuda-<your cuda version>/bin/nvcc (#28) | |
| CMake error: No known features for CXX compiler "MSVC" | Reinstall Visual Studio & make sure you run CMake from a developer shell. Make sure you delete the build folder before building again. (#21) |
| Compile error: A single input file is required for a non-link phase when an outputfile is specified | Ensure there no spaces in the path to instant-ngp. Some build systems seem to have trouble with those. (#39 #198) |
| Compile error: undefined references to "cudaGraphExecUpdate" / identifier "cublasSetWorkspace" is undefined | Update your CUDA installation (which is likely 11.0) to 11.3 or higher. (#34 #41 #42) |
| Compile error: too few arguments in function call | Update submodules with the above two git commands. (#37 #52) |
| Python error: No module named 'pyngp' | It is likely that CMake did not detect your Python installation and therefore did not build pyngp. Check CMake logs to verify this. If pyngp was built in a different folder than instant-ngp/build, Python will be unable to detect it and you have to supply the full path to the import statement. (#43) |
If you cannot find your problem in the table, try searching the discussions board and the issues area for help. If you are still stuck, please open an issue and ask for help.
Many thanks to Jonathan Tremblay and Andrew Tao for testing early versions of this codebase and to Arman Toorians and Saurabh Jain for the factory robot dataset. We also thank Andrew Webb for noticing that one of the prime numbers in the spatial hash was not actually prime; this has been fixed since.
This project makes use of a number of awesome open source libraries, including:
dependencies folder.Many thanks to the authors of these brilliant projects!
@article{mueller2022instant,
author = {Thomas M\"uller and Alex Evans and Christoph Schied and Alexander Keller},
title = {Instant Neural Graphics Primitives with a Multiresolution Hash Encoding},
journal = {ACM Trans. Graph.},
issue_date = {July 2022},
volume = {41},
number = {4},
month = jul,
year = {2022},
pages = {102:1--102:15},
articleno = {102},
numpages = {15},
url = {https://doi.org/10.1145/3528223.3530127},
doi = {10.1145/3528223.3530127},
publisher = {ACM},
address = {New York, NY, USA},
}
Copyright © 2022, NVIDIA Corporation. All rights reserved.
This work is made available under the Nvidia Source Code License-NC. Click here to view a copy of this license.