mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-03 22:38:48 +08:00
add encoding boilerplate
This commit is contained in:
1 parent
6d874310c1
commit
47459f4be7
1 file changed
+57
@@ -0,0 +1,57 @@
|
|||||||
|
"""
|
||||||
|
Encoding functions
|
||||||
|
"""
|
||||||
|
from torch import nn
|
||||||
|
from torchtyping import TensorType
|
||||||
|
|
||||||
|
|
||||||
|
class Encoding(nn.Module):
|
||||||
|
"""Encode an input tensor. Intended to be subclassed"""
|
||||||
|
|
||||||
|
def encode(self, in_tensor: TensorType[..., "input_dim"]) -> TensorType[..., "output_dim"]:
|
||||||
|
"""Encodes an input tensor.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
x (TensorType[..., "input_dim"]): Input tensor to be encoded
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
TensorType[..., "output_dim"]: A encoded input tensor
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def forward(self, in_tensor: TensorType[..., "input_dim"]) -> TensorType[..., "output_dim"]:
|
||||||
|
"""Call forward"""
|
||||||
|
return self.encode(in_tensor)
|
||||||
|
|
||||||
|
|
||||||
|
class RFFEncoding(Encoding):
|
||||||
|
"""Random Fourier Feature encoding"""
|
||||||
|
def encode(self, in_tensor: TensorType[..., "input_dim"]) -> TensorType[..., "output_dim"]:
|
||||||
|
"""Encodes an input tensor.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
x (TensorType[..., "input_dim"]): Input tensor to be encoded
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
TensorType[..., "output_dim"]: A encoded input tensor
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
class HashEncoding(Encoding):
|
||||||
|
"""Hash encoding"""
|
||||||
|
def encode(self, in_tensor: TensorType[..., "input_dim"]) -> TensorType[..., "output_dim"]:
|
||||||
|
"""Encodes an input tensor.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
x (TensorType[..., "input_dim"]): Input tensor to be encoded
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
TensorType[..., "output_dim"]: A encoded input tensor
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
encodings_dict = {
|
||||||
|
"RFF": RFFEncoding,
|
||||||
|
"hash": HashEncoding,
|
||||||
|
}
|
||||||
Reference in new issue
Block a user