update docstrings and random cleanups (#387)

* fixing docstrings and small nits; up to fileds

* finished adding and fixing docstrings
This commit is contained in:
evonneng authored and GitHub committed 2022-09-10 23:09:44 -07:00
1 parent bd5967461d
commit d50c71ac43
52 files changed
+846 -646

No files matched your search

@@ -29,14 +29,11 @@ from nerfactory.cameras.rays import RaySamples
def _create_grid_coords(resolution: int, device: Union[torch.device, str] = "cpu") -> TensorType["n_coords", 3]:
"""Create 3D grid coordinates
"""Create 3D grid coordinates. Returns all grid coordinates with shape [res * res * res, 3].
Args:
resolution (int): The 3D resolution of the grid.
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].
resolution: The 3D resolution of the grid.
device: Which device you want the returned tensor to live on.
"""
arrange = torch.arange(resolution, device=device)
grid_x, grid_y, grid_z = torch.meshgrid([arrange, arrange, arrange], indexing="ij")
@@ -73,11 +70,11 @@ class DensityGrid(nn.Module):
TODO(ruilongli): support `center` and `base_scale` with 3-dim.
Args:
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.
center: Center of all the grids in the world space. Defaults to 0.
base_scale: Center of the scale of the base level grid. Defaults to 1.
num_cascades: Number of the cascaded multi-res levels. Defaults to 1.
resolution: Resolution of the grid. Defaults to 128.
update_every_num_iters: How frequently to update the grid values. Defaults to 16.
"""
density_grid: TensorType["num_cascades", "resolution_cubed"]
@@ -111,24 +108,16 @@ class DensityGrid(nn.Module):
@torch.no_grad()
def get_all_cells(self) -> List[Tuple[TensorType["n_cells"], TensorType["n_cells", 3]]]:
"""Returns all cells of the grid.
Returns:
List[Tuple[TensorType["n_cells"], TensorType["n_cells", 3]]]: All grid indices and grid
coordinates of all cascade levels.
"""
"""Returns a list of all grid indices and grid coordinates of all cascade levels."""
return [(self.grid_indices, self.grid_coords)] * self.num_cascades
@torch.no_grad()
def sample_uniform_and_occupied_cells(self, n: int) -> List[Tuple[TensorType["n"], TensorType["n", 3]]]:
"""Samples both n uniform and occupied cells (per cascade)
"""Samples both n uniform and occupied cells (per cascade).
Returns a tuple of (sampled grid indices, grid coordinates of all cascade levels).
Args:
n: Number of cells to be sampled.
Returns:
List[Tuple[TensorType["n"], TensorType["n", 3]]]: Sampled grid indices and grid
coordinates of all cascade levels.
"""
device = self.density_grid.device
@@ -164,11 +153,11 @@ class DensityGrid(nn.Module):
returns densities (N, 1).
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. Recommended to calculate it using this rule:
density_threshold: 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.
decay (float): EMA decay for density updating.
decay: EMA decay for density updating.
"""
# create temporary grid
tmp_grid = -torch.ones_like(self.density_grid)
@@ -206,10 +195,9 @@ class DensityGrid(nn.Module):
@torch.no_grad()
def get_densities(self, ray_samples: RaySamples) -> TensorType[..., 1]:
"""Get the density values stored in the density grid.
Args:
ray_samples RaySamples: ray samples
Returns:
TensorType[..., 1]: Density values
ray_samples: ray samples to get density for
"""
positions = ray_samples.frustums.get_positions()
deltas = ray_samples.frustums.ends - ray_samples.frustums.starts