Skip to content

Guide · Open source

How to use NeRF: setup, training and rendering views

Updated · written with AI from the project's own documentation and checked against our catalogue data

NeRF (Neural Radiance Fields) is the official code release for a 2020 view synthesis method. You give it photos of one scene taken from known camera positions, and it trains a small network that can render that scene from angles that were never photographed. This guide walks through the clone-and-build setup, training an example scene, rendering new views and preparing your own posed photos, so you can run it yourself.

NeRFbmild/nerf · ★ 11k · MIT

Quick start

  1. 1Clone the repository. Run git clone on bmild/nerf to get the code.
  2. 2Create the conda environment. Run conda env create -f environment.yml to install TensorFlow 1.15 and other dependencies.
  3. 3Activate the environment. Run conda activate nerf before running any code.
  4. 4Download example data. Run bash download_example_data.sh to get the Lego and Fern datasets.
  5. 5Train the Fern scene. Run python run_nerf.py --config config_fern.txt on a machine with a single GPU, expecting hours to a day or two.
  6. 6Render new views. Open render_demo.ipynb in Jupyter after downloading pretrained weights, or use your own trained model.

What you need before you install NeRF

The project is Python code with no graphical interface described in the README. It is built around TensorFlow 1.15, and the README says training needs a single GPU and takes a few hours to a day or two depending on resolution.

  • Python 3
  • conda, used to create the environment from environment.yml
  • TensorFlow 1.15 (installed through the environment file)
  • ImageMagick, required by the LLFF data loader
  • A single GPU for practical training

Install NeRF by cloning the repository and creating the environment

Clone the repository, then create and activate the conda environment. The environment file includes all the Python dependencies listed in the README: TensorFlow 1.15, matplotlib, numpy, imageio and configargparse.

git clone https://github.com/bmild/nerf conda env create -f environment.yml conda activate nerf

Download the example data and train a first scene

The README provides a script that downloads the synthetic Lego dataset and the LLFF Fern dataset. To train a low-resolution Fern model, run the config file for that scene. After 200k iterations (about 15 hours according to the README), the output video is written to logs/fern_test.

  • Lego and Fern are the two example scenes the README uses.
  • Training output goes to logs/, and TensorBoard can show progress from logs/summaries.
bash download_example_data.sh python run_nerf.py --config config_fern.txt tensorboard --logdir=logs/summaries --port=6006

Render new views from a pretrained model

If you do not want to train from scratch, the README describes a script that downloads a pretrained high-resolution NeRF for the Fern dataset. You can then open render_demo.ipynb in Jupyter to render new views from it.

  • Open render_demo.ipynb to render views.
  • Use the pretrained Fern weights as a starting point before training your own scene.
bash download_example_weights.sh

Run your own photos through NeRF

For real photos you need camera poses. The README recommends the imgs2poses.py script from the LLFF code, which also requires COLMAP. Pass the scene folder with --datadir and set -dataset_type llff. For a forward-facing scene, config_fern.txt is a reference for settings. For a 360-degree capture, the README suggests adding --no_ndc --spherify --lindisp.

If you already have poses, they must be 3x4 numpy camera-to-world matrices in the OpenGL convention (X right, Y up, Z backwards), plus hwf = [height, width, focal length] and near/far bounds.

  • Poses: 3x4 numpy arrays, camera-to-world.
  • Intrinsics: hwf = [height, width, focal length].
  • The README points to data loading code in run_nerf.py for details.
python run_nerf.py --config config_fern.txt --datadir <myscene> -dataset_type llff

Reproduce the paper results and extract a mesh

The example configs run at lower resolution than the paper. To replicate paper results, start from the configs in paper_configs/, and the README links the Blender and LLFF data. The README also includes extract_mesh.ipynb, which runs marching cubes on a trained network. It needs PyMCubes, and trimesh and pyrender if you want to view the mesh in the notebook.

  • Paper configs live in paper_configs/.
  • Mesh extraction uses extract_mesh.ipynb and requires PyMCubes.
pip install trimesh pyrender PyMCubes

What people use it for

  • Reproducing the view synthesis results from the NeRF paper.
  • Studying how a fully connected network represents a scene with volume rendering.
  • Training a model on your own posed photos of a single object or room.
  • Extracting a triangle mesh from a trained network with marching cubes.

Frequently asked questions

Does NeRF have a GUI or app?

No. The README describes command-line Python code and Jupyter notebooks, with no graphical interface. Users who want a point-and-click tool will need to look at other projects.

What hardware do I need to run NeRF?

The README says training needs a single GPU. Optimizing a NeRF takes a few hours to a day or two depending on resolution, and rendering takes under a second to about 30 seconds.

Is NeRF free and open source?

Yes. The repository is released under the MIT licence, as listed on its project page.

Why does NeRF need TensorFlow 1.15?

The README lists Tensorflow 1.15 as the required version and provides environment.yml to install it along with the other dependencies. Using a different setup is not covered by the README.

How do I get camera poses for my own photos?

The README recommends the imgs2poses.py script from the LLFF code, which needs COLMAP. Without poses, the model cannot place your photos in 3D space.

What are alternatives to NeRF?

The README does not compare projects, but Instant-NGP, Nerfstudio, Mip-NeRF and TensoRF are listed as comparable projects in this directory. Check each one's documentation to compare setup and requirements.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

NeRF suits researchers reproducing the paper, students learning neural radiance fields, and developers comfortable with TensorFlow, Python and a single GPU. It is research code with no GUI, so people wanting a polished app or a non-technical workflow should choose a different tool.

Install options & downloads