text stringlengths 1 93.6k |
|---|
approx_total_time = int(round(step * total_time / total_steps))
|
# Transpose and stack stats_buffer along axis 0.
|
fs = [utils.flatten_dict(s, sep='/') for s in stats_buffer]
|
stats_stacked = {k: np.stack([f[k] for f in fs]) for k in fs[0].keys()}
|
# Split every statistic that isn't a vector into a set of statistics.
|
stats_split = {}
|
for k, v in stats_stacked.items():
|
if v.ndim not in [1, 2] and v.shape[0] != len(stats_buffer):
|
raise ValueError('statistics must be of size [n], or [n, k].')
|
if v.ndim == 1:
|
stats_split[k] = v
|
elif v.ndim == 2:
|
for i, vi in enumerate(tuple(v.T)):
|
stats_split[f'{k}/{i}'] = vi
|
# Summarize the entire histogram of each statistic.
|
for k, v in stats_split.items():
|
summary_writer.add_histogram('train_' + k, v, step)
|
# Take the mean and max of each statistic since the last summary.
|
avg_stats = {k: np.mean(v) for k, v in stats_split.items()}
|
max_stats = {k: np.max(v) for k, v in stats_split.items()}
|
summ_fn = lambda s, v: summary_writer.add_scalar(s, v, step) # pylint:disable=cell-var-from-loop
|
# Summarize the mean and max of each statistic.
|
for k, v in avg_stats.items():
|
summ_fn(f'train_avg_{k}', v)
|
for k, v in max_stats.items():
|
summ_fn(f'train_max_{k}', v)
|
summ_fn('train_num_params', num_params)
|
summ_fn('train_learning_rate', learning_rate)
|
summ_fn('train_steps_per_sec', steps_per_sec)
|
summ_fn('train_rays_per_sec', rays_per_sec)
|
summary_writer.add_scalar('train_avg_psnr_timed', avg_stats['psnr'],
|
total_time // TIME_PRECISION)
|
summary_writer.add_scalar('train_avg_psnr_timed_approx', avg_stats['psnr'],
|
approx_total_time // TIME_PRECISION)
|
if dataset.metadata is not None and module.learned_exposure_scaling:
|
scalings = module.exposure_scaling_offsets.weight
|
num_shutter_speeds = dataset.metadata['unique_shutters'].shape[0]
|
for i_s in range(num_shutter_speeds):
|
for j_s, value in enumerate(scalings[i_s]):
|
summary_name = f'exposure/scaling_{i_s}_{j_s}'
|
summary_writer.add_scalar(summary_name, value, step)
|
precision = int(np.ceil(np.log10(config.max_steps))) + 1
|
avg_loss = avg_stats['loss']
|
avg_psnr = avg_stats['psnr']
|
str_losses = { # Grab each "losses_{x}" field and print it as "x[:4]".
|
k[7:11]: (f'{v:0.5f}' if 1e-4 <= v < 10 else f'{v:0.1e}')
|
for k, v in avg_stats.items()
|
if k.startswith('losses/')
|
}
|
logger.info(f'{step}' + f'/{config.max_steps:d}:' +
|
f'loss={avg_loss:0.5f},' + f'psnr={avg_psnr:.3f},' +
|
f'lr={learning_rate:0.2e} | ' +
|
','.join([f'{k}={s}' for k, s in str_losses.items()]) +
|
f',{rays_per_sec:0.0f} r/s')
|
# Reset everything we are tracking between summarizations.
|
reset_stats = True
|
if step > 0 and step % config.checkpoint_every == 0 and accelerator.is_main_process:
|
checkpoints.save_checkpoint(config.checkpoint_dir,
|
accelerator, step,
|
config.checkpoints_total_limit)
|
# Test-set evaluation.
|
if config.train_render_every > 0 and step % config.train_render_every == 0:
|
# We reuse the same random number generator from the optimization step
|
# here on purpose so that the visualization matches what happened in training.
|
eval_start_time = time.time()
|
try:
|
test_batch = next(test_dataiter)
|
except StopIteration:
|
test_dataiter = iter(test_dataloader)
|
test_batch = next(test_dataiter)
|
test_batch = accelerate.utils.send_to_device(test_batch, accelerator.device)
|
# render a single image with all distributed processes
|
rendering = models.render_image(model, accelerator,
|
test_batch, False,
|
train_frac, config,
|
disable_bilgrid=True)
|
# move to numpy
|
rendering = tree_map(lambda x: x.detach().cpu().numpy(), rendering)
|
test_batch = tree_map(lambda x: x.detach().cpu().numpy() if x is not None else None, test_batch)
|
# Log eval summaries on host 0.
|
if accelerator.is_main_process:
|
eval_time = time.time() - eval_start_time
|
num_rays = np.prod(test_batch['directions'].shape[:-1])
|
rays_per_sec = num_rays / eval_time
|
summary_writer.add_scalar('test_rays_per_sec', rays_per_sec, step)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.