File size: 6,108 Bytes
d3c7b2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
"""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