mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-06 07:48:50 +08:00
Add spherical harmoincs
This commit is contained in:
1 parent
97c9fe2541
commit
cd6342733b
7 files changed
+353
-3
No files matched your search
@@ -9,6 +9,7 @@ from torch import nn
|
||||
from torchtyping import TensorType
|
||||
|
||||
from mattport.nerf.field_modules.base import FieldModule
|
||||
from mattport.utils.math import components_from_spherical_harmonics
|
||||
|
||||
|
||||
class Encoding(FieldModule):
|
||||
@@ -348,3 +349,26 @@ class TensorVMEncoding(Encoding):
|
||||
)
|
||||
|
||||
self.resolution = resolution
|
||||
|
||||
|
||||
class SHEncoding(Encoding):
|
||||
"""Spherical harmonic encoding"""
|
||||
|
||||
def __init__(self, levels: int = 4) -> None:
|
||||
"""
|
||||
Args:
|
||||
levels (int, optional): Number of spherical hamonic levels to encode. Defaults to 4.
|
||||
"""
|
||||
super().__init__(in_dim=3)
|
||||
|
||||
if levels <= 0 or levels > 4:
|
||||
raise ValueError(f"Spherical harmonic encoding only suports 1 to 4 levels, requested {levels}")
|
||||
|
||||
self.levels = levels
|
||||
|
||||
def get_out_dim(self) -> int:
|
||||
return self.levels**2
|
||||
|
||||
@torch.no_grad()
|
||||
def encode(self, in_tensor: TensorType[..., "input_dim"]) -> TensorType[..., "output_dim"]:
|
||||
return components_from_spherical_harmonics(levels=self.levels, directions=in_tensor)
|
||||
@@ -75,3 +75,19 @@ class RGBFieldHead(FieldHead):
|
||||
|
||||
def __init__(self, in_dim: int, activation: Optional[nn.Module] = nn.Sigmoid()) -> None:
|
||||
super().__init__(in_dim, out_dim=3, field_head_name=FieldHeadNames.RGB, activation=activation)
|
||||
|
||||
|
||||
class SHFieldHead(FieldHead):
|
||||
"""Spherical harmonics output"""
|
||||
|
||||
def __init__(self, in_dim: int, levels: int = 3, channels: int = 3, activation: Optional[nn.Module] = None) -> None:
|
||||
"""_summary_
|
||||
|
||||
Args:
|
||||
in_dim (int): Input dimension
|
||||
levels (int, optional): Number of spherical harmonics layers. Defaults to 3.
|
||||
channels (int, optional): Number of channels. Defaults to 3 (ie RGB).
|
||||
activation (Optional[nn.Module], optional): Output activation. Defaults to None.
|
||||
"""
|
||||
out_dim = channels * levels**2
|
||||
super().__init__(in_dim, out_dim=out_dim, field_head_name=FieldHeadNames.RGB, activation=activation)
|
||||
Reference in new issue
Block a user