mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-21 07:05:44 +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)
|
||||
Reference in new issue
Block a user