mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-25 10:29:51 +08:00
Fix typing errors (#229)
This commit is contained in:
1 parent
be001e8ebe
commit
58212543f5
30 files changed
+236
-147
No files matched your search
@@ -16,6 +16,7 @@
|
||||
The field module baseclass.
|
||||
"""
|
||||
from abc import abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from torch import nn
|
||||
from torchtyping import TensorType
|
||||
@@ -29,7 +30,7 @@ class FieldModule(nn.Module):
|
||||
out_dim (int, optional): Ouput dimension to module.
|
||||
"""
|
||||
|
||||
def __init__(self, in_dim: int = None, out_dim: int = None) -> None:
|
||||
def __init__(self, in_dim: Optional[int] = None, out_dim: Optional[int] = None) -> None:
|
||||
super().__init__()
|
||||
self.in_dim = in_dim
|
||||
self.out_dim = out_dim
|
||||
|
||||
@@ -50,6 +50,8 @@ class Identity(Encoding):
|
||||
"""Identity encoding (Does not modify input)"""
|
||||
|
||||
def get_out_dim(self) -> int:
|
||||
if self.in_dim is None:
|
||||
raise ValueError("Input dimension has not been set")
|
||||
return self.in_dim
|
||||
|
||||
def forward(self, in_tensor: TensorType["bs":..., "input_dim"]) -> TensorType["bs":..., "output_dim"]:
|
||||
@@ -72,6 +74,8 @@ class ScalingAndOffset(Encoding):
|
||||
self.offset = offset
|
||||
|
||||
def get_out_dim(self) -> int:
|
||||
if self.in_dim is None:
|
||||
raise ValueError("Input dimension has not been set")
|
||||
return self.in_dim
|
||||
|
||||
def forward(self, in_tensor: TensorType["bs":..., "input_dim"]) -> TensorType["bs":..., "output_dim"]:
|
||||
@@ -101,6 +105,8 @@ class NeRFEncoding(Encoding):
|
||||
self.include_input = include_input
|
||||
|
||||
def get_out_dim(self) -> int:
|
||||
if self.in_dim is None:
|
||||
raise ValueError("Input dimension has not been set")
|
||||
out_dim = self.in_dim * self.num_frequencies * 2
|
||||
if self.include_input:
|
||||
out_dim += self.in_dim
|
||||
@@ -156,6 +162,8 @@ class RFFEncoding(Encoding):
|
||||
if not scale > 0:
|
||||
raise ValueError("RFF encoding scale should be greater than zero")
|
||||
self.scale = scale
|
||||
if self.in_dim is None:
|
||||
raise ValueError("Input dimension has not been set")
|
||||
b_matrix = torch.normal(mean=0, std=self.scale, size=(self.in_dim, self.num_frequencies))
|
||||
self.register_buffer(name="b_matrix", tensor=b_matrix)
|
||||
self.include_input = include_input
|
||||
|
||||
@@ -42,7 +42,7 @@ class MLP(FieldModule):
|
||||
num_layers: int,
|
||||
layer_width: int,
|
||||
out_dim: Optional[int] = None,
|
||||
skip_connections: Tuple[int] = (),
|
||||
skip_connections: Optional[Tuple[int]] = None,
|
||||
activation: Optional[nn.Module] = nn.ReLU(),
|
||||
out_activation: Optional[nn.Module] = None,
|
||||
) -> None:
|
||||
@@ -67,9 +67,10 @@ class MLP(FieldModule):
|
||||
else:
|
||||
for i in range(self.num_layers - 1):
|
||||
if i == 0:
|
||||
assert i not in list(self.skip_connections), "Skip connection at layer 0 doesn't make sense."
|
||||
if self.skip_connections is not None:
|
||||
assert i not in list(self.skip_connections), "Skip connection at layer 0 doesn't make sense."
|
||||
layers.append(nn.Linear(self.in_dim, self.layer_width))
|
||||
elif i in self.skip_connections:
|
||||
elif self.skip_connections is not None and i in self.skip_connections:
|
||||
layers.append(nn.Linear(self.layer_width + self.in_dim, self.layer_width))
|
||||
else:
|
||||
layers.append(nn.Linear(self.layer_width, self.layer_width))
|
||||
@@ -87,7 +88,7 @@ class MLP(FieldModule):
|
||||
"""
|
||||
x = in_tensor
|
||||
for i, layer in enumerate(self.layers):
|
||||
if i in self.skip_connections:
|
||||
if self.skip_connections is not None and i in self.skip_connections:
|
||||
x = torch.cat([in_tensor, x], -1)
|
||||
x = layer(x)
|
||||
if self.activation:
|
||||
|
||||
Reference in new issue
Block a user