mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-06 07:48:50 +08:00
Get tests passing
This commit is contained in:
1 parent
4325c86997
commit
40f0338eb2
8 files changed
+58
-174
No files matched your search
@@ -21,16 +21,20 @@ class FieldHeadOutputs:
|
||||
class FieldHead(FieldModule):
|
||||
"""Base field output"""
|
||||
|
||||
def __init__(self, in_dim: int, out_dim: int, activation: Optional[nn.Module] = None) -> None:
|
||||
def __init__(
|
||||
self, in_dim: int, out_dim: int, field_quantity_name: str, activation: Optional[nn.Module] = None
|
||||
) -> None:
|
||||
"""
|
||||
Args:
|
||||
in_dim (int): input dimension
|
||||
out_dim (int): output dimension for renderer
|
||||
field_quantity_name (srt): name of field head
|
||||
activation (Optional[nn.Module]): output head activation
|
||||
"""
|
||||
super().__init__()
|
||||
self.in_dim = in_dim
|
||||
self.out_dim = out_dim
|
||||
self.field_quantity_name = field_quantity_name
|
||||
self.activation = activation
|
||||
self.net = None
|
||||
self.build_nn_modules()
|
||||
@@ -41,7 +45,7 @@ class FieldHead(FieldModule):
|
||||
layers.append(self.activation)
|
||||
self.net = nn.Sequential(*layers)
|
||||
|
||||
def forward(self, in_tensor: TensorType[..., "in_dim"]) -> TensorType[..., "out_dim"]:
|
||||
def forward(self, in_tensor: TensorType[..., "in_dim"]) -> FieldHeadOutputs:
|
||||
"""Process network output for renderer
|
||||
|
||||
Args:
|
||||
@@ -64,13 +68,11 @@ class DensityFieldHead(FieldHead):
|
||||
"""Density output"""
|
||||
|
||||
def __init__(self, in_dim: int, activation: Optional[nn.Module] = nn.Softplus()) -> None:
|
||||
super().__init__(in_dim, 1, activation)
|
||||
self.field_quantity_name = "density"
|
||||
super().__init__(in_dim, out_dim=1, field_quantity_name="density", activation=activation)
|
||||
|
||||
|
||||
class RGBFieldHead(FieldHead):
|
||||
"""RGB output"""
|
||||
|
||||
def __init__(self, in_dim: int, activation: Optional[nn.Module] = nn.Sigmoid()) -> None:
|
||||
super().__init__(in_dim, 3, activation)
|
||||
self.field_quantity_name = "rgb"
|
||||
super().__init__(in_dim, out_dim=3, field_quantity_name="rgb", activation=activation)
|
||||
@@ -32,7 +32,7 @@ class UniformSampler(nn.Module):
|
||||
near_plane: Optional[float] = None,
|
||||
far_plane: Optional[float] = None,
|
||||
num_samples: Optional[int] = None,
|
||||
) -> TensorType[..., "num_samples", 3]:
|
||||
) -> RaySamples:
|
||||
"""Generates position samples uniformly.
|
||||
|
||||
Args:
|
||||
@@ -77,12 +77,12 @@ class PDFSampler(nn.Module):
|
||||
def forward(
|
||||
self,
|
||||
ray_bundle: RayBundle,
|
||||
coase_ray_samples: RaySamples,
|
||||
coarse_ray_samples: RaySamples,
|
||||
density: TensorType[..., "num_samples", 1],
|
||||
num_samples: Optional[int] = None,
|
||||
randomized: bool = True,
|
||||
eps: float = 1e-5,
|
||||
) -> TensorType[..., "num_samples", 3]:
|
||||
) -> RaySamples:
|
||||
"""Generates position samples given a distribution.
|
||||
|
||||
Args:
|
||||
@@ -102,7 +102,7 @@ class PDFSampler(nn.Module):
|
||||
|
||||
# Calculate weight contributions along ray
|
||||
# Todo(matt): This computation is duplicated
|
||||
delta_density = coase_ray_samples.deltas * density[..., 0]
|
||||
delta_density = coarse_ray_samples.deltas * density[..., 0]
|
||||
alphas = 1 - torch.exp(-delta_density)
|
||||
|
||||
transmittance = torch.cumsum(delta_density[..., :-1], dim=-1)
|
||||
@@ -136,7 +136,7 @@ class PDFSampler(nn.Module):
|
||||
indicies_g = torch.stack([below, above], -1)
|
||||
matched_shape = (indicies_g.shape[0], indicies_g.shape[1], cdf.shape[-1])
|
||||
cdf_g = torch.gather(cdf.unsqueeze(1).expand(matched_shape), dim=2, index=indicies_g)
|
||||
bins_g = torch.gather(coase_ray_samples.bins.unsqueeze(1).expand(matched_shape), dim=2, index=indicies_g)
|
||||
bins_g = torch.gather(coarse_ray_samples.bins.unsqueeze(1).expand(matched_shape), dim=2, index=indicies_g)
|
||||
|
||||
denom = cdf_g[..., 1] - cdf_g[..., 0]
|
||||
denom = torch.where(denom < eps, torch.ones_like(denom), denom)
|
||||
@@ -144,7 +144,7 @@ class PDFSampler(nn.Module):
|
||||
samples = bins_g[..., 0] + t * (bins_g[..., 1] - bins_g[..., 0])
|
||||
|
||||
ray_samples = RaySamples(
|
||||
bins=samples,
|
||||
bins=samples, # TODO(matt) These are not bins!
|
||||
ray_bundle=ray_bundle,
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user