mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-03 14:28:41 +08:00
added base class and methods; done logic for building graph
This commit is contained in:
1 parent
69ea3ae45e
commit
39346ccf40
5 files changed
+80
-40
No files matched your search
@@ -1,4 +1,4 @@
|
||||
"""init modules"""
|
||||
from .encoding import Encoding
|
||||
from .encoding import ScalingAndOffset
|
||||
from .encoding import Encoding, ScalingAndOffset
|
||||
from .mlp import MLP
|
||||
from .module import Module
|
||||
@@ -2,11 +2,11 @@
|
||||
Encoding functions
|
||||
"""
|
||||
import torch
|
||||
from torch import nn
|
||||
from torchtyping import TensorType
|
||||
from mattport.nerf.modules.module import Module
|
||||
|
||||
|
||||
class Encoding(nn.Module):
|
||||
class Encoding(Module):
|
||||
"""Encode an input tensor. Intended to be subclassed"""
|
||||
|
||||
def __init__(self, in_dim: int) -> None:
|
||||
@@ -19,21 +19,6 @@ class Encoding(nn.Module):
|
||||
raise ValueError("Input dimension should be greater than zero")
|
||||
self.in_dim = in_dim
|
||||
|
||||
def build_model(self) -> None:
|
||||
"""TODO: create base module class from which this extends"""
|
||||
|
||||
def set_in_dim(self, in_dim: int) -> None:
|
||||
"""TODO: create base module class from which this extends"""
|
||||
self.in_dim = in_dim
|
||||
|
||||
def get_out_dim(self) -> int:
|
||||
"""Calculates output dimension of encoding.
|
||||
|
||||
Returns:
|
||||
int: output dimension
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def encode(self, in_tensor: TensorType[..., "input_dim"]) -> TensorType[..., "output_dim"]:
|
||||
"""Encodes an input tensor.
|
||||
|
||||
|
||||
@@ -5,9 +5,10 @@ from typing import Optional
|
||||
|
||||
from torch import nn
|
||||
from torchtyping import TensorType
|
||||
from mattport.nerf.modules.module import Module
|
||||
|
||||
|
||||
class MLP(nn.Module):
|
||||
class MLP(Module):
|
||||
"""Multilayer perceptron"""
|
||||
|
||||
def __init__(
|
||||
@@ -54,14 +55,6 @@ class MLP(nn.Module):
|
||||
|
||||
self.net = nn.Sequential(*layers)
|
||||
|
||||
def set_in_dim(self, in_dim: int) -> None:
|
||||
"""TODO: create base module class from which this extends"""
|
||||
self.in_dim = in_dim
|
||||
|
||||
def get_out_dim(self) -> int:
|
||||
"""TODO: create base module class from which this extends"""
|
||||
return self.out_dim
|
||||
|
||||
def forward(self, in_tensor: TensorType[..., "in_dim"]) -> TensorType[..., "out_dim"]:
|
||||
"""Process input with a multilayer perceptron.
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
"""
|
||||
The module baseclass.
|
||||
"""
|
||||
from abc import abstractmethod
|
||||
|
||||
from torch import nn
|
||||
from torchtyping import TensorType
|
||||
|
||||
|
||||
class Module(nn.Module):
|
||||
"""_summary_
|
||||
|
||||
Args:
|
||||
nn (_type_): _description_
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Default initialization of module
|
||||
"""
|
||||
super().__init__()
|
||||
self.in_dim = 0
|
||||
self.out_dim = 0
|
||||
|
||||
def build_nn_modules(self) -> None:
|
||||
"""Function instantiates any torch.nn members within the module.
|
||||
If none exist, do nothing."""
|
||||
|
||||
def set_in_dim(self, in_dim: int) -> None:
|
||||
"""Sets input dimension of encoding
|
||||
|
||||
Args:
|
||||
in_dim (int): input dimension
|
||||
"""
|
||||
if in_dim <= 0:
|
||||
raise ValueError("Input dimension should be greater than zero")
|
||||
self.in_dim = in_dim
|
||||
|
||||
def get_out_dim(self) -> int:
|
||||
"""Calculates output dimension of encoding.
|
||||
|
||||
Returns:
|
||||
int: output dimension
|
||||
"""
|
||||
if not hasattr(self, "out_dim"):
|
||||
raise ValueError("Output dimension has not been set")
|
||||
if self.out_dim <= 0:
|
||||
raise ValueError("Output dimension should be greater than zero")
|
||||
return self.out_dim
|
||||
|
||||
@abstractmethod
|
||||
def forward(self, in_tensor: TensorType[..., "input_dim"]) -> TensorType[..., "output_dim"]:
|
||||
"""_summary_
|
||||
|
||||
Args:
|
||||
x (TensorType[..., "input_dim"]): Input tensor to be encoded
|
||||
|
||||
Raises:
|
||||
NotImplementedError: _description_
|
||||
|
||||
Returns:
|
||||
TensorType[..., "output_dim"]: A encoded input tensor
|
||||
"""
|
||||
raise NotImplementedError
|
||||
Reference in new issue
Block a user