File size: 2,359 Bytes
bdc469b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Fixed points of the SplatScore scale for every task, on the held-out views.

  uv run python scripts/baselines.py          -> results/baselines.json

* empty scene        0 by definition
* one_gaussian       one Gaussian at the visual-hull center, sized to the hull, in the mean object color
* gd64               gradient-descent fit with 64 Gaussians (data/bench/scenes/<scene>/oracle64.npz)
* gd300              gradient-descent fit with 300 Gaussians, the same cap and photos as the model: 100 by definition
* scrambled_start    reassembly tasks only: the scrambled start, submitted unchanged
"""
import argparse
import glob
import json
from pathlib import Path

import numpy as np
import torch

from splatbench.env import load_task
from splatbench.optimize import visual_hull_points
from splatbench.scene import Scene
from splatbench.score import evaluate, splat_score

ap = argparse.ArgumentParser()
ap.add_argument("--device", default="cuda" if torch.cuda.is_available() else "cpu")
ap.add_argument("--out", default="results/baselines.json")
a = ap.parse_args()
dev = a.device

out = {}
for tp in sorted(glob.glob("data/bench/tasks/*.json")):
    task = load_task(tp)
    sd = Path(task.scene_dir)
    sc = Scene.load(sd)
    norm = json.loads((sd / "norm.json").read_text())
    cams, imgs, masks = sc.torch_views("ref", dev)
    _, occ = visual_hull_points(cams, masks, 1.0, res=64)
    lo, hi = occ.min(0), occ.max(0)
    fg = imgs[masks > 0.5].mean(0)
    f = lambda x: torch.as_tensor(np.asarray(x), dtype=torch.float32, device=dev)
    blob = dict(means=f([(lo + hi) / 2]), scales=f([(hi - lo) / 4]), quats=f([[1, 0, 0, 0]]), colors=fg[None],
                opacities=f([0.95]))
    res = dict(one_gaussian=round(splat_score(evaluate(blob, sc, "test", dev)["mean"], norm["test"])["score"], 2),
               gd64=round(splat_score(norm["test"]["oracle64"], norm["test"])["score"], 2), gd300=100.0)
    if task.kind == "assemble":
        d = np.load(task.init_npz)
        gs = {k: f(d[k]) for k in ("means", "scales", "quats", "colors", "opacities")}
        res["scrambled_start"] = round(splat_score(evaluate(gs, sc, "test", dev)["mean"], norm["test"])["score"], 2)
    out[task.task_id] = res
    print(task.task_id, res, flush=True)
Path(a.out).parent.mkdir(parents=True, exist_ok=True)
Path(a.out).write_text(json.dumps(out, indent=1))