mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-05 23:38:42 +08:00
most code for nerf running
This commit is contained in:
1 parent
c2f3c06b6c
commit
be6fbe799e
16 files changed
+223
-168
No files matched your search
+14
-11
@@ -3,28 +3,32 @@ Multi Layer Perceptron
|
||||
"""
|
||||
from typing import Optional
|
||||
|
||||
import torch
|
||||
from torch import nn
|
||||
from torchtyping import TensorType
|
||||
|
||||
from mattport.nerf.field_modules.encoding import NeRFEncoding
|
||||
from mattport.nerf.field_modules.field_outputs import DensityFieldOutput, RGBFieldOutput
|
||||
from mattport.nerf.field_modules.mlp import MLP
|
||||
from mattport.structures.rays import RayBundle, RaySamples
|
||||
|
||||
|
||||
class NeRFField():
|
||||
class NeRFField(nn.Module):
|
||||
"""Multilayer perceptron"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.build_nn_modules()
|
||||
|
||||
def build_nn_modules(self) -> None:
|
||||
"""Initialize mulilayer perceptron."""
|
||||
"""Initialize modules."""
|
||||
self.encoding_xyz = NeRFEncoding(in_dim=3, num_frequencies=10, min_freq_exp=0.0, max_freq_exp=8.0)
|
||||
self.encoding_dir = NeRFEncoding(in_dim=3, num_frequencies=6, min_freq_exp=0.0, max_freq_exp=4.0)
|
||||
self.mlp_base = MLP(
|
||||
in_dim=self.encoding_xyz.get_out_dim(), out_dim=64, num_layers=8, layer_width=64, activation=nn.ReLU()
|
||||
)
|
||||
self.mlp_rgb = MLP(
|
||||
in_dim=self.base_mlp.get_out_dim() + self.encoding_dir.get_out_dim(),
|
||||
in_dim=self.mlp_base.get_out_dim() + self.encoding_dir.get_out_dim(),
|
||||
out_dim=64,
|
||||
num_layers=2,
|
||||
layer_width=64,
|
||||
@@ -33,20 +37,19 @@ class NeRFField():
|
||||
self.field_output_rgb = RGBFieldOutput(in_dim=self.mlp_rgb.get_out_dim())
|
||||
self.field_output_density = DensityFieldOutput(in_dim=self.mlp_base.get_out_dim())
|
||||
|
||||
def forward(self, in_tensor: TensorType[..., "in_dim"]) -> TensorType[..., "out_dim"]:
|
||||
"""Process input with a multilayer perceptron.
|
||||
def forward(self, xyz: TensorType["num_rays", 3], dirs: TensorType["num_rays", 3]):
|
||||
"""
|
||||
|
||||
Args:
|
||||
in_tensor (TensorType[..., "in_dim]): Network input
|
||||
|
||||
Returns:
|
||||
TensorType[..., "out_dim"]: Network output
|
||||
xyz: ()
|
||||
# TODO(ethan): change the input to be something more abstracted
|
||||
e.g., a FieldInput structure
|
||||
"""
|
||||
|
||||
encoded_xyz = self.encoding_xyz(xyz)
|
||||
encoded_dir = self.encoding_dir(rays.direction)
|
||||
encoded_dir = self.encoding_dir(dirs)
|
||||
base_mlp_out = self.mlp_base(encoded_xyz)
|
||||
rgb_mlp_out = self.mlp_rgb(torch.cat([encoded_dir, base_mlp_out], dim=-1))
|
||||
field_rgb_output = self.field_output_rgb(rgb_mlp_out)
|
||||
field_density_out = self.field_output_density(base_mlp_out)
|
||||
return rgb_coarse
|
||||
return field_rgb_output, field_density_out
|
||||
Reference in new issue
Block a user