eval_our / benchmark.py
nosmall's picture
Upload panorama depth benchmark (initial)
d3c7b2f verified
Raw History Blame Contribute Delete
6.11 kB
"""HuggingFace `datasets` loading script for the Panorama Depth Benchmark.
The data lives in sibling folders of this script (`stanford2d3d/`, …).
Non-parquet subsets expose `rgb`, `depth`, and optional `mask` as raw
bytes with the correct file extension; `zuripano` is already parquet
and keeps its native schema.
Usage:
from datasets import load_dataset
ds = load_dataset("/path/to/benchmark", "stanford2d3d", split="test")
row = ds[0]
# row["rgb"] -> dict {"path": ..., "bytes": raw PNG/JPG}
# row["depth"] -> same (PNG u16 / RGB-encoded / EXR)
# row["mask"] -> same (JPG), or None if not available
# row["stem"] -> str
# row["depth_scale"]-> str recipe hint: "v / 512.0 -> meters", etc.
"""
from __future__ import annotations
from pathlib import Path
import datasets as hfds
_DESCRIPTION = (
"Unified evaluation suite for equirectangular (360°) depth estimation,"
" assembled from eight public panorama depth test splits."
)
_CITATION = """
If you use this benchmark please cite each original dataset's paper
(Stanford2D3D, Matterport3D, PanoSUNCG, Structured3D, Metropolis / DA360,
ZuriPano / PaGeR, Holo360D).
"""
# -- per-subset config ---------------------------------------------------
# depth_fmt : how depth maps to meters (string hint for consumers)
# has_mask : whether a per-sample mask file is present
# min/max : depth clamp range used for evaluation
# scene : indoor / outdoor / synthetic
_CONFIGS = {
"stanford2d3d": dict(fmt="png_u16", scale="v / 512.0", has_mask=False, min=0.001, max=5.0, scene="indoor", n=373),
"matterport3d": dict(fmt="png_u16", scale="v / 4000.0", has_mask=False, min=0.001, max=5.0, scene="indoor", n=2014),
"panosuncg": dict(fmt="png_u8_rgb", scale="v[...,0] * 10 / 255", has_mask=False, min=0.001, max=5.0, scene="synthetic", n=3944),
"structured3d": dict(fmt="png_u16", scale="v / 1000.0", has_mask=False, min=0.001, max=5.0, scene="synthetic", n=1691),
"metropolis": dict(fmt="png_u16", scale="v / 512.0", has_mask=False, min=0.2, max=128.0, scene="outdoor", n=3000),
"holo360d_indoor": dict(fmt="exr", scale="EXR channel 0 is metric", has_mask=True, min=0.01, max=10.0, scene="indoor", n=360),
"holo360d_outdoor":dict(fmt="exr", scale="EXR channel 0 is metric", has_mask=True, min=0.01, max=75.0, scene="outdoor", n=90),
"replica360_2k": dict(fmt="dpt", scale="Sintel .dpt float32 is metric", has_mask=False, min=0.001, max=10.0, scene="indoor", n=130),
"panoinfinigen_indoor": dict(fmt="npy", scale="raw float16 meters", has_mask=False, min=0.001, max=10.0, scene="indoor", n=4392),
"panoinfinigen_nature": dict(fmt="npy", scale="raw float16 meters", has_mask=False, min=0.001, max=100.0, scene="nature", n=848),
"panoinfinigen_urban": dict(fmt="npy", scale="raw float32 meters", has_mask=False, min=0.001, max=500.0, scene="urban", n=788),
}
# zuripano is handled via its own parquet shards; see the native dataset
# card for its schema. Its entry lives in _loader.py CONFIG (min=0.01,
# max=75.0) — keep the two in sync.
class PanoDepthBenchmarkConfig(hfds.BuilderConfig):
def __init__(self, scene: str = "", **kw):
super().__init__(**kw)
self.scene = scene
class PanoDepthBenchmark(hfds.GeneratorBasedBuilder):
BUILDER_CONFIGS = [
PanoDepthBenchmarkConfig(name=k, version=hfds.Version("1.0.0"),
description=f"{k} test split", scene=v["scene"])
for k, v in _CONFIGS.items()
]
def _info(self):
cfg = _CONFIGS[self.config.name]
features = {
"stem": hfds.Value("string"),
"rgb": hfds.Image(decode=False),
"depth": hfds.Value("binary") if cfg["fmt"] in ("exr", "dpt", "npy")
else hfds.Image(decode=False),
"depth_scale": hfds.Value("string"),
"min_depth": hfds.Value("float32"),
"max_depth": hfds.Value("float32"),
"scene": hfds.Value("string"),
}
if cfg["has_mask"]:
features["mask"] = hfds.Image(decode=False)
return hfds.DatasetInfo(
description=_DESCRIPTION,
features=hfds.Features(features),
citation=_CITATION,
)
def _split_generators(self, dl_manager):
root = Path(self.base_path or ".") / self.config.name
return [hfds.SplitGenerator(name=hfds.Split.TEST,
gen_kwargs={"root": str(root)})]
def _generate_examples(self, root):
cfg = _CONFIGS[self.config.name]
root = Path(root)
split_file = root / "test.txt"
for idx, ln in enumerate(split_file.read_text().strip().splitlines()):
parts = ln.split()
if len(parts) < 2:
continue
rgb_rel, dep_rel = parts[0], parts[1]
mask_rel = parts[2] if len(parts) >= 3 and parts[2] else None
def _read_bytes(rel):
with open(root / rel, "rb") as fp:
return fp.read()
stem = Path(rgb_rel).stem
if cfg["fmt"] in ("exr", "dpt", "npy"):
depth_val = _read_bytes(dep_rel)
else:
depth_val = {"path": str(root / dep_rel), "bytes": _read_bytes(dep_rel)}
row = {
"stem": stem,
"rgb": {"path": str(root / rgb_rel), "bytes": _read_bytes(rgb_rel)},
"depth": depth_val,
"depth_scale": cfg["scale"],
"min_depth": float(cfg["min"]),
"max_depth": float(cfg["max"]),
"scene": cfg["scene"],
}
if cfg["has_mask"] and mask_rel:
row["mask"] = {"path": str(root / mask_rel), "bytes": _read_bytes(mask_rel)}
elif cfg["has_mask"]:
row["mask"] = None
yield idx, row