mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-07 00:09:14 +08:00
Factor out nerf_field
This commit is contained in:
1 parent
279df6a9ce
commit
9b63adba01
5 files changed
+140
-126
No files matched your search
@@ -2,6 +2,7 @@
|
||||
Encoding functions
|
||||
"""
|
||||
|
||||
from abc import abstractmethod
|
||||
import numpy as np
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
@@ -25,6 +26,7 @@ class Encoding(FieldModule):
|
||||
raise ValueError("Input dimension should be greater than zero")
|
||||
self.in_dim = in_dim
|
||||
|
||||
@abstractmethod
|
||||
def encode(self, in_tensor: TensorType[..., "input_dim"]) -> TensorType[..., "output_dim"]:
|
||||
"""Encodes an input tensor.
|
||||
|
||||
@@ -41,6 +43,16 @@ class Encoding(FieldModule):
|
||||
return self.encode(in_tensor)
|
||||
|
||||
|
||||
class Identity(Encoding):
|
||||
"""Identity encoding (Does not modify input)"""
|
||||
|
||||
def get_out_dim(self) -> int:
|
||||
return self.in_dim
|
||||
|
||||
def encode(self, in_tensor: TensorType[..., "input_dim"]) -> TensorType[..., "output_dim"]:
|
||||
return in_tensor
|
||||
|
||||
|
||||
class ScalingAndOffset(Encoding):
|
||||
"""Simple scaling and offet to input"""
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ class MLP(FieldModule):
|
||||
def __init__(
|
||||
self,
|
||||
in_dim: int,
|
||||
out_dim: int,
|
||||
num_layers: int,
|
||||
layer_width: int = None,
|
||||
layer_width: int,
|
||||
out_dim: Optional[int] = None,
|
||||
skip_connections: Tuple[int] = (),
|
||||
activation: Optional[nn.Module] = nn.ReLU(),
|
||||
out_activation: Optional[nn.Module] = None,
|
||||
@@ -27,16 +27,16 @@ class MLP(FieldModule):
|
||||
|
||||
Args:
|
||||
in_dim (int): Input layer dimension
|
||||
out_dim (int): Ouput layer dimension
|
||||
num_layers (int): Number of network layers
|
||||
layer_width (int): Width of each MLP layer
|
||||
out_dim (int, optional): Ouput layer dimension. Defaults to layer_width
|
||||
activation (Optional[nn.Module], optional): intermediate layer activation function. Defaults to nn.ReLU.
|
||||
out_activation (Optional[nn.Module], optional): output activation function. Defaults to None.
|
||||
"""
|
||||
super().__init__()
|
||||
self.in_dim = in_dim
|
||||
assert self.in_dim > 0
|
||||
self.out_dim = out_dim
|
||||
self.out_dim = out_dim if out_dim is not None else layer_width
|
||||
self.num_layers = num_layers
|
||||
self.layer_width = layer_width
|
||||
self.skip_connections = skip_connections
|
||||
|
||||
Reference in new issue
Block a user