mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-04 06:49:13 +08:00
Remove density field
This commit is contained in:
1 parent
10d713f84b
commit
4350bc78d6
4 files changed
+28
-82
No files matched your search
@@ -3,21 +3,17 @@ Base class for the graphs.
|
||||
"""
|
||||
|
||||
from abc import abstractmethod
|
||||
from typing import Tuple
|
||||
|
||||
from torch import nn
|
||||
from torchtyping import TensorType
|
||||
|
||||
from mattport.structures.rays import PointSamples, RaySamples
|
||||
from mattport.structures.rays import PointSamples
|
||||
|
||||
|
||||
class Field(nn.Module):
|
||||
"""Base class for fields."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
# minimum weight for it to be valid. used to skip querying the field
|
||||
# TODO(ethan): avoid the hardcoding
|
||||
self.weights_threshold = 1e-4
|
||||
|
||||
def density_fn(self, positions):
|
||||
"""Returns only the density. Used primarily with the occupancy grid."""
|
||||
point_samples = PointSamples(positions=positions)
|
||||
@@ -25,8 +21,15 @@ class Field(nn.Module):
|
||||
return density
|
||||
|
||||
@abstractmethod
|
||||
def get_density(self, point_samples: PointSamples):
|
||||
"""Computes and returns the densities."""
|
||||
def get_density(self, point_samples: PointSamples) -> Tuple[TensorType[..., 1], TensorType[..., "num_features"]]:
|
||||
"""Computes and returns the densities.
|
||||
|
||||
Args:
|
||||
point_samples (PointSamples): Samples locations to compute density.
|
||||
|
||||
Returns:
|
||||
Tuple[TensorType[...,1], TensorType[...,"num_features"]]: A tensor of densities and a tensor of features.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def get_outputs(self, point_samples: PointSamples, density_embedding=None, valid_mask=None):
|
||||
@@ -38,14 +41,3 @@ class Field(nn.Module):
|
||||
field_outputs = self.get_outputs(point_samples, density_embedding=density_embedding)
|
||||
field_outputs["density"] = density
|
||||
return field_outputs
|
||||
|
||||
def forward_with_weight_pruning(self, ray_samples: RaySamples):
|
||||
"""Forward but with pruning based on weights, from the densities."""
|
||||
density, density_embedding = self.get_density(ray_samples)
|
||||
weights = ray_samples.get_weights(density)
|
||||
valid_mask_outputs = weights >= self.weights_threshold
|
||||
field_outputs = self.get_outputs(
|
||||
ray_samples, density_embedding=density_embedding, valid_mask=valid_mask_outputs
|
||||
)
|
||||
field_outputs["density"] = density
|
||||
return field_outputs
|
||||
Reference in new issue
Block a user