mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-06 15:59:16 +08:00
Update render_heads to use Module class
This commit is contained in:
1 parent
4b131d4358
commit
03738b1066
3 files changed
+33
-15
No files matched your search
@@ -6,22 +6,30 @@ from typing import Optional
|
|||||||
from torch import nn
|
from torch import nn
|
||||||
from torchtyping import TensorType
|
from torchtyping import TensorType
|
||||||
|
|
||||||
|
from mattport.nerf.modules.module import Module
|
||||||
|
|
||||||
class RenderHead(nn.Module):
|
|
||||||
|
class RenderHead(Module):
|
||||||
"""Base Render head"""
|
"""Base Render head"""
|
||||||
|
|
||||||
def __init__(self, in_dim: int, out_dim: int, activation: Optional[nn.Module]) -> None:
|
def __init__(self, in_dim: int, out_dim: int, activation: Optional[nn.Module]) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
in_dim (int): input dimension
|
in_dim (int): input dimension
|
||||||
out_dim (int): output dimension for renderer
|
out_dim (int): output dimension for renderer
|
||||||
activation (Optional[nn.Module]): output head activation
|
activation (Optional[nn.Module]): output head activation
|
||||||
"""
|
"""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
layers = [nn.Linear(in_dim, out_dim)]
|
self.in_dim = in_dim
|
||||||
if activation:
|
self.out_dim = out_dim
|
||||||
layers.append(activation)
|
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)
|
||||||
self.net = nn.Sequential(*layers)
|
self.net = nn.Sequential(*layers)
|
||||||
|
|
||||||
def forward(self, in_tensor: TensorType[..., "in_dim"]) -> TensorType[..., "out_dim"]:
|
def forward(self, in_tensor: TensorType[..., "in_dim"]) -> TensorType[..., "out_dim"]:
|
||||||
@@ -33,7 +41,8 @@ class RenderHead(nn.Module):
|
|||||||
Returns:
|
Returns:
|
||||||
TensorType[..., "out_dim"]: Render head output
|
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)
|
return self.net(in_tensor)
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
"""
|
||||||
|
Render Head Tests
|
||||||
|
"""
|
||||||
|
from mattport.nerf.modules import render_heads
|
||||||
|
|
||||||
|
|
||||||
|
def test_density_head():
|
||||||
|
"""Test rgb render head"""
|
||||||
|
in_dim = 6
|
||||||
|
density_head = render_heads.DensityHead(in_dim)
|
||||||
|
assert density_head.get_out_dim() == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_rgb_head():
|
||||||
|
"""Test rgb render head"""
|
||||||
|
in_dim = 6
|
||||||
|
rgb_head = render_heads.RGBHead(in_dim)
|
||||||
|
assert rgb_head.get_out_dim() == 3
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import pytest
|
|
||||||
|
|
||||||
|
|
||||||
def test_positional_encoding():
|
|
||||||
assert True
|
|
||||||
|
|
||||||
|
|
||||||
def test_lower_case():
|
|
||||||
assert "MATTPORT".lower() == "mattport"
|
|
||||||
Reference in new issue
Block a user