shuinb's picture
Add files using upload-large-folder tool
df3939b verified
Raw History Blame Contribute Delete
7.09 kB
import json
import csv
from pathlib import Path
import yaml
ROOT = Path(__file__).resolve().parents[1]
PROJECTS = ROOT / 'stb_minimal_20261017'
RUN = ROOT / 'experiments/run_20261025'
PYTHON = str(ROOT / 'experiments/.venv/bin/python')
def read_ini(path):
entries = {}
for line in path.read_text().splitlines():
if line.strip() and not line.lstrip().startswith('#'):
key, value = line.split('=', 1)
entries[key.strip()] = value.strip()
return entries
def save_ini(path, entries):
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text('\n'.join(f'{key} = {value}' for key, value in entries.items()) + '\n')
def quoted(path):
return json.dumps(str(path))
def build(scene_names=None):
RUN.mkdir(parents=True, exist_ok=True)
calibration = ROOT / 'experiments/calibration/IRF_global_nonnegative.csv'
calibration.parent.mkdir(parents=True, exist_ok=True)
with (ROOT / 'config/IRF_global.csv').open() as source:
reader = csv.DictReader(source)
columns = reader.fieldnames
responses = list(reader)
for response in responses:
response['irf'] = str(max(0.0, float(response['irf'])))
with calibration.open('w') as destination:
writer = csv.DictWriter(destination, fieldnames=columns)
writer.writeheader()
writer.writerows(responses)
jobs = []
for scene_root in sorted((ROOT / 'experiments/data').iterdir()):
scene = scene_root.name
if scene_names is not None and scene not in scene_names:
continue
info = json.loads((scene_root / 'scene.json').read_text())
reference = ROOT / 'experiments/references' / scene / 'contract.json'
for views, count in [('three_views', 3), ('five_views', 5), ('ten_views', 10)]:
poses = scene_root / views
for method in ['trnerf', 'FlyingWithPhotons', 'transientangelo']:
job_id = f'{method}__{scene}__{count}views'
work = RUN / job_id
work.mkdir(exist_ok=True)
project = PROJECTS / method
checkpoint = work / 'checkpoints'
job = dict(id=job_id, method=method, scene=scene, views=count, test_frames=info['test_frames'],
cwd=str(project), work=str(work), checkpoint=str(checkpoint), status='pending')
if method == 'transientangelo':
config = yaml.safe_load((project / 'configs/captured.yaml').read_text())
config.update(name=job_id, tag=job_id, seed=42, trial_name='train',
exp_dir=str(work), save_dir=str(work / 'save'), ckpt_dir=str(checkpoint),
code_dir=str(work / 'code'), config_dir=str(work / 'config'))
config['dataset'].update(scene=scene, root_dir=str(poses), num_views=str(count),
intrinsics=str(ROOT / 'config/intrinsics.npy'),
measurement_root=str(scene_root), data_exts='.npz',
irf_path=str(calibration),
invalid_mask_path=str(ROOT / 'config/offset.txt'))
config['dataset']['far_plane'] = 672 * 7.5e-10 * 299792458.0 / 2
config['model']['scene_aabb'] = info['aabb']
config['system'].update(shared_reference_contract=str(reference), evaluate_after_fit=False)
config['checkpoint'].update(every_n_train_steps=50000, filename='step{step}', auto_insert_metric_name=False)
config['trainer'].update(max_steps=150000, enable_progress_bar=False, precision=16)
config_path = work / 'train.yaml'
config_path.write_text(yaml.safe_dump(config, sort_keys=False))
job['train'] = [PYTHON, '-u', 'launch.py', '--config', str(config_path), '--train', '--gpu', '{gpu}',
'--runs_dir', str(work / 'tensorboard')]
job['eval'] = [PYTHON, '-u', 'eval.py', 'render', '--config', str(config_path), '--gpu', '{gpu}',
'--resume', str(checkpoint / 'step{step}.ckpt'), '--output', str(work / 'test_{step}')]
else:
config = read_ini(project / 'configs/train.ini')
config.update(exp_name='checkpoints', outpath=quoted(work), measurement_root=quoted(scene_root),
aabb=quoted(info['aabb']), max_steps='150000', far_plane=str(672 * 7.5e-10 * 299792458.0 / 2),
summary='False' if method == 'FlyingWithPhotons' else None)
if method == 'trnerf':
config.pop('summary')
config.update(data_root_fp=quoted(poses), num_views=str(count), data_exts='".npz"',
irf_path=quoted(calibration), intrinsics=quoted(ROOT / 'config/intrinsics.npy'),
invalid_mask_path=quoted(ROOT / 'config/offset.txt'), steps_til_checkpoint='50000',
skip_train_summaries='True')
evaluation = dict(config)
for key in ['img_height', 'img_width', 'skip_train_summaries']:
evaluation.pop(key)
evaluation.update(test_folder_path=quoted(poses), split='test', rep_number='30',
shared_reference_contract=quoted(reference))
else:
config.update(data_root=quoted(poses), intrinsics_path=quoted(ROOT / 'config/intrinsics.npy'),
depth_offset_map=quoted(ROOT / 'config/offset.txt'), steps_till_checkpoint='50000')
evaluation = dict(config, warped='True', t_min_test='0', t_max_test='672',
transforms_path=quoted(poses / 'transforms_test.json'),
shared_reference_contract=quoted(reference))
config_path = work / 'train.ini'
eval_path = work / 'eval.ini'
save_ini(config_path, config)
save_ini(eval_path, evaluation)
job['train'] = [PYTHON, '-u', 'train_ours.py', '-c', str(config_path)]
job['eval'] = [PYTHON, '-u', 'eval.py', 'render', '--config', str(eval_path),
'--checkpoint_dir', str(checkpoint), '--step', '{step}', '--output', str(work / 'test_{step}')]
jobs.append(job)
manifest = dict(gpus=[0, 1], max_steps=150000, test_steps=[100000, 150000], seed=42,
python=PYTHON, jobs=jobs)
(RUN / 'manifest.json').write_text(json.dumps(manifest, indent=2) + '\n')
print(f'Built {len(jobs)} jobs, {2 * len(jobs)} full test runs.')
if __name__ == '__main__':
build()