mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-20 06:35:36 +08:00
refactoring configs; pulled network out of graph; created trainer heirarchy (#51)
* changed config graph structure * removed network udner graphs; added new heirarchy trainer * fixed callback in occupancy graph * lint * changed register callback to setter method
This commit is contained in:
1 parent
41073540c1
commit
91ef54963c
19 files changed
+163
-134
No files matched your search
+26
-15
@@ -16,20 +16,31 @@
|
||||
Callback functions for training iterations
|
||||
"""
|
||||
|
||||
from pyrad.graphs.base import Graph
|
||||
from pyrad.fields.occupancy_fields.occupancy_grid import OccupancyGrid
|
||||
from typing import Callable
|
||||
|
||||
|
||||
def update_occupancy(graph: Graph):
|
||||
"""Update the occupancy grid depending on iteration count after every train step"""
|
||||
if not hasattr(graph, "occupancy_pointers"):
|
||||
occupancy_grids = []
|
||||
for _, module in graph.__dict__["_modules"].items():
|
||||
if isinstance(module, OccupancyGrid):
|
||||
occupancy_grids.append(module)
|
||||
graph.occupancy_pointers = occupancy_grids
|
||||
for grid in graph.occupancy_pointers:
|
||||
grid.iteration_count += 1
|
||||
if grid.iteration_count % grid.update_every_num_iters == 0:
|
||||
if grid.density_fn is not None:
|
||||
grid.update_occupancy_grid(grid.density_fn)
|
||||
class Callback:
|
||||
"""Callback Object"""
|
||||
|
||||
def __init__(self, update_every_num_iters: int, func: Callable, *args, **kwargs):
|
||||
self.update_every_num_iters = update_every_num_iters
|
||||
self.func = func
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
|
||||
def before_step(self, step: int):
|
||||
"""callback to run before training step
|
||||
|
||||
Args:
|
||||
step (int): current iteration step
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def after_step(self, step: int):
|
||||
"""callback to run after training step
|
||||
|
||||
Args:
|
||||
step (int): current iteration step
|
||||
"""
|
||||
if step % self.update_every_num_iters == 0:
|
||||
self.func(*self.args, **self.kwargs)
|
||||
+14
-14
@@ -141,13 +141,13 @@ def setup_event_writers(config: DictConfig) -> None:
|
||||
writer_class = getattr(sys.modules[__name__], writer_type)
|
||||
writer_config = logging_configs[writer_type]
|
||||
if writer_type == "LocalWriter":
|
||||
curr_writer = writer_class(writer_config.save_dir, writer_config.stats_to_track, writer_config.max_log_size)
|
||||
curr_writer = writer_class(writer_config.log_dir, writer_config.stats_to_track, writer_config.max_log_size)
|
||||
else:
|
||||
curr_writer = writer_class(writer_config.save_dir)
|
||||
curr_writer = writer_class(writer_config.log_dir)
|
||||
EVENT_WRITERS.append(curr_writer)
|
||||
|
||||
## configure all the global buffer basic information
|
||||
GLOBAL_BUFFER["max_iter"] = config.graph.max_num_iterations
|
||||
GLOBAL_BUFFER["max_iter"] = config.trainer.max_num_iterations
|
||||
GLOBAL_BUFFER["max_buffer_size"] = config.logging.max_buffer_size
|
||||
GLOBAL_BUFFER["steps_per_log"] = config.logging.steps_per_log
|
||||
GLOBAL_BUFFER["events"] = {}
|
||||
@@ -156,8 +156,8 @@ def setup_event_writers(config: DictConfig) -> None:
|
||||
class Writer:
|
||||
"""Writer class"""
|
||||
|
||||
def __init__(self, save_dir: str):
|
||||
self.save_dir = save_dir
|
||||
def __init__(self, log_dir: str):
|
||||
self.log_dir = log_dir
|
||||
|
||||
@abstractmethod
|
||||
def write_image(self, name: str, image: TensorType["H", "W", "C"], step: int) -> None:
|
||||
@@ -225,9 +225,9 @@ class TimeWriter:
|
||||
class WandbWriter(Writer):
|
||||
"""WandDB Writer Class"""
|
||||
|
||||
def __init__(self, save_dir: str):
|
||||
super().__init__(save_dir)
|
||||
wandb.init(dir=save_dir)
|
||||
def __init__(self, log_dir: str):
|
||||
super().__init__(log_dir)
|
||||
wandb.init(dir=log_dir)
|
||||
|
||||
def write_image(self, name: str, image: TensorType["H", "W", "C"], step: int) -> None:
|
||||
"""_summary_
|
||||
@@ -253,9 +253,9 @@ class WandbWriter(Writer):
|
||||
class TensorboardWriter(Writer):
|
||||
"""Tensorboard Writer Class"""
|
||||
|
||||
def __init__(self, save_dir: str):
|
||||
super().__init__(save_dir)
|
||||
self.tb_writer = SummaryWriter(log_dir=self.save_dir)
|
||||
def __init__(self, log_dir: str):
|
||||
super().__init__(log_dir)
|
||||
self.tb_writer = SummaryWriter(log_dir=self.log_dir)
|
||||
|
||||
def write_image(self, name: str, image: TensorType["H", "W", "C"], step: int) -> None:
|
||||
"""_summary_
|
||||
@@ -310,13 +310,13 @@ def _format_time(seconds):
|
||||
class LocalWriter(Writer):
|
||||
"""Local Writer Class"""
|
||||
|
||||
def __init__(self, save_dir: str, stats_to_track: ListConfig, max_log_size: int = 0):
|
||||
def __init__(self, log_dir: str, stats_to_track: ListConfig, max_log_size: int = 0):
|
||||
"""
|
||||
Args:
|
||||
stats_to_track (ListConfig): the names of stats that should be logged.
|
||||
max_log size (int): max number of lines that will be logged to teminal.
|
||||
"""
|
||||
super().__init__(save_dir)
|
||||
super().__init__(log_dir)
|
||||
self.stats_to_track = [EventName[name].value for name in stats_to_track]
|
||||
self.max_log_size = max_log_size
|
||||
self.keys = set()
|
||||
@@ -325,7 +325,7 @@ class LocalWriter(Writer):
|
||||
def write_image(self, name: str, image: TensorType["H", "W", "C"], step: int) -> None:
|
||||
if name in self.stats_to_track:
|
||||
image = to8b(image)
|
||||
image_path = os.path.join(self.save_dir, f"{name}.jpg")
|
||||
image_path = os.path.join(self.log_dir, f"{name}.jpg")
|
||||
imageio.imwrite(image_path, np.uint8(image.cpu().numpy() * 255.0))
|
||||
|
||||
def write_scalar(self, name: str, scalar: float, step: int) -> None:
|
||||
|
||||
Reference in new issue
Block a user