Occupancy grid (#79)

* occupancy grid in progress

* visualizing occupancy grid. currently restructing field and renderer head outputs

* black and pylint. broke nerfw and semantic nerf but it's okay

* get_project_root
This commit is contained in:
Ethan Weber authored and GitHub committed 2022-05-17 19:09:25 -07:00
1 parent 5c2d8c2a0b
commit fb440fedf3
23 files changed
+423 -217

No files matched your search

+1 -1
View File
@@ -10,7 +10,7 @@ from tqdm import tqdm
from mattport.nerf.dataset.collate import CollateIterDataset, collate_batch_size_one
from mattport.nerf.dataset.image_dataset import ImageDataset, collate_batch
from mattport.nerf.dataset.utils import get_dataset_inputs
from mattport.nerf.field_modules.ray_generator import RayGenerator
from mattport.nerf.ray_generator import RayGenerator
from mattport.utils.io import get_absolute_path
from mattport.viewer.plotly import visualize_dataset
@@ -7,7 +7,6 @@ from torch import nn
from mattport.nerf.field_modules.field_heads import (
DensityFieldHead,
FieldHead,
FieldHeadNames,
RGBFieldHead,
SHFieldHead,
)
@@ -17,9 +16,8 @@ def test_field_output():
"""Test render output"""
in_dim = 6
out_dim = 4
field_head_name = FieldHeadNames.DENSITY
activation = nn.ReLU()
render_head = FieldHead(in_dim=in_dim, out_dim=out_dim, field_head_name=field_head_name, activation=activation)
render_head = FieldHead(in_dim=in_dim, out_dim=out_dim, activation=activation)
assert render_head.get_out_dim() == out_dim
x = torch.ones((9, in_dim))
+22
View File
@@ -0,0 +1,22 @@
"""
Code to test the occupancy grid.
"""
import torch
from mattport.nerf.occupancy_grid import OccupancyGrid
def test_occupancy_grid():
"""For testing the occupancy grid."""
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
num_cascades = 1
resolution = 128
aabb = torch.tensor([[-1, -1, -1], [1, 1, 1]], dtype=torch.float32).to(device)
grid = OccupancyGrid(num_cascades, resolution, aabb)
grid.to(device)
density_fn = lambda x: x[..., 0:1] # xyz (..., 3) => density (...,)
grid.update_occupancy_grid(density_fn=density_fn)
if __name__ == "__main__":
test_occupancy_grid()
+11 -11
View File
@@ -11,17 +11,17 @@ def test_rgb_renderer():
"""Test RGB volumetric rendering"""
num_samples = 10
rgb = torch.ones((3, num_samples, 3))
rgb_samples = torch.ones((3, num_samples, 3))
weights = torch.ones((3, num_samples))
weights /= torch.sum(weights, axis=-1, keepdim=True)
rgb_renderer = renderers.RGBRenderer()
out = rgb_renderer(rgb=rgb, weights=weights)
assert torch.max(out.rgb) > 0.9
rgb = rgb_renderer(rgb=rgb_samples, weights=weights)
assert torch.max(rgb) > 0.9
out = rgb_renderer(rgb=rgb * 0, weights=weights)
assert torch.max(out.rgb) == pytest.approx(0)
rgb = rgb_renderer(rgb=rgb_samples * 0, weights=weights)
assert torch.max(rgb) == pytest.approx(0)
def test_sh_renderer():
@@ -38,8 +38,8 @@ def test_sh_renderer():
sh_renderer = renderers.SHRenderer()
out = sh_renderer(sh=sh, directions=directions, weights=weights)
assert torch.max(out.rgb) > 0.9
rgb = sh_renderer(sh=sh, directions=directions, weights=weights)
assert torch.max(rgb) > 0.9
def test_acc_renderer():
@@ -51,8 +51,8 @@ def test_acc_renderer():
acc_renderer = renderers.AccumulationRenderer()
out = acc_renderer(weights=weights)
assert torch.max(out.accumulation) > 0.9
accumulation = acc_renderer(weights=weights)
assert torch.max(accumulation) > 0.9
def test_depth_renderer():
@@ -67,8 +67,8 @@ def test_depth_renderer():
depth_renderer = renderers.DepthRenderer()
out = depth_renderer(weights=weights, ts=ts)
assert torch.min(out.depth) > 0
depth = depth_renderer(weights=weights, ts=ts)
assert torch.min(depth) > 0
if __name__ == "__main__":
+1 -1
View File
@@ -5,7 +5,7 @@ import torch
from mattport.nerf.sampler import PDFSampler, UniformSampler
from mattport.structures.rays import RayBundle
from mattport.nerf.field_modules.scene_bounds_collider import NearFarCollider
from mattport.nerf.colliders import NearFarCollider
def test_uniform_sampler():