Skip to content

Commit 51de308

Browse files
davnov134facebook-github-bot
authored andcommitted
Readme
Summary: Adds the readme file. Reviewed By: nikhilaravi Differential Revision: D25684459 fbshipit-source-id: f1aaa621a2a67c98d5fcfe33fe9bbfea8f95b537
1 parent 2628fb5 commit 51de308

File tree

7 files changed

+87
-5
lines changed

7 files changed

+87
-5
lines changed

projects/nerf/README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
Neural Radiance Fields in PyTorch3D
2+
===================================
3+
4+
This project implements the Neural Radiance Fields (NeRF) from [1].
5+
6+
Installation
7+
------------
8+
1) [Install PyTorch3D](https://github.com/facebookresearch/pytorch3d/blob/master/INSTALL.md)
9+
- Note that this repo requires `PyTorch` version `>= v1.6.0` due to dependency on `torch.searchsorted`.
10+
11+
2) Install other dependencies:
12+
- [`visdom`](https://github.com/facebookresearch/visdom)
13+
- [`hydra`](https://github.com/facebookresearch/hydra)
14+
- [`Pillow`](https://python-pillow.org/)
15+
- [`requests`](https://pypi.org/project/requests/)
16+
17+
E.g. using `pip`:
18+
```
19+
pip install visdom
20+
pip install hydra-core --upgrade
21+
pip install Pillow
22+
pip install requests
23+
```
24+
25+
Exporting videos further requires a working `ffmpeg`.
26+
27+
Training NeRF
28+
-------------
29+
```
30+
python ./train_nerf.py --config-name lego
31+
```
32+
will train the model from [1] on the Lego dataset.
33+
34+
Note that the script outputs visualizations to `Visdom`. In order to enable this, make sure to start the visdom server (before launching the training) with the following command:
35+
```
36+
python -m visdom.server
37+
```
38+
Note that training on the "lego" scene takes roughly 24 hours on a single Tesla V100.
39+
40+
#### Training data
41+
Note that the `train_nerf.py` script will automatically download the relevant dataset in case it is missing.
42+
43+
Testing NeRF
44+
------------
45+
```
46+
python ./test_nerf.py --config-name lego
47+
```
48+
Will load a trained model from the `./checkpoints` directory and evaluate it on the test split of the corresponding dataset (Lego in the case above).
49+
50+
### Exporting multi-view video of the radience field
51+
Furthermore, the codebase supports generating videos of the neural radiance field.
52+
The following generates a turntable video of the Lego scene:
53+
```
54+
python ./test_nerf.py --config-name=lego test.mode='export_video'
55+
```
56+
Note that this requires a working `ffmpeg` for generating the video from exported frames.
57+
58+
Additionally, note that generation of the video in the original resolution is quite slow. In order to speed up the process, one can decrease the resolution of the output video by setting the `data.image_size` flag:
59+
```
60+
python ./test_nerf.py --config-name=lego test.mode='export_video' data.image_size="[128,128]"
61+
```
62+
This will generate the video in a lower `128 x 128` resolution.
63+
64+
65+
Training & testing on other datasets
66+
------------------------------------
67+
Currently we support the following datasets:
68+
- lego `python ./train_nerf.py --config-name lego`
69+
- fern `python ./train_nerf.py --config-name fern`
70+
- pt3logo `python ./train_nerf.py --config-name pt3logo`
71+
72+
The dataset files are located in the following public S3 bucket:
73+
https://dl.fbaipublicfiles.com/pytorch3d_nerf_data
74+
75+
Attribution: `lego` and `fern` are data from the original code release of [1] in https://drive.google.com/drive/folders/128yBriW1IG_3NJ5Rp7APSTZsJqdJdfc1, which are hosted under the CC-BY license (https://creativecommons.org/licenses/by/4.0/) The S3 bucket files contains the same images while the camera matrices have been adjusted to follow the PyTorch3D convention.
76+
77+
78+
#### References
79+
[1] Ben Mildenhall and Pratul P. Srinivasan and Matthew Tancik and Jonathan T. Barron and Ravi Ramamoorthi and Ren Ng, NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis, ECCV2020

projects/nerf/nerf/dataset.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
22
import os
3-
from typing import Tuple, Optional, List
3+
from typing import List, Optional, Tuple
44

55
import numpy as np
66
import requests
@@ -9,6 +9,7 @@
99
from pytorch3d.renderer import PerspectiveCameras
1010
from torch.utils.data import Dataset
1111

12+
1213
DEFAULT_DATA_ROOT = os.path.join(
1314
os.path.dirname(os.path.realpath(__file__)), "..", "data"
1415
)

projects/nerf/nerf/eval_video_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Tuple
44

55
import torch
6-
from pytorch3d.renderer import look_at_view_transform, PerspectiveCameras
6+
from pytorch3d.renderer import PerspectiveCameras, look_at_view_transform
77

88

99
def generate_eval_video_cameras(

projects/nerf/nerf/nerf_renderer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
2-
from typing import Tuple, List, Optional
2+
from typing import List, Optional, Tuple
33

44
import torch
55
from pytorch3d.renderer import ImplicitRenderer, ray_bundle_to_ray_points
@@ -11,7 +11,7 @@
1111
from .implicit_function import NeuralRadianceField
1212
from .raymarcher import EmissionAbsorptionNeRFRaymarcher
1313
from .raysampler import NeRFRaysampler, ProbabilisticRaysampler
14-
from .utils import sample_images_at_mc_locs, calc_psnr, calc_mse
14+
from .utils import calc_mse, calc_psnr, sample_images_at_mc_locs
1515

1616

1717
class RadianceFieldRenderer(torch.nn.Module):

projects/nerf/nerf/raysampler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import List
44

55
import torch
6-
from pytorch3d.renderer import RayBundle, NDCGridRaysampler, MonteCarloRaysampler
6+
from pytorch3d.renderer import MonteCarloRaysampler, NDCGridRaysampler, RayBundle
77
from pytorch3d.renderer.cameras import CamerasBase
88

99
from .utils import sample_pdf

projects/nerf/test_nerf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from omegaconf import DictConfig
1414
from PIL import Image
1515

16+
1617
CONFIG_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "configs")
1718

1819

projects/nerf/train_nerf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from omegaconf import DictConfig
1515
from visdom import Visdom
1616

17+
1718
CONFIG_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "configs")
1819

1920

0 commit comments

Comments
 (0)