mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-02 05:48:57 +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
+43
-37
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
The Graph module contains all trainable parameters.
|
||||
"""
|
||||
from abc import abstractmethod
|
||||
import importlib
|
||||
from dataclasses import dataclass
|
||||
from typing import Dict, List, Optional, Set
|
||||
@@ -9,6 +10,8 @@ from omegaconf import DictConfig
|
||||
|
||||
from torch import nn
|
||||
|
||||
from mattport.nerf.dataset.utils import DatasetInputs
|
||||
|
||||
|
||||
@dataclass
|
||||
class GraphInputs:
|
||||
@@ -34,27 +37,38 @@ class Node:
|
||||
class Graph(nn.ModuleDict):
|
||||
"""_summary_"""
|
||||
|
||||
def __init__(self, modules_config: DictConfig) -> None:
|
||||
def __init__(self, intrinsics=None, camera_to_world=None) -> None:
|
||||
super().__init__()
|
||||
self.modules_config = modules_config
|
||||
# create graph and get ordering
|
||||
self.roots = self.construct_graph()
|
||||
self.module_order = self.get_module_order()
|
||||
self.intrinsics = intrinsics
|
||||
self.camera_to_world = camera_to_world
|
||||
|
||||
# initialize graph with known input dimensions; set default in_dim to 0
|
||||
for module_name, module_dict in modules_config.items():
|
||||
module = getattr(importlib.import_module("mattport.nerf.field_modules"), module_dict.class_name)
|
||||
if not module_dict.meta_data.in_dim:
|
||||
module_dict.meta_data.in_dim = 0
|
||||
self[module_name] = module(**module_dict.meta_data)
|
||||
self.modules = None # NOTE(ethan): I'm turning off these features for now
|
||||
if self.modules is not None:
|
||||
# create graph and get ordering
|
||||
self.roots = self.construct_graph()
|
||||
self.module_order = self.get_module_order()
|
||||
|
||||
# calculate input dimensions based on module dependencies
|
||||
for root in self.roots:
|
||||
self.get_in_dim(root)
|
||||
# initialize graph with known input dimensions; set default in_dim to 0
|
||||
for module_name, module_dict in self.modules.items():
|
||||
module = getattr(importlib.import_module("mattport.nerf.field_modules"), module_dict.class_name)
|
||||
if not module_dict.meta_data.in_dim:
|
||||
module_dict.meta_data.in_dim = 0
|
||||
self[module_name] = module(**module_dict.meta_data)
|
||||
|
||||
# instantiate torch.nn members of network
|
||||
for _, module in self.items():
|
||||
module.build_nn_modules()
|
||||
# calculate input dimensions based on module dependencies
|
||||
for root in self.roots:
|
||||
self.get_in_dim(root)
|
||||
|
||||
# instantiate torch.nn members of network
|
||||
for _, module in self.items():
|
||||
module.build_nn_modules()
|
||||
|
||||
self.populate_modules() # populate the modules
|
||||
|
||||
@abstractmethod
|
||||
def populate_modules(self):
|
||||
"""Initializes the modules that are part of the network."""
|
||||
pass
|
||||
|
||||
def get_in_dim(self, curr_node: Node) -> None:
|
||||
"""Dynamically calculates and sets the input dimensions of the modules based on dependency graph
|
||||
@@ -68,7 +82,7 @@ class Graph(nn.ModuleDict):
|
||||
for parent_name in curr_node.parents.keys():
|
||||
in_dim += self[parent_name].get_out_dim()
|
||||
self[curr_node.name].set_in_dim(in_dim)
|
||||
self.modules_config[curr_node.name].meta_data.in_dim = in_dim
|
||||
self.modules[curr_node.name].meta_data.in_dim = in_dim
|
||||
|
||||
for child_node in curr_node.children.values():
|
||||
if not child_node.visited_in_dim:
|
||||
@@ -78,14 +92,14 @@ class Graph(nn.ModuleDict):
|
||||
"""Constructs a dependency graph given the module configuration
|
||||
|
||||
Args:
|
||||
modules_config (dict): module definitions that make up the network
|
||||
config (dict): module definitions that make up the network
|
||||
|
||||
Returns:
|
||||
set: all root nodes of the constructed dependency graph
|
||||
"""
|
||||
processed_modules = {}
|
||||
roots = set()
|
||||
for module_name, module_dict in self.modules_config.items():
|
||||
for module_name, module_dict in self.modules.items():
|
||||
if not module_name in processed_modules:
|
||||
curr_module = Node(name=module_name, children={}, parents={})
|
||||
processed_modules[module_name] = curr_module
|
||||
@@ -125,7 +139,7 @@ class Graph(nn.ModuleDict):
|
||||
"""Generates a graph and determines order of module operations using topological sorting
|
||||
|
||||
Args:
|
||||
modules_config (dict): module definitions that make up the network
|
||||
config (dict): module definitions that make up the network
|
||||
|
||||
Returns:
|
||||
list: ordering of the module names that should be executed
|
||||
@@ -137,20 +151,12 @@ class Graph(nn.ModuleDict):
|
||||
self.topological_sort(root, ordering_stack)
|
||||
return ordering_stack[::-1]
|
||||
|
||||
def forward(self, x):
|
||||
"""_summary_
|
||||
@abstractmethod
|
||||
def forward(self):
|
||||
"""Forward function that needs to be overridden."""
|
||||
pass
|
||||
|
||||
Args:
|
||||
x (_type_): _description_
|
||||
"""
|
||||
# for name in self.module_order:
|
||||
# x = self.modules[name](x)
|
||||
|
||||
## can index into previous results using dictionary
|
||||
# raise NotImplementedError
|
||||
for inputs, node_name, out_name in priority_queue:
|
||||
self.outputs[out_name] = self.modules[node_name](inputs)
|
||||
|
||||
# possibly delete things from output if no longer needed
|
||||
for old_name in :
|
||||
del self.outputs[old_name]
|
||||
@abstractmethod
|
||||
def get_losses(self):
|
||||
"""Computes and returns the losses."""
|
||||
pass
|
||||
Reference in new issue
Block a user