mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-04 14:58:55 +08:00
nerf-w and semantic-nerf initial implementations (#73)
* initial nerfw code * nerfw should be implmented correctly now * semantic nerf in progress. data loader is too slow and not clean right now * added implementation of semantic nerf * mend
This commit is contained in:
1 parent
97c9fe2541
commit
1c1a58c4e5
22 files changed
+725
-92
No files matched your search
@@ -0,0 +1,30 @@
|
||||
"""
|
||||
Code for embeddings.
|
||||
"""
|
||||
|
||||
|
||||
import torch
|
||||
from torchtyping import TensorType
|
||||
from mattport.nerf.field_modules.base import FieldModule
|
||||
|
||||
|
||||
class Embedding(FieldModule):
|
||||
"""Index into embeddings."""
|
||||
|
||||
def __init__(self, in_dim: int, out_dim: int) -> None:
|
||||
"""
|
||||
Args:
|
||||
in_dim (int): Number of embeddings
|
||||
out_dim (int): Dimension of the embedding vectors
|
||||
"""
|
||||
super().__init__()
|
||||
self.in_dim = in_dim
|
||||
self.out_dim = out_dim
|
||||
self.build_nn_modules()
|
||||
|
||||
def build_nn_modules(self) -> None:
|
||||
self.embedding = torch.nn.Embedding(self.in_dim, self.out_dim)
|
||||
|
||||
def forward(self, in_tensor: TensorType[..., "input_dim"]) -> TensorType[..., "output_dim"]:
|
||||
"""Call forward"""
|
||||
return self.embedding(in_tensor)
|
||||
@@ -15,6 +15,11 @@ class FieldHeadNames(Enum):
|
||||
|
||||
RGB = "rgb"
|
||||
DENSITY = "density"
|
||||
UNCERTAINTY = "uncertainty"
|
||||
TRANSIENT_RGB = "transient_rgb"
|
||||
TRANSIENT_DENSITY = "transient_density"
|
||||
SEMANTICS_STUFF = "semantics_stuff"
|
||||
SEMANTICS_THING = "semantics_thing"
|
||||
|
||||
|
||||
class FieldHead(FieldModule):
|
||||
@@ -66,12 +71,53 @@ class FieldHead(FieldModule):
|
||||
class DensityFieldHead(FieldHead):
|
||||
"""Density output"""
|
||||
|
||||
def __init__(self, in_dim: int, activation: Optional[nn.Module] = nn.Softplus()) -> None:
|
||||
super().__init__(in_dim, out_dim=1, field_head_name=FieldHeadNames.DENSITY, activation=activation)
|
||||
def __init__(
|
||||
self, in_dim: int, field_head_name=FieldHeadNames.DENSITY, activation: Optional[nn.Module] = nn.Softplus()
|
||||
) -> None:
|
||||
super().__init__(in_dim, out_dim=1, field_head_name=field_head_name, activation=activation)
|
||||
|
||||
|
||||
class RGBFieldHead(FieldHead):
|
||||
"""RGB output"""
|
||||
|
||||
def __init__(self, in_dim: int, activation: Optional[nn.Module] = nn.Sigmoid()) -> None:
|
||||
super().__init__(in_dim, out_dim=3, field_head_name=FieldHeadNames.RGB, activation=activation)
|
||||
def __init__(
|
||||
self, in_dim: int, field_head_name=FieldHeadNames.RGB, activation: Optional[nn.Module] = nn.Sigmoid()
|
||||
) -> None:
|
||||
super().__init__(in_dim, out_dim=3, field_head_name=field_head_name, activation=activation)
|
||||
|
||||
|
||||
class UncertaintyFieldHead(FieldHead):
|
||||
"""Uncertainty output"""
|
||||
|
||||
def __init__(
|
||||
self, in_dim: int, field_head_name=FieldHeadNames.UNCERTAINTY, activation: Optional[nn.Module] = nn.Softplus()
|
||||
) -> None:
|
||||
super().__init__(in_dim, out_dim=1, field_head_name=field_head_name, activation=activation)
|
||||
|
||||
|
||||
class TransientRGBHead(RGBFieldHead):
|
||||
"""Transient RGB output"""
|
||||
|
||||
def __init__(
|
||||
self, in_dim: int, field_head_name=FieldHeadNames.TRANSIENT_RGB, activation: Optional[nn.Module] = nn.Sigmoid()
|
||||
) -> None:
|
||||
super().__init__(in_dim, field_head_name, activation)
|
||||
|
||||
|
||||
class TransientDensityHead(DensityFieldHead):
|
||||
"""Transient density output"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
in_dim: int,
|
||||
field_head_name=FieldHeadNames.TRANSIENT_DENSITY,
|
||||
activation: Optional[nn.Module] = nn.Softplus(),
|
||||
) -> None:
|
||||
super().__init__(in_dim, field_head_name, activation)
|
||||
|
||||
|
||||
class SemanticStuffHead(FieldHead):
|
||||
"""Semantic stuff output"""
|
||||
|
||||
def __init__(self, in_dim: int, num_classes: int, field_head_name=FieldHeadNames.SEMANTICS_STUFF) -> None:
|
||||
super().__init__(in_dim, out_dim=num_classes, field_head_name=field_head_name, activation=None)
|
||||
Reference in new issue
Block a user