mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-03 14:28:41 +08:00
removed stats tracker; consolidate writers into local writer
This commit is contained in:
1 parent
4dee65b480
commit
59eeaca93b
9 files changed
+248
-316
No files matched your search
@@ -212,4 +212,4 @@ class NerfWGraph(NeRFGraph):
|
||||
row2 = torch.cat([depth_fine, depth_fine_static, depth_coarse], dim=-2)
|
||||
combined_image = torch.cat([row0, row1, row2], dim=-3)
|
||||
|
||||
writer.write_image(name="image_idx_{image_idx}-nerfw", image=combined_image, step=step, group="img")
|
||||
writer.put_scalar(name="image_idx_{image_idx}-nerfw", image=combined_image, step=step, group="img")
|
||||
@@ -155,4 +155,4 @@ class SemanticNerfGraph(NeRFGraph):
|
||||
self.stuff_classes
|
||||
)
|
||||
semantic_labels_image = visualization.apply_colormap(semantic_labels[..., None])
|
||||
writer.write_image(name="image_idx_{image_idx}", image=semantic_labels_image, step=step, group="semantics")
|
||||
writer.put_image(name="image_idx_{image_idx}", image=semantic_labels_image, step=step, group="semantics")
|
||||
@@ -23,7 +23,7 @@ from mattport.nerf.sampler import PDFSampler, UniformSampler
|
||||
from mattport.structures import colors
|
||||
from mattport.structures.rays import PointSamples, RayBundle
|
||||
from mattport.nerf.colliders import NearFarCollider
|
||||
from mattport.utils import stats_tracker, visualization, writer
|
||||
from mattport.utils import visualization, writer
|
||||
from mattport.utils.misc import is_not_none
|
||||
|
||||
|
||||
@@ -231,9 +231,9 @@ class NeRFGraph(Graph):
|
||||
combined_acc = torch.cat([acc_coarse, acc_fine], dim=1)
|
||||
combined_depth = torch.cat([depth_coarse, depth_fine], dim=1)
|
||||
|
||||
writer.write_image(name=f"image_idx_{image_idx}", image=combined_rgb, step=step, group="img")
|
||||
writer.write_image(name=f"image_idx_{image_idx}", image=combined_acc, step=step, group="accumulation")
|
||||
writer.write_image(name=f"image_idx_{image_idx}", image=combined_depth, step=step, group="depth")
|
||||
writer.put_image(name=f"image_idx_{image_idx}", image=combined_rgb, step=step, group="img")
|
||||
writer.put_image(name=f"image_idx_{image_idx}", image=combined_acc, step=step, group="accumulation")
|
||||
writer.put_image(name=f"image_idx_{image_idx}", image=combined_depth, step=step, group="depth")
|
||||
|
||||
# Switch images from [H, W, C] to [1, C, H, W] for metrics computations
|
||||
image = torch.moveaxis(image, -1, 0)[None, ...]
|
||||
@@ -245,13 +245,11 @@ class NeRFGraph(Graph):
|
||||
fine_ssim = self.ssim(image, rgb_fine)
|
||||
fine_lpips = self.lpips(image, rgb_fine)
|
||||
|
||||
writer.write_scalar(name=f"val_{image_idx}-coarse", scalar=float(coarse_psnr), step=step, group="psnr")
|
||||
writer.write_scalar(name=f"val_{image_idx}-fine", scalar=float(fine_psnr), step=step, group="psnr")
|
||||
writer.write_scalar(name=f"val_{image_idx}", scalar=float(fine_ssim), step=step, group="ssim")
|
||||
writer.write_scalar(name=f"val_{image_idx}", scalar=float(fine_lpips), step=step, group="lpips")
|
||||
writer.put_scalar(name=f"val_{image_idx}-coarse", scalar=float(coarse_psnr), step=step, group="psnr")
|
||||
writer.put_scalar(name=f"val_{image_idx}-fine", scalar=float(fine_psnr), step=step, group="psnr")
|
||||
writer.put_scalar(name=f"val_{image_idx}", scalar=float(fine_ssim), step=step, group="ssim")
|
||||
writer.put_scalar(name=f"val_{image_idx}", scalar=float(fine_lpips), step=step, group="lpips")
|
||||
|
||||
stats_tracker.update_stats(
|
||||
{"name": stats_tracker.Stats.CURR_TEST_PSNR, "value": float(fine_psnr), "step": step}
|
||||
)
|
||||
writer.put_scalar(name="Test PSNR", scalar=float(fine_psnr), step=step)
|
||||
|
||||
return fine_psnr.item()
|
||||
@@ -83,4 +83,4 @@ class Optimizers:
|
||||
scheduler.step()
|
||||
# TODO(ethan): clean this up. why is there indexing into a list?
|
||||
lr = scheduler.get_last_lr()[0]
|
||||
writer.write_scalar(name=f"{param_group_name}", scalar=lr, step=step, group="learning_rate")
|
||||
writer.put_scalar(name=f"{param_group_name}", scalar=lr, step=step, group="learning_rate")
|
||||
+33
-27
@@ -18,7 +18,7 @@ from mattport.nerf.dataset.collate import CollateIterDataset, collate_batch_size
|
||||
from mattport.nerf.dataset.image_dataset import ImageDataset, collate_batch
|
||||
from mattport.nerf.dataset.utils import DatasetInputs, get_dataset_inputs
|
||||
from mattport.nerf.optimizers import Optimizers
|
||||
from mattport.utils import profiler, stats_tracker, writer
|
||||
from mattport.utils import profiler, writer
|
||||
from mattport.utils.decorators import check_main_thread
|
||||
|
||||
logging.getLogger("PIL").setLevel(logging.WARNING)
|
||||
@@ -51,8 +51,7 @@ class Trainer:
|
||||
self.optimizers = None
|
||||
self.start_step = 0
|
||||
# logging variables
|
||||
stats_tracker.setup_stats_tracker(config)
|
||||
writer.setup_event_writers(config.logging.writer)
|
||||
writer.setup_event_writers(config)
|
||||
profiler.setup_profiler(config.logging)
|
||||
self.device = "cpu" if self.world_size == 0 else f"cuda:{self.local_rank}"
|
||||
|
||||
@@ -199,47 +198,54 @@ class Trainer:
|
||||
train_start = time()
|
||||
num_iterations = self.config.graph.max_num_iterations
|
||||
iter_dataset = iter(self.train_dataloader)
|
||||
for i, step in enumerate(range(self.start_step, self.start_step + num_iterations)):
|
||||
for step in range(self.start_step, self.start_step + num_iterations):
|
||||
self.step = step
|
||||
data_start = time()
|
||||
batch = next(iter_dataset)
|
||||
stats_tracker.update_stats(
|
||||
{"name": stats_tracker.Stats.ITER_LOAD_TIME, "start_time": data_start, "end_time": time(), "step": step}
|
||||
writer.put_time(
|
||||
name="Data Load (time)", start_time=data_start, end_time=time(), step=step, avg_over_iters=True
|
||||
)
|
||||
|
||||
iter_start = time()
|
||||
loss_dict = self.train_iteration(batch, step)
|
||||
stats_tracker.update_stats(
|
||||
{
|
||||
"name": stats_tracker.Stats.RAYS_PER_SEC,
|
||||
"start_time": iter_start,
|
||||
"end_time": time(),
|
||||
"step": step,
|
||||
"batch_size": batch["indices"].shape[0],
|
||||
},
|
||||
writer.put_time(
|
||||
name="Rays Per Sec (time)",
|
||||
start_time=iter_start,
|
||||
end_time=time(),
|
||||
step=step,
|
||||
avg_over_iters=True,
|
||||
avg_over_batch=batch["indices"].shape[0],
|
||||
)
|
||||
stats_tracker.update_stats(
|
||||
{
|
||||
"name": stats_tracker.Stats.ITER_TRAIN_TIME,
|
||||
"start_time": iter_start,
|
||||
"end_time": time(),
|
||||
"step": step,
|
||||
}
|
||||
writer.put_time(
|
||||
name="Train Iter (time)",
|
||||
start_time=iter_start,
|
||||
end_time=time(),
|
||||
step=step,
|
||||
avg_over_iters=True,
|
||||
update_eta=True,
|
||||
)
|
||||
|
||||
if step != 0 and step % self.config.logging.steps_per_log == 0:
|
||||
writer.write_scalar_dict(scalar_dict=loss_dict, step=step, group="Loss", prefix="train-")
|
||||
writer.put_dict(name="loss_dict", scalar_dict=loss_dict, step=step, group="Loss", prefix="train-")
|
||||
# TODO: add the learning rates to tensorboard/logging
|
||||
if step != 0 and self.config.graph.steps_per_save and step % self.config.graph.steps_per_save == 0:
|
||||
self.save_checkpoint(self.config.graph.model_dir, step)
|
||||
if step % self.config.graph.steps_per_test == 0: # NOTE(ethan): we should still run this in dry-run mode!
|
||||
for image_idx in self.config.data.val_image_indices:
|
||||
_ = self.test_image(image_idx=image_idx, step=step)
|
||||
stats_tracker.print_stats(i / num_iterations)
|
||||
self._write_out_storage()
|
||||
|
||||
stats_tracker.update_stats(
|
||||
{"name": stats_tracker.Stats.TOTAL_TRAIN_TIME, "start_time": train_start, "end_time": time()}
|
||||
)
|
||||
stats_tracker.print_stats(1.0)
|
||||
writer.put_time(name="Train Total (time)", start_time=train_start, end_time=time(), step=num_iterations)
|
||||
self._write_out_storage()
|
||||
|
||||
def _write_out_storage(self):
|
||||
"""Perform writes only during appropriate time steps"""
|
||||
if (
|
||||
self.step % self.config.logging.steps_per_log == 0
|
||||
or (self.config.graph.steps_per_save and self.step % self.config.graph.steps_per_save == 0)
|
||||
or self.step % self.config.graph.steps_per_test == 0
|
||||
):
|
||||
writer.write_out_storage()
|
||||
|
||||
@profiler.time_function
|
||||
def train_iteration(self, batch: dict, step: int):
|
||||
|
||||
Reference in new issue
Block a user