Serializing JSON code for drawable objects (and some documentation) (#222)

* some comments and starting serializing comments. on plane w/o formatter

* fixing pylint and black

* removed changes in file

* revert file

* addressing comments

* remove abstract

Co-authored-by: Ethan Weber <ethanweber@Ethans-MacBook-Pro.local>
This commit is contained in:
Ethan WeberandEthan Weber authored and GitHub committed 2022-07-28 13:55:58 -05:00
1 parent 44a7fa288c
commit d13a766b9e
13 files changed
+240 -106

No files matched your search

+7 -9
View File
@@ -30,6 +30,7 @@ from nerfactory.cameras.rays import RayBundle
from nerfactory.data.structs import DatasetInputs, SceneBounds
from nerfactory.graphs.modules.ray_generator import RayGenerator
from nerfactory.utils import profiler
from nerfactory.utils.callbacks import Callback
from nerfactory.utils.config import GraphConfig
from nerfactory.utils.misc import (
get_masked_dict,
@@ -58,10 +59,6 @@ class AbstractGraph(nn.Module):
# to keep track of which device the nn.Module is on
self.device_indicator_param = nn.Parameter(torch.empty(0))
def get_device(self):
"""Returns the device that the torch parameters are on."""
return self.device_indicator_param.device
@property
def device(self):
"""Returns the device that the graph is on."""
@@ -73,7 +70,8 @@ class AbstractGraph(nn.Module):
class Graph(AbstractGraph):
"""Where everything (Fields, Optimizers, Samplers, Visualization, etc) is linked together. This should be
"""Graph class
Where everything (Fields, Optimizers, Samplers, Visualization, etc) is linked together. This should be
subclassed for custom NeRF model.
Args:
@@ -122,9 +120,9 @@ class Graph(AbstractGraph):
self.vis_outputs = None
self.default_output_name = None
def register_callbacks(self): # pylint:disable=no-self-use
"""Option to register callback for training functions"""
self.callbacks = []
def get_training_callbacks(self) -> List[Callback]: # pylint:disable=no-self-use
"""Returns a list of callbacks that run functions at the specified training iterations."""
return []
def populate_density_field(self):
"""Set the scene density field to use."""
@@ -235,7 +233,7 @@ class Graph(AbstractGraph):
def get_outputs_for_camera(self, camera: Camera):
"""Get the graph outputs for a Camera."""
camera_ray_bundle = camera.get_camera_ray_bundle(device=self.get_device())
camera_ray_bundle = camera.get_camera_ray_bundle(device=self.device)
return self.get_outputs_for_camera_ray_bundle(camera_ray_bundle)
@abstractmethod
+12 -9
View File
@@ -36,22 +36,25 @@ from nerfactory.utils.callbacks import Callback
class NGPGraph(Graph):
"""Instant NGP graph
"""Instant NGP graph"""
Args:
field_implementation (str): one of "torch" or "tcnn", or other fields in 'field_implementation_to_class'
kwargs: additional params to pass up to the parent class Graph
"""
def __init__(self, field_implementation="torch", intrinsics=None, camera_to_world=None, **kwargs) -> None:
def __init__(self, field_implementation="torch", **kwargs) -> None:
assert field_implementation in field_implementation_to_class
self.field_implementation = field_implementation
self.field = None
super().__init__(intrinsics=intrinsics, camera_to_world=camera_to_world, **kwargs)
super().__init__(**kwargs)
def register_callbacks(self) -> None:
"""defining callbacks to run after every training iteration"""
def get_training_callbacks(self) -> List[Callback]:
assert self.density_field is not None
self.callbacks = [
return [
Callback(
self.density_field.update_every_num_iters,
self.density_field.update_density_grid,
update_every_num_iters=self.density_field.update_every_num_iters,
func=self.density_field.update_density_grid,
density_eval_func=self.field.density_fn,
)
]
@@ -119,7 +122,7 @@ class NGPGraph(Graph):
return outputs
def get_loss_dict(self, outputs, batch, metrics_dict, loss_coefficients):
device = self.get_device()
device = self.device
image = batch["image"].to(device)
if "alive_ray_mask" in outputs:
mask = outputs["alive_ray_mask"]
+6 -6
View File
@@ -82,17 +82,17 @@ class NeRFGraph(Graph):
**kwargs,
)
def register_callbacks(self) -> None:
"""defining callbacks to run after every training iteration"""
self.callbacks = []
def get_training_callbacks(self) -> List[Callback]:
callbacks = []
if self.density_field is not None:
self.callbacks += [
callbacks = [
Callback(
self.density_field.update_every_num_iters,
self.density_field.update_density_grid,
update_every_num_iters=self.density_field.update_every_num_iters,
func=self.density_field.update_density_grid,
density_eval_func=self.field_coarse.density_fn,
)
]
return callbacks # type: ignore
def populate_fields(self):
"""Set the fields."""