mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-03 14:28:41 +08:00
Restructure into field modules
This commit is contained in:
1 parent
28a66dac72
commit
5e24cbf6fe
13 files changed
+21
-23
No files matched your search
@@ -0,0 +1,61 @@
|
||||
"""
|
||||
Collection of render heads
|
||||
"""
|
||||
from typing import Optional
|
||||
|
||||
from torch import nn
|
||||
from torchtyping import TensorType
|
||||
|
||||
from mattport.nerf.field_modules.base import FieldModule
|
||||
|
||||
|
||||
class RenderHead(FieldModule):
|
||||
"""Base Render head"""
|
||||
|
||||
def __init__(self, in_dim: int, out_dim: int, activation: Optional[nn.Module] = None) -> None:
|
||||
"""
|
||||
Args:
|
||||
in_dim (int): input dimension
|
||||
out_dim (int): output dimension for renderer
|
||||
activation (Optional[nn.Module]): output head activation
|
||||
"""
|
||||
super().__init__()
|
||||
self.in_dim = in_dim
|
||||
self.out_dim = out_dim
|
||||
self.activation = activation
|
||||
|
||||
self.net = None
|
||||
|
||||
def build_nn_modules(self) -> None:
|
||||
layers = [nn.Linear(self.in_dim, self.out_dim)]
|
||||
if self.activation:
|
||||
layers.append(self.activation)
|
||||
print(layers)
|
||||
self.net = nn.Sequential(*layers)
|
||||
|
||||
def forward(self, in_tensor: TensorType[..., "in_dim"]) -> TensorType[..., "out_dim"]:
|
||||
"""Process network output for renderer
|
||||
|
||||
Args:
|
||||
in_tensor (TensorType[..., "in_dim]): Network input
|
||||
|
||||
Returns:
|
||||
TensorType[..., "out_dim"]: Render head output
|
||||
"""
|
||||
if not self.net:
|
||||
raise SystemError("Render head network not initialized. build_nn_modules() should be called.")
|
||||
return self.net(in_tensor)
|
||||
|
||||
|
||||
class DensityHead(RenderHead):
|
||||
"""Density head"""
|
||||
|
||||
def __init__(self, in_dim: int, activation: Optional[nn.Module] = nn.Softplus()) -> None:
|
||||
super().__init__(in_dim, 1, activation)
|
||||
|
||||
|
||||
class RGBHead(RenderHead):
|
||||
"""RGB head"""
|
||||
|
||||
def __init__(self, in_dim: int, activation: Optional[nn.Module] = nn.Sigmoid()) -> None:
|
||||
super().__init__(in_dim, 3, activation)
|
||||
Reference in new issue
Block a user