callback for optimizer (#99)

This commit is contained in:
evonneng authored and GitHub committed 2022-05-23 08:57:27 -07:00
1 parent 9df71ae4f3
commit 985560eace
5 files changed
+36 -18

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
"""
Callback functions for training iterations
"""
from mattport.nerf.graph.base import Graph
from mattport.nerf.occupancy_grid import OccupancyGrid
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)
+6 -3
View File
@@ -320,15 +320,18 @@ class LocalWriter(Writer):
def _update_header(self, latest_map, new_key):
"""helper to handle the printing of the header labels"""
if (not self.max_log_size and len(self.past_mssgs) == 0) or (
self.max_log_size and (len(self.past_mssgs) == 0 or new_key)
):
full_log_cond = not self.max_log_size and GLOBAL_BUFFER["step"] <= GLOBAL_BUFFER["steps_per_log"]
capped_log_cond = self.max_log_size and (len(self.past_mssgs) <= 2 or new_key)
if full_log_cond or capped_log_cond:
mssg = f"{'Step (% Done)':<20}"
for name, _ in latest_map.items():
if name in self.stats_to_track:
mssg += f"{name:<20} "
self.past_mssgs[0] = mssg
self.past_mssgs[1] = "-" * len(mssg)
if full_log_cond:
print(mssg)
print("-" * len(mssg))
def _print_stats(self, latest_map, padding=" "):
"""helper to print out the stats in a readable format"""