Skip to content

Commit 5129bc9

Browse files
authored
Merge branch 'nerfstudio-project:main' into main
2 parents ff9d741 + ae6c46c commit 5129bc9

File tree

24 files changed

+547
-306
lines changed

24 files changed

+547
-306
lines changed

colab/demo.ipynb

Lines changed: 10 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"\n",
7575
"%cd /content/\n",
7676
"!pip install --upgrade pip\n",
77-
"!pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 --extra-index-url https://download.pytorch.org/whl/cu118\n",
77+
"!pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 torchaudio==2.0.2+cu118 --extra-index-url https://download.pytorch.org/whl/cu118\n",
7878
"\n",
7979
"# Installing TinyCuda\n",
8080
"%cd /content/\n",
@@ -166,84 +166,6 @@
166166
"print(\"Data Processing Succeeded!\")"
167167
]
168168
},
169-
{
170-
"cell_type": "code",
171-
"execution_count": null,
172-
"metadata": {
173-
"cellView": "form",
174-
"colab": {
175-
"base_uri": "https://localhost:8080/",
176-
"height": 928
177-
},
178-
"id": "VoKDxqEcjmfC",
179-
"outputId": "d2919aa4-96dd-4e50-829f-289e4208882b"
180-
},
181-
"outputs": [
182-
{
183-
"name": "stdout",
184-
"output_type": "stream",
185-
"text": [
186-
"/content\n",
187-
"\u001b[K\u001b[?25h/tools/node/bin/lt -> /tools/node/lib/node_modules/localtunnel/bin/lt.js\n",
188-
"\u001b[K\u001b[?25h+ localtunnel@2.0.2\n",
189-
"added 22 packages from 22 contributors in 2.07s\n",
190-
"https://viewer.nerf.studio/?websocket_url=wss://cyan-facts-matter-34-91-1-218.loca.lt\n",
191-
"You may need to click Refresh Page after you start training!\n"
192-
]
193-
},
194-
{
195-
"data": {
196-
"text/html": [
197-
"\n",
198-
" <iframe\n",
199-
" width=\"100%\"\n",
200-
" height=\"800\"\n",
201-
" src=\"https://viewer.nerf.studio/?websocket_url=wss://cyan-facts-matter-34-91-1-218.loca.lt\"\n",
202-
" frameborder=\"0\"\n",
203-
" allowfullscreen\n",
204-
" ></iframe>\n",
205-
" "
206-
],
207-
"text/plain": [
208-
"<IPython.lib.display.IFrame at 0x7f1d0da6f950>"
209-
]
210-
},
211-
"execution_count": 2,
212-
"metadata": {},
213-
"output_type": "execute_result"
214-
}
215-
],
216-
"source": [
217-
"#@markdown <h1>Set up and Start Viewer</h1>\n",
218-
"\n",
219-
"%cd /content\n",
220-
"\n",
221-
"# Install localtunnel\n",
222-
"# We are using localtunnel https://github.com/localtunnel/localtunnel but ngrok could also be used\n",
223-
"!npm install -g localtunnel\n",
224-
"\n",
225-
"# Tunnel port 7007, the default for\n",
226-
"!rm url.txt 2> /dev/null\n",
227-
"get_ipython().system_raw('lt --port 7007 >> url.txt 2>&1 &')\n",
228-
"\n",
229-
"import time\n",
230-
"time.sleep(3) # the previous command needs time to write to url.txt\n",
231-
"\n",
232-
"\n",
233-
"with open('url.txt') as f:\n",
234-
" lines = f.readlines()\n",
235-
"websocket_url = lines[0].split(\": \")[1].strip().replace(\"https\", \"wss\")\n",
236-
"# from nerfstudio.utils.io import load_from_json\n",
237-
"# from pathlib import Path\n",
238-
"# json_filename = \"nerfstudio/nerfstudio/viewer/app/package.json\"\n",
239-
"# version = load_from_json(Path(json_filename))[\"version\"]\n",
240-
"url = f\"https://viewer.nerf.studio/?websocket_url={websocket_url}\"\n",
241-
"print(url)\n",
242-
"print(\"You may need to click Refresh Page after you start training!\")\n",
243-
"from IPython import display\n",
244-
"display.IFrame(src=url, height=800, width=\"100%\")"
245-
]
246-
},
247169
{
248170
"cell_type": "code",
249171
"execution_count": null,
@@ -256,8 +178,16 @@
256178
"#@markdown <h1>Start Training</h1>\n",
257179
"\n",
258180
"%cd /content\n",
181+
"!pip install colab-xterm\n",
182+
"%load_ext colabxterm\n",
183+
"%env TERM=xterm\n",
184+
"from IPython.display import clear_output\n",
185+
"clear_output(wait=True)\n",
259186
"if os.path.exists(f\"data/nerfstudio/{scene}/transforms.json\"):\n",
260-
" !ns-train nerfacto --viewer.websocket-port 7007 nerfstudio-data --data data/nerfstudio/$scene --downscale-factor 4\n",
187+
" print(\"\\033[1m\" + \"Copy and paste the following command into the terminal window that pops up under this cell.\" + \"\\033[0m\")\n",
188+
" print(f\"ns-train nerfacto --viewer.websocket-port 7007 --viewer.make-share-url True nerfstudio-data --data data/nerfstudio/{scene} --downscale-factor 4\")\n",
189+
" print()\n",
190+
" %xterm\n",
261191
"else:\n",
262192
" from IPython.core.display import display, HTML\n",
263193
" display(HTML('<h3 style=\"color:red\">Error: Data processing did not complete</h3>'))\n",

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ This documentation is organized into 3 parts:
156156
- [Instruct-GS2GS](nerfology/methods/igs2gs.md): Editing 3DGS Scenes with Instructions
157157
- [PyNeRF](nerfology/methods/pynerf.md): Pyramidal Neural Radiance Fields
158158
- [SeaThru-NeRF](nerfology/methods/seathru_nerf.md): Neural Radiance Field for subsea scenes
159+
- [Zip-NeRF](nerfology/methods/zipnerf.md): Anti-Aliased Grid-Based Neural Radiance Fields
159160

160161
**Eager to contribute a method?** We'd love to see you use nerfstudio in implementing new (or even existing) methods! Please view our {ref}`guide<own_method_docs>` for more details about how to add to this list!
161162

docs/nerfology/methods/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ The following methods are supported in nerfstudio:
4242
Instruct-GS2GS<igs2gs.md>
4343
PyNeRF<pynerf.md>
4444
SeaThru-NeRF<seathru_nerf.md>
45+
Zip-NeRF<zipnerf.md>
4546
```
4647

4748
(own_method_docs)=

docs/nerfology/methods/nerf.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Rending RGB images is not the only type of output render supported. It is possib
115115
Associated nerfstudio code:
116116

117117
```python
118-
from nerfstudio.renderers.renderers import RGBRenderer
118+
from nerfstudio.model_components.renderers import RGBRenderer
119119

120120
renderer_rgb = RGBRenderer(background_color=colors.WHITE)
121121
# Ray samples discussed in the next section

docs/nerfology/methods/splat.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ Because the method trains on *full images* instead of bundles of rays, there is
3131
### Running the Method
3232
To run splatfacto, run `ns-train splatfacto --data <data>`. Just like NeRF methods, the splat can be interactively viewed in the web-viewer, loaded from a checkpoint, rendered, and exported.
3333

34+
We provide a few additional variants:
35+
36+
| Method | Description | Memory | Speed |
37+
| ---------------- | ------------------------------ | ------ | ------- |
38+
| `splatfacto` | Default Model | ~6GB | Fast |
39+
| `splatfacto-big` | More Gaussians, Higher Quality | ~12GB | Slower |
40+
41+
42+
A full evalaution of Nerfstudio's implementation of Gaussian Splatting against the original Inria method can be found [here](https://docs.gsplat.studio/tests/eval.html).
43+
3444
#### Quality and Regularization
3545
The default settings provided maintain a balance between speed, quality, and splat file size, but if you care more about quality than training speed or size, you can decrease the alpha cull threshold
3646
(threshold to delete translucent gaussians) and disable culling after 15k steps like so: `ns-train splatfacto --pipeline.model.cull_alpha_thresh=0.005 --pipeline.model.continue_cull_post_densification=False --data <data>`

docs/nerfology/methods/zipnerf.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Zip-NeRF
2+
3+
<h4>A pytorch implementation of "Zip-NeRF: Anti-Aliased Grid-Based Neural Radiance Fields"</h4>
4+
5+
```{button-link} https://jonbarron.info/zipnerf/
6+
:color: primary
7+
:outline:
8+
Paper Website
9+
```
10+
```{button-link} https://github.com/SuLvXiangXin/zipnerf-pytorch
11+
:color: primary
12+
:outline:
13+
Code
14+
```
15+
### Installation
16+
First, install nerfstudio and its dependencies. Then run:
17+
```
18+
pip install git+https://github.com/SuLvXiangXin/zipnerf-pytorch#subdirectory=extensions/cuda
19+
pip install git+https://github.com/SuLvXiangXin/zipnerf-pytorch
20+
```
21+
Finally, install torch_scatter corresponding to your cuda version(https://pytorch-geometric.com/whl/torch-2.0.1%2Bcu118.html).
22+
23+
24+
### Running Model
25+
26+
```bash
27+
ns-train zipnerf --data {DATA_DIR/SCENE}
28+
```
29+
30+
## Overview
31+
Zipnerf combines mip-NeRF 360’s overall framework with iNGP’s featurization approach.
32+
Following mip-NeRF, zipnerf assume each pixel corresponds to a cone. Given an interval along the ray, it construct a set of multisamples that approximate the shape of that conical frustum.
33+
Also, it present an alternative loss that, unlike mip-NeRF 360’s interlevel loss, is continuous and smooth with respect to distance along the ray to prevent z-aliasing.

nerfstudio/configs/external_methods.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,22 @@ class ExternalMethod:
192192
)
193193
)
194194

195+
# Zip-NeRF
196+
external_methods.append(
197+
ExternalMethod(
198+
"""[bold yellow]Zip-NeRF[/bold yellow]
199+
For more information visit https://docs.nerf.studio/nerfology/methods/zipnerf.html
200+
201+
To enable Zip-NeRF, you must install it first by running:
202+
[grey]pip install git+https://github.com/SuLvXiangXin/zipnerf-pytorch#subdirectory=extensions/cuda
203+
and pip install git+https://github.com/SuLvXiangXin/zipnerf-pytorch[/grey]""",
204+
configurations=[
205+
("zipnerf", "A pytorch implementation of 'Zip-NeRF: Anti-Aliased Grid-Based Neural Radiance Fields'")
206+
],
207+
pip_package="pip install git+https://github.com/SuLvXiangXin/zipnerf-pytorch",
208+
)
209+
)
210+
195211

196212
@dataclass
197213
class ExternalMethodDummyTrainerConfig:

nerfstudio/configs/method_configs.py

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,6 @@
599599
steps_per_eval_all_images=1000,
600600
max_num_iterations=30000,
601601
mixed_precision=False,
602-
gradient_accumulation_steps={"camera_opt": 100},
603602
pipeline=VanillaPipelineConfig(
604603
datamanager=FullImageDatamanagerConfig(
605604
dataparser=NerfstudioDataParserConfig(load_3D_points=True),
@@ -608,7 +607,7 @@
608607
model=SplatfactoModelConfig(),
609608
),
610609
optimizers={
611-
"xyz": {
610+
"means": {
612611
"optimizer": AdamOptimizerConfig(lr=1.6e-4, eps=1e-15),
613612
"scheduler": ExponentialDecaySchedulerConfig(
614613
lr_final=1.6e-6,
@@ -623,15 +622,67 @@
623622
"optimizer": AdamOptimizerConfig(lr=0.0025 / 20, eps=1e-15),
624623
"scheduler": None,
625624
},
626-
"opacity": {
625+
"opacities": {
627626
"optimizer": AdamOptimizerConfig(lr=0.05, eps=1e-15),
628627
"scheduler": None,
629628
},
630-
"scaling": {
629+
"scales": {
631630
"optimizer": AdamOptimizerConfig(lr=0.005, eps=1e-15),
632631
"scheduler": None,
633632
},
634-
"rotation": {"optimizer": AdamOptimizerConfig(lr=0.001, eps=1e-15), "scheduler": None},
633+
"quats": {"optimizer": AdamOptimizerConfig(lr=0.001, eps=1e-15), "scheduler": None},
634+
"camera_opt": {
635+
"optimizer": AdamOptimizerConfig(lr=1e-3, eps=1e-15),
636+
"scheduler": ExponentialDecaySchedulerConfig(lr_final=5e-5, max_steps=30000),
637+
},
638+
},
639+
viewer=ViewerConfig(num_rays_per_chunk=1 << 15),
640+
vis="viewer",
641+
)
642+
643+
method_configs["splatfacto-big"] = TrainerConfig(
644+
method_name="splatfacto",
645+
steps_per_eval_image=100,
646+
steps_per_eval_batch=0,
647+
steps_per_save=2000,
648+
steps_per_eval_all_images=1000,
649+
max_num_iterations=30000,
650+
mixed_precision=False,
651+
pipeline=VanillaPipelineConfig(
652+
datamanager=FullImageDatamanagerConfig(
653+
dataparser=NerfstudioDataParserConfig(load_3D_points=True),
654+
cache_images_type="uint8",
655+
),
656+
model=SplatfactoModelConfig(
657+
cull_alpha_thresh=0.005,
658+
continue_cull_post_densification=False,
659+
),
660+
),
661+
optimizers={
662+
"means": {
663+
"optimizer": AdamOptimizerConfig(lr=1.6e-4, eps=1e-15),
664+
"scheduler": ExponentialDecaySchedulerConfig(
665+
lr_final=1.6e-6,
666+
max_steps=30000,
667+
),
668+
},
669+
"features_dc": {
670+
"optimizer": AdamOptimizerConfig(lr=0.0025, eps=1e-15),
671+
"scheduler": None,
672+
},
673+
"features_rest": {
674+
"optimizer": AdamOptimizerConfig(lr=0.0025 / 20, eps=1e-15),
675+
"scheduler": None,
676+
},
677+
"opacities": {
678+
"optimizer": AdamOptimizerConfig(lr=0.05, eps=1e-15),
679+
"scheduler": None,
680+
},
681+
"scales": {
682+
"optimizer": AdamOptimizerConfig(lr=0.005, eps=1e-15),
683+
"scheduler": None,
684+
},
685+
"quats": {"optimizer": AdamOptimizerConfig(lr=0.001, eps=1e-15), "scheduler": None},
635686
"camera_opt": {
636687
"optimizer": AdamOptimizerConfig(lr=1e-3, eps=1e-15),
637688
"scheduler": ExponentialDecaySchedulerConfig(lr_final=5e-5, max_steps=30000),

nerfstudio/data/datamanagers/full_images_datamanager.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,26 +180,30 @@ def process_eval_data(idx):
180180
return data
181181

182182
CONSOLE.log("Caching / undistorting train images")
183-
with ThreadPoolExecutor() as executor:
183+
with ThreadPoolExecutor(max_workers=2) as executor:
184184
cached_train = list(
185-
executor.map(
186-
process_train_data,
187-
track(
185+
track(
186+
executor.map(
187+
process_train_data,
188188
range(len(self.train_dataset)),
189-
description="Caching / undistorting train images",
190-
transient=True,
191189
),
190+
description="Caching / undistorting train images",
191+
transient=True,
192+
total=len(self.train_dataset),
192193
)
193194
)
194195

195196
CONSOLE.log("Caching / undistorting eval images")
196-
with ThreadPoolExecutor() as executor:
197+
with ThreadPoolExecutor(max_workers=2) as executor:
197198
cached_eval = list(
198-
executor.map(
199-
process_eval_data,
200-
track(
201-
range(len(self.eval_dataset)), description="Caching / undistorting eval images", transient=True
199+
track(
200+
executor.map(
201+
process_eval_data,
202+
range(len(self.eval_dataset)),
202203
),
204+
description="Caching / undistorting eval images",
205+
transient=True,
206+
total=len(self.eval_dataset),
203207
)
204208
)
205209

@@ -383,6 +387,8 @@ def _undistort_image(
383387
mask = cv2.undistort(mask, K, distortion_params, None, newK) # type: ignore
384388
mask = mask[y : y + h, x : x + w]
385389
mask = torch.from_numpy(mask).bool()
390+
if len(mask.shape) == 2:
391+
mask = mask[:, :, None]
386392
K = newK
387393

388394
elif camera.camera_type.item() == CameraType.FISHEYE.value:
@@ -402,6 +408,8 @@ def _undistort_image(
402408
mask = mask.astype(np.uint8) * 255
403409
mask = cv2.fisheye.undistortImage(mask, K, distortion_params, None, newK)
404410
mask = torch.from_numpy(mask).bool()
411+
if len(mask.shape) == 2:
412+
mask = mask[:, :, None]
405413
K = newK
406414
elif camera.camera_type.item() == CameraType.FISHEYE624.value:
407415
fisheye624_params = torch.cat(
@@ -494,6 +502,8 @@ def _undistort_image(
494502
)
495503
/ 255.0
496504
).bool()[..., None]
505+
if len(mask.shape) == 2:
506+
mask = mask[:, :, None]
497507
assert mask.shape == (undist_h, undist_w, 1)
498508
K = undist_K.numpy()
499509
else:

0 commit comments

Comments
 (0)