mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-26 10:59:53 +08:00
Serializing JSON code for drawable objects (and some documentation) (#222)
* some comments and starting serializing comments. on plane w/o formatter * fixing pylint and black * removed changes in file * revert file * addressing comments * remove abstract Co-authored-by: Ethan Weber <ethanweber@Ethans-MacBook-Pro.local>
This commit is contained in:
1 parent
44a7fa288c
commit
d13a766b9e
13 files changed
+240
-106
No files matched your search
@@ -30,10 +30,10 @@ def _create_grid_coords(resolution: int, device: torch.device = "cpu") -> Tensor
|
||||
|
||||
Args:
|
||||
resolution (int): The 3D resolution of the grid.
|
||||
device (torch.device): Which device you want the returned tensor to live int.
|
||||
device (torch.device): Which device you want the returned tensor to live on.
|
||||
|
||||
Returns:
|
||||
TensorType["n_coords", 3]: All grid coordinates with shape [res * res * res, 3]
|
||||
TensorType["n_coords", 3]: All grid coordinates with shape [res * res * res, 3].
|
||||
"""
|
||||
arrange = torch.arange(resolution, device=device)
|
||||
grid_x, grid_y, grid_z = torch.meshgrid([arrange, arrange, arrange], indexing="ij")
|
||||
@@ -51,9 +51,9 @@ class DensityGrid(nn.Module):
|
||||
on the scale but all shares the same center.
|
||||
|
||||
For example:
|
||||
- `center=0`, `base_scale=3`, `num_cascades=1` would create one grid (lvl=0) covers [-1.5, -1.5, -1.5, 1.5, 1.5, 1.5].
|
||||
- `center=0`, `base_scale=3`, `num_cascades=2` would create one grid (lvl=0) covers [-1.5, -1.5, -1.5, 1.5, 1.5, 1.5],
|
||||
and one more grid (lvl=1) covers [-3, -3, -3, 3, 3, 3].
|
||||
- `center=0`, `base_scale=3`, `num_cascades=1` would create one grid (lvl=0) covers the aabb [[-1.5, -1.5, -1.5], [1.5, 1.5, 1.5]].
|
||||
- `center=0`, `base_scale=3`, `num_cascades=2` would create one grid (lvl=0) covers the aabb [[-1.5, -1.5, -1.5], [1.5, 1.5, 1.5]],
|
||||
and one more grid (lvl=1) covers the aabb [[-3, -3, -3], [3, 3, 3]].
|
||||
|
||||
Normally you can simply set the `center` to the scene center, and `base_scale` to be the scene scale, and use
|
||||
`num_cascades=1` to create a single level density grid that covers the scene.
|
||||
@@ -68,11 +68,11 @@ class DensityGrid(nn.Module):
|
||||
TODO(ruilongli): support `center` and `base_scale` with 3-dim.
|
||||
|
||||
Args:
|
||||
center (float, optional): Center of all the grids in the world space. Defaults to 0.
|
||||
base_scale (float, optional): Center of the scale of the base level grid. Defaults to 1.
|
||||
num_cascades (int, optional): Number of the cascaded multi-res levels. Defaults to 1.
|
||||
resolution (int, optional): Resolution of the grid. Defaults to 128.
|
||||
update_every_num_iters (int, optional): How frequently to update the grid values. Defaults to 16.
|
||||
center (float): Center of all the grids in the world space. Defaults to 0.
|
||||
base_scale (float): Center of the scale of the base level grid. Defaults to 1.
|
||||
num_cascades (int): Number of the cascaded multi-res levels. Defaults to 1.
|
||||
resolution (int): Resolution of the grid. Defaults to 128.
|
||||
update_every_num_iters (int): How frequently to update the grid values. Defaults to 16.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
@@ -157,11 +157,11 @@ class DensityGrid(nn.Module):
|
||||
"""Update the density grid in EMA way.
|
||||
|
||||
Args:
|
||||
density_eval_func (Callable): A Callable function that takes in sample positions (N, 3) and
|
||||
density_eval_func: A Callable function that takes in sample positions (N, 3) and
|
||||
returns densities (N, 1).
|
||||
step (int): The current training step. Instant-NGP has a warmup stage where all cells are updated.
|
||||
step: The current training step. Instant-NGP has a warmup stage where all cells are updated.
|
||||
After certain amount of steps (256), it speeds up by only update sampled cells.
|
||||
density_threshold (float): The threshold to prune cells. Recommand to calculate it using this rule:
|
||||
density_threshold (float): The threshold to prune cells. Recommended to calculate it using this rule:
|
||||
`weight_threshold / dt`. For example for Instant-NGP on Lego, the minimum step size `dt` is
|
||||
`3` (scale of the scene) * `sqrt(3)` / `1024` (number of samples). And if we want to the weight
|
||||
threshold to be `0.01`, we will get `0.01 / (3 * sqrt(3) / 1024) ~= 2.` for density threshold.
|
||||
|
||||
@@ -23,6 +23,7 @@ import torch
|
||||
from torch.nn.parameter import Parameter
|
||||
|
||||
from nerfactory.cameras.rays import RaySamples
|
||||
from nerfactory.data.structs import SceneBounds
|
||||
from nerfactory.fields.base import Field
|
||||
from nerfactory.fields.modules.encoding import Encoding, HashEncoding, SHEncoding
|
||||
from nerfactory.fields.modules.field_heads import FieldHeadNames
|
||||
@@ -36,13 +37,6 @@ except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
def get_normalized_positions(positions, aabb):
|
||||
"""Return normalized positions in range [0, 1] based on the aabb axis-aligned bounding box."""
|
||||
aabb_lengths = aabb[1] - aabb[0]
|
||||
positions = (positions - aabb[0]) / aabb_lengths
|
||||
return positions
|
||||
|
||||
|
||||
def get_normalized_directions(directions):
|
||||
"""SH encoding must be in the range [0, 1]"""
|
||||
return (directions + 1.0) / 2.0
|
||||
@@ -105,7 +99,7 @@ class TCNNInstantNGPField(Field):
|
||||
|
||||
def get_density(self, ray_samples: RaySamples):
|
||||
"""Computes and returns the densities."""
|
||||
positions = get_normalized_positions(ray_samples.frustums.get_positions(), self.aabb)
|
||||
positions = SceneBounds.get_normalized_positions(ray_samples.frustums.get_positions(), self.aabb)
|
||||
positions_flat = positions.view(-1, 3)
|
||||
h = self.mlp_base(positions_flat).view(*ray_samples.frustums.shape, -1)
|
||||
density_before_activation, base_mlp_out = torch.split(h, [1, self.geo_feat_dim], dim=-1)
|
||||
@@ -156,7 +150,7 @@ class TorchInstantNGPField(NeRFField):
|
||||
|
||||
def get_density(self, ray_samples: RaySamples):
|
||||
normalized_ray_samples = ray_samples
|
||||
normalized_ray_samples.positions = get_normalized_positions(
|
||||
normalized_ray_samples.positions = SceneBounds.get_normalized_positions(
|
||||
normalized_ray_samples.frustums.get_positions(), self.aabb
|
||||
)
|
||||
return super().get_density(normalized_ray_samples)
|
||||
|
||||
Reference in new issue
Block a user