Spaces:
Running
Running
SWR-Bench Explorer: initial release
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +2 -34
- .gitignore +6 -0
- README.md +68 -7
- app.py +345 -0
- build_preview.py +180 -0
- data/botanical/f_0000.npz +3 -0
- data/botanical/f_0000_cir.jpg +3 -0
- data/botanical/f_0000_mat.png +0 -0
- data/botanical/f_0000_rgb.jpg +3 -0
- data/botanical/f_0092.npz +3 -0
- data/botanical/f_0092_cir.jpg +3 -0
- data/botanical/f_0092_mat.png +0 -0
- data/botanical/f_0092_rgb.jpg +3 -0
- data/botanical/f_0176.npz +3 -0
- data/botanical/f_0176_cir.jpg +3 -0
- data/botanical/f_0176_mat.png +0 -0
- data/botanical/f_0176_rgb.jpg +3 -0
- data/city/f_0000.npz +3 -0
- data/city/f_0000_cir.jpg +3 -0
- data/city/f_0000_mat.png +0 -0
- data/city/f_0000_rgb.jpg +3 -0
- data/city/f_0120.npz +3 -0
- data/city/f_0120_cir.jpg +3 -0
- data/city/f_0120_mat.png +0 -0
- data/city/f_0120_rgb.jpg +3 -0
- data/city/f_0236.npz +3 -0
- data/city/f_0236_cir.jpg +3 -0
- data/city/f_0236_mat.png +0 -0
- data/city/f_0236_rgb.jpg +3 -0
- data/city_afternoon/f_0000.npz +3 -0
- data/city_afternoon/f_0000_cir.jpg +3 -0
- data/city_afternoon/f_0000_mat.png +0 -0
- data/city_afternoon/f_0000_rgb.jpg +3 -0
- data/city_afternoon/f_0120.npz +3 -0
- data/city_afternoon/f_0120_cir.jpg +3 -0
- data/city_afternoon/f_0120_mat.png +0 -0
- data/city_afternoon/f_0120_rgb.jpg +3 -0
- data/city_afternoon/f_0236.npz +3 -0
- data/city_afternoon/f_0236_cir.jpg +3 -0
- data/city_afternoon/f_0236_mat.png +0 -0
- data/city_afternoon/f_0236_rgb.jpg +3 -0
- data/city_metamer/f_0000.npz +3 -0
- data/city_metamer/f_0000_cir.jpg +3 -0
- data/city_metamer/f_0000_mat.png +0 -0
- data/city_metamer/f_0000_rgb.jpg +3 -0
- data/city_metamer/f_0120.npz +3 -0
- data/city_metamer/f_0120_cir.jpg +3 -0
- data/city_metamer/f_0120_mat.png +0 -0
- data/city_metamer/f_0120_rgb.jpg +3 -0
- data/city_metamer/f_0236.npz +3 -0
.gitattributes
CHANGED
|
@@ -1,35 +1,3 @@
|
|
| 1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.
|
| 17 |
-
*.
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.gitignore
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
_raw/
|
| 2 |
+
.venv/
|
| 3 |
+
__pycache__/
|
| 4 |
+
build.log
|
| 5 |
+
screenshots/
|
| 6 |
+
*.pyc
|
README.md
CHANGED
|
@@ -1,13 +1,74 @@
|
|
| 1 |
---
|
| 2 |
-
title: SWR
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
python_version:
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: SWR-Bench Explorer
|
| 3 |
+
emoji: 🌈
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.49.1
|
| 8 |
+
python_version: "3.12"
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
+
license: cc-by-4.0
|
| 12 |
+
datasets:
|
| 13 |
+
- ming0531/SWR-Bench
|
| 14 |
+
short_description: Click any pixel to see 64-band hyperspectral spectra and GT
|
| 15 |
+
tags:
|
| 16 |
+
- hyperspectral
|
| 17 |
+
- spectral-unmixing
|
| 18 |
+
- abundance-estimation
|
| 19 |
+
- material-segmentation
|
| 20 |
+
- multi-view
|
| 21 |
+
- 3d-gaussian-splatting
|
| 22 |
+
- novel-view-synthesis
|
| 23 |
+
- remote-sensing
|
| 24 |
+
- synthetic
|
| 25 |
+
- dataset-explorer
|
| 26 |
---
|
| 27 |
|
| 28 |
+
# SWR-Bench Explorer
|
| 29 |
+
|
| 30 |
+
An interactive viewer for **[SWR-Bench](https://huggingface.co/datasets/ming0531/SWR-Bench)**, a multi-view
|
| 31 |
+
hyperspectral benchmark for **3D hyperspectral unmixing** rendered with the Spectral World Renderer.
|
| 32 |
+
Pick a world and a view, switch between the sRGB render, the material ground truth, a colour-infrared composite
|
| 33 |
+
and per-class abundance maps, and click any pixel to plot its 64-band radiance spectrum (420–980 nm, clean and noisy)
|
| 34 |
+
together with its ground-truth material and sub-pixel area abundances.
|
| 35 |
+
|
| 36 |
+
**Paper:** [Spectral World Renderer: Unified 3D Hyperspectral Unmixing](https://arxiv.org/abs/2610.19520) ·
|
| 37 |
+
**Dataset:** [ming0531/SWR-Bench](https://huggingface.co/datasets/ming0531/SWR-Bench) ·
|
| 38 |
+
**Code:** [ming053l/Spectral-World-Renderer](https://github.com/ming053l/Spectral-World-Renderer) ·
|
| 39 |
+
**Project page:** [ming053l.github.io/Spectral-World-Renderer](https://ming053l.github.io/Spectral-World-Renderer/) ·
|
| 40 |
+
**Collection:** [Spectral World Renderer](https://huggingface.co/collections/ming0531/spectral-world-renderer-6b0fa8e8994ece823c7415ec)
|
| 41 |
+
|
| 42 |
+
## What is in this Space
|
| 43 |
+
|
| 44 |
+
A small preview subset of the dataset (`data/`, built by `build_preview.py` from the public release with the
|
| 45 |
+
official loader): three test views for each of ten worlds and City variants (Forbidden City, Market, Botanical,
|
| 46 |
+
Karst, City, Study, Office, and City with metamers, stress, morning and afternoon sun). For every view the Space
|
| 47 |
+
stores the released sRGB render, the full-resolution material map, a colour-infrared composite, and the clean and
|
| 48 |
+
noisy 64-band cubes and area abundances sampled at every third pixel (float16). No values are averaged, so each
|
| 49 |
+
spectrum and abundance vector belongs to one full-resolution pixel. The full dataset (2,364 views, 960×540 float32
|
| 50 |
+
cubes, shading coefficients, instances, depth, normals and cameras) is on the
|
| 51 |
+
[dataset page](https://huggingface.co/datasets/ming0531/SWR-Bench). The NVIDIA HQ world is not included in this Space.
|
| 52 |
+
|
| 53 |
+
## Licence and attribution
|
| 54 |
+
|
| 55 |
+
The rendered data and ground truth are released under **CC BY 4.0**. Third-party inputs keep their own terms:
|
| 56 |
+
|
| 57 |
+
- **ECOSTRESS Spectral Library**, courtesy of the Jet Propulsion Laboratory, California Institute of Technology
|
| 58 |
+
(© 2017 Caltech, https://speclib.jpl.nasa.gov/); not covered by CC BY 4.0. Please cite Meerdink et al. (2019),
|
| 59 |
+
*Remote Sensing of Environment* 230, 111196, and Baldridge et al. (2009), *Remote Sensing of Environment* 113, 711–715.
|
| 60 |
+
- **USGS Spectral Library Version 7**, public domain; Kokaly et al. (2017), https://doi.org/10.5066/F7RR1WDJ.
|
| 61 |
+
|
| 62 |
+
## Citation
|
| 63 |
+
|
| 64 |
+
```bibtex
|
| 65 |
+
@misc{lee2026swr,
|
| 66 |
+
title = {Spectral World Renderer: Unified 3D Hyperspectral Unmixing},
|
| 67 |
+
author = {Lee, Chia-Ming and Hsiao, Yu-Jou and Chang, Ming-Ching and Li, Xin and Liu, Yu-Lun and Hsu, Chih-Chung},
|
| 68 |
+
year = {2026},
|
| 69 |
+
eprint = {2610.19520},
|
| 70 |
+
archivePrefix = {arXiv},
|
| 71 |
+
primaryClass = {cs.CV},
|
| 72 |
+
url = {https://arxiv.org/abs/2610.19520}
|
| 73 |
+
}
|
| 74 |
+
```
|
app.py
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""SWR-Bench Explorer: browse multi-view hyperspectral renders and their ground truth.
|
| 2 |
+
|
| 3 |
+
Data: a small preview subset of https://huggingface.co/datasets/ming0531/SWR-Bench (CC BY 4.0), built with
|
| 4 |
+
build_preview.py: three test views per world, 64-band clean and noisy radiance sampled at every third pixel,
|
| 5 |
+
area abundances and full-resolution material maps.
|
| 6 |
+
"""
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import json
|
| 10 |
+
from functools import lru_cache
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
import gradio as gr
|
| 14 |
+
import numpy as np
|
| 15 |
+
import plotly.graph_objects as go
|
| 16 |
+
from PIL import Image, ImageDraw
|
| 17 |
+
|
| 18 |
+
DATA = Path(__file__).resolve().parent / "data"
|
| 19 |
+
META = json.load(open(DATA / "meta.json"))
|
| 20 |
+
WORLDS = META["worlds"]
|
| 21 |
+
UNITS = "W m⁻² sr⁻¹ nm⁻¹"
|
| 22 |
+
H, W = META["resolution"]
|
| 23 |
+
|
| 24 |
+
LINKS = {
|
| 25 |
+
"Paper (arXiv)": "https://arxiv.org/abs/2610.19520",
|
| 26 |
+
"Dataset": "https://huggingface.co/datasets/ming0531/SWR-Bench",
|
| 27 |
+
"Code": "https://github.com/ming053l/Spectral-World-Renderer",
|
| 28 |
+
"Project page": "https://ming053l.github.io/Spectral-World-Renderer/",
|
| 29 |
+
"Collection": "https://huggingface.co/collections/ming0531/spectral-world-renderer-6b0fa8e8994ece823c7415ec",
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
# fixed categorical order for compared pixels (validated reference palette, slots 1-4)
|
| 33 |
+
PICK_COLORS = ["#257de0", "#f47230", "#00b894", "#e2a100"]
|
| 34 |
+
CLEAN_COLOR, NOISY_COLOR = "#257de0", "#f47230"
|
| 35 |
+
MAX_PICKS = 4
|
| 36 |
+
LAYERS = ["sRGB render", "Material ground truth", "Colour infrared (850/650/550 nm)", "Abundance of one class"]
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def pretty(name: str) -> str:
|
| 40 |
+
return name.replace("_", " ")
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def view_label(w: str, v: dict) -> str:
|
| 44 |
+
return f"{v['stem']} · test view {v['test_index'] + 1}/{WORLDS[w]['n_test']}"
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def view_stem(w: str, label: str) -> str:
|
| 48 |
+
for v in WORLDS[w]["views"]:
|
| 49 |
+
if view_label(w, v) == label:
|
| 50 |
+
return v["stem"]
|
| 51 |
+
return WORLDS[w]["views"][0]["stem"]
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
@lru_cache(maxsize=8)
|
| 55 |
+
def load_view(w: str, stem: str) -> dict:
|
| 56 |
+
with np.load(DATA / w / f"{stem}.npz") as z:
|
| 57 |
+
d = {k: z[k] for k in z.files}
|
| 58 |
+
s = float(d["scale"])
|
| 59 |
+
d["clean"] = d["clean"].astype(np.float32) * s
|
| 60 |
+
d["noisy"] = d["noisy"].astype(np.float32) * s
|
| 61 |
+
d["abundance"] = d["abundance"].astype(np.float32)
|
| 62 |
+
d["material"] = d["material"].astype(np.int16) - 1
|
| 63 |
+
return d
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
@lru_cache(maxsize=24)
|
| 67 |
+
def base_image(w: str, stem: str, layer: str, cls: int) -> np.ndarray:
|
| 68 |
+
if layer == LAYERS[0]:
|
| 69 |
+
return np.asarray(Image.open(DATA / w / f"{stem}_rgb.jpg").convert("RGB"))
|
| 70 |
+
if layer == LAYERS[1]:
|
| 71 |
+
return np.asarray(Image.open(DATA / w / f"{stem}_mat.png").convert("RGB"))
|
| 72 |
+
if layer == LAYERS[2]:
|
| 73 |
+
return np.asarray(Image.open(DATA / w / f"{stem}_cir.jpg").convert("RGB"))
|
| 74 |
+
d = load_view(w, stem)
|
| 75 |
+
a = d["abundance"][..., cls]
|
| 76 |
+
# sequential single-hue ramp (dark surface -> bright blue), nearest upsampling to full resolution
|
| 77 |
+
lo, hi = np.array([18, 22, 30], np.float32), np.array([168, 210, 255], np.float32)
|
| 78 |
+
img = (lo + a[..., None] * (hi - lo)).astype(np.uint8)
|
| 79 |
+
st = int(d["stride"])
|
| 80 |
+
img = np.repeat(np.repeat(img, st, 0), st, 1)[:H, :W]
|
| 81 |
+
img[d["material"] < 0] = (8, 8, 10)
|
| 82 |
+
return img
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def draw_picks(img: np.ndarray, picks: list) -> np.ndarray:
|
| 86 |
+
im = Image.fromarray(img.copy())
|
| 87 |
+
dr = ImageDraw.Draw(im)
|
| 88 |
+
for k, (x, y) in enumerate(picks):
|
| 89 |
+
c = PICK_COLORS[k % len(PICK_COLORS)] if len(picks) > 1 else "#ffffff"
|
| 90 |
+
r = 9
|
| 91 |
+
dr.ellipse([x - r - 2, y - r - 2, x + r + 2, y + r + 2], outline="#000000", width=2)
|
| 92 |
+
dr.ellipse([x - r, y - r, x + r, y + r], outline=c, width=3)
|
| 93 |
+
dr.line([x - r - 6, y, x - r + 3, y], fill=c, width=2)
|
| 94 |
+
dr.line([x + r - 3, y, x + r + 6, y], fill=c, width=2)
|
| 95 |
+
dr.line([x, y - r - 6, x, y - r + 3], fill=c, width=2)
|
| 96 |
+
dr.line([x, y + r - 3, x, y + r + 6], fill=c, width=2)
|
| 97 |
+
return np.asarray(im)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def sample(d: dict, x: int, y: int):
|
| 101 |
+
st, o = int(d["stride"]), int(d["offset"])
|
| 102 |
+
hh, ww = d["clean"].shape[:2]
|
| 103 |
+
i = int(np.clip(round((y - o) / st), 0, hh - 1))
|
| 104 |
+
j = int(np.clip(round((x - o) / st), 0, ww - 1))
|
| 105 |
+
return i, j, st * j + o, st * i + o # cube index and the full-resolution pixel it samples
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def class_name(w: str, c: int) -> str:
|
| 109 |
+
return "background (no surface)" if c < 0 else pretty(WORLDS[w]["classes"][c])
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def spectrum_fig(w: str, stem: str, picks: list) -> go.Figure:
|
| 113 |
+
d = load_view(w, stem)
|
| 114 |
+
wl = np.asarray(WORLDS[w]["wavelengths"])
|
| 115 |
+
fig = go.Figure()
|
| 116 |
+
fig.add_vrect(x0=wl[0], x1=700, fillcolor="rgba(127,127,127,0.06)", line_width=0, layer="below")
|
| 117 |
+
fig.add_annotation(x=560, y=1.0, yref="paper", text="visible", showarrow=False,
|
| 118 |
+
font=dict(size=11, color="#888"), yanchor="bottom")
|
| 119 |
+
fig.add_annotation(x=840, y=1.0, yref="paper", text="near infrared", showarrow=False,
|
| 120 |
+
font=dict(size=11, color="#888"), yanchor="bottom")
|
| 121 |
+
if len(picks) == 1:
|
| 122 |
+
x, y = picks[0]
|
| 123 |
+
i, j, px, py = sample(d, x, y)
|
| 124 |
+
fig.add_trace(go.Scatter(x=wl, y=d["noisy"][i, j], name="noisy observation", mode="lines",
|
| 125 |
+
line=dict(color=NOISY_COLOR, width=1.2), opacity=0.8,
|
| 126 |
+
hovertemplate="%{x:.1f} nm<br>%{y:.4g}<extra>noisy</extra>"))
|
| 127 |
+
fig.add_trace(go.Scatter(x=wl, y=d["clean"][i, j], name="clean radiance", mode="lines",
|
| 128 |
+
line=dict(color=CLEAN_COLOR, width=2.2),
|
| 129 |
+
hovertemplate="%{x:.1f} nm<br>%{y:.4g}<extra>clean</extra>"))
|
| 130 |
+
else:
|
| 131 |
+
for k, (x, y) in enumerate(picks):
|
| 132 |
+
i, j, px, py = sample(d, x, y)
|
| 133 |
+
c = int(d["material"][py, px])
|
| 134 |
+
fig.add_trace(go.Scatter(x=wl, y=d["clean"][i, j], mode="lines",
|
| 135 |
+
name=f"#{k + 1} {class_name(w, c)}",
|
| 136 |
+
line=dict(color=PICK_COLORS[k % len(PICK_COLORS)], width=2.2),
|
| 137 |
+
hovertemplate="%{x:.1f} nm<br>%{y:.4g}<extra>#" + str(k + 1) + "</extra>"))
|
| 138 |
+
fig.update_layout(
|
| 139 |
+
template="plotly_white", height=330, margin=dict(l=64, r=16, t=30, b=58),
|
| 140 |
+
xaxis=dict(title="wavelength (nm)", range=[wl[0] - 4, wl[-1] + 4], showgrid=False,
|
| 141 |
+
ticks="outside", tickcolor="#bbb"),
|
| 142 |
+
yaxis=dict(title=f"radiance ({UNITS})", gridcolor="rgba(127,127,127,0.18)", zeroline=False,
|
| 143 |
+
rangemode="tozero"),
|
| 144 |
+
legend=dict(orientation="h", yanchor="top", y=-0.26, x=0, font=dict(size=11)),
|
| 145 |
+
hovermode="x unified", paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)",
|
| 146 |
+
font=dict(size=12),
|
| 147 |
+
)
|
| 148 |
+
return fig
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def abundance_fig(w: str, stem: str, pick) -> go.Figure:
|
| 152 |
+
d = load_view(w, stem)
|
| 153 |
+
i, j, px, py = sample(d, *pick)
|
| 154 |
+
a = d["abundance"][i, j]
|
| 155 |
+
names, pal = WORLDS[w]["classes"], WORLDS[w]["palette"]
|
| 156 |
+
idx = [c for c in np.argsort(-a) if a[c] > 1e-3]
|
| 157 |
+
fig = go.Figure()
|
| 158 |
+
if idx:
|
| 159 |
+
fig.add_trace(go.Bar(
|
| 160 |
+
y=[pretty(names[c]) for c in idx][::-1], x=[float(a[c]) for c in idx][::-1], orientation="h",
|
| 161 |
+
marker=dict(color=[pal[c] for c in idx][::-1], line=dict(color="rgba(0,0,0,0.35)", width=1)),
|
| 162 |
+
text=[f"{a[c]:.2f}" for c in idx][::-1], textposition="outside", cliponaxis=False,
|
| 163 |
+
hovertemplate="%{y}: %{x:.3f}<extra></extra>"))
|
| 164 |
+
else:
|
| 165 |
+
fig.add_annotation(text="no surface at this pixel", x=0.5, y=0.5, xref="paper", yref="paper",
|
| 166 |
+
showarrow=False, font=dict(color="#888"))
|
| 167 |
+
fig.update_layout(
|
| 168 |
+
template="plotly_white", height=max(150, 60 + 30 * max(len(idx), 1)),
|
| 169 |
+
margin=dict(l=10, r=40, t=10, b=34),
|
| 170 |
+
xaxis=dict(range=[0, 1.12], title="area abundance (16 sub-pixel samples)", tickvals=[0, 0.5, 1],
|
| 171 |
+
gridcolor="rgba(127,127,127,0.18)"),
|
| 172 |
+
yaxis=dict(automargin=True), bargap=0.35, showlegend=False,
|
| 173 |
+
paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)", font=dict(size=12))
|
| 174 |
+
return fig
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
def legend_html(w: str, stem: str) -> str:
|
| 178 |
+
v = next(v for v in WORLDS[w]["views"] if v["stem"] == stem)
|
| 179 |
+
names, pal = WORLDS[w]["classes"], WORLDS[w]["palette"]
|
| 180 |
+
items = "".join(
|
| 181 |
+
f'<span class="swr-chip"><span class="swr-sw" style="background:{pal[c]}"></span>{pretty(names[c])}</span>'
|
| 182 |
+
for c in range(len(names)) if c in v["present_classes"])
|
| 183 |
+
return f'<div class="swr-legend">{items}</div>'
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def info_md(w: str, stem: str, picks: list) -> str:
|
| 187 |
+
d = load_view(w, stem)
|
| 188 |
+
wl = np.asarray(WORLDS[w]["wavelengths"])
|
| 189 |
+
rows = []
|
| 190 |
+
for k, (x, y) in enumerate(picks):
|
| 191 |
+
i, j, px, py = sample(d, x, y)
|
| 192 |
+
c = int(d["material"][py, px])
|
| 193 |
+
cl = d["clean"][i, j]
|
| 194 |
+
tag = f"**#{k + 1}** · " if len(picks) > 1 else ""
|
| 195 |
+
rows.append(f"{tag}pixel **(x={px}, y={py})** · material **{class_name(w, c)}** · "
|
| 196 |
+
f"peak {cl.max():.3g} at {wl[int(cl.argmax())]:.0f} nm")
|
| 197 |
+
return "<br>".join(rows)
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def world_md(w: str) -> str:
|
| 201 |
+
m = WORLDS[w]
|
| 202 |
+
return (f"**{m['name']}** — {m['setting']} · {len(m['classes'])} material classes · "
|
| 203 |
+
f"[browse files](https://huggingface.co/datasets/ming0531/SWR-Bench/tree/main/{w})")
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
def code_md(w: str, stem: str) -> str:
|
| 207 |
+
return f"""```python
|
| 208 |
+
from huggingface_hub import hf_hub_download
|
| 209 |
+
import numpy as np
|
| 210 |
+
|
| 211 |
+
repo = "ming0531/SWR-Bench"
|
| 212 |
+
cube = np.load(hf_hub_download(repo, "{w}/hsi_noisy/{stem}.npy", repo_type="dataset")) # (540, 960, 64) float32
|
| 213 |
+
gt = np.load(hf_hub_download(repo, "{w}/gt/{stem}.npz", repo_type="dataset")) # material, abundances, ...
|
| 214 |
+
```
|
| 215 |
+
For whole worlds and the unified ground-truth reader (`SWRScene`), see the [dataset card]({LINKS['Dataset']})."""
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
# ------------------------------------------------------------------------------------------------- callbacks
|
| 219 |
+
def render(w, stem, layer, cls_label, picks):
|
| 220 |
+
cls = int(cls_label) if layer == LAYERS[3] and cls_label is not None else 0
|
| 221 |
+
img = draw_picks(base_image(w, stem, layer, cls), picks)
|
| 222 |
+
pick = picks[-1]
|
| 223 |
+
return (img, spectrum_fig(w, stem, picks), abundance_fig(w, stem, pick), info_md(w, stem, picks))
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
def default_pick():
|
| 227 |
+
return [(W // 2, int(H * 0.62))]
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
def on_world(w):
|
| 231 |
+
views = [view_label(w, v) for v in WORLDS[w]["views"]]
|
| 232 |
+
classes = [(pretty(c), i) for i, c in enumerate(WORLDS[w]["classes"])]
|
| 233 |
+
stem = WORLDS[w]["views"][0]["stem"]
|
| 234 |
+
picks = default_pick()
|
| 235 |
+
return (gr.update(choices=views, value=views[0]), gr.update(choices=classes, value=0),
|
| 236 |
+
world_md(w), legend_html(w, stem), code_md(w, stem), picks,
|
| 237 |
+
*render(w, stem, LAYERS[0], 0, picks), LAYERS[0])
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
def on_view(w, view, layer, cls_label):
|
| 241 |
+
stem = view_stem(w, view)
|
| 242 |
+
picks = default_pick()
|
| 243 |
+
return (legend_html(w, stem), code_md(w, stem), picks, *render(w, stem, layer, cls_label, picks))
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
def on_layer(w, view, layer, cls_label, picks):
|
| 247 |
+
return (gr.update(visible=layer == LAYERS[3]),
|
| 248 |
+
*render(w, view_stem(w, view), layer, cls_label, picks))
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def on_click(w, view, layer, cls_label, compare, picks, evt: gr.SelectData):
|
| 252 |
+
x, y = int(evt.index[0]), int(evt.index[1])
|
| 253 |
+
picks = (list(picks) + [(x, y)])[-MAX_PICKS:] if compare else [(x, y)]
|
| 254 |
+
return (picks, *render(w, view_stem(w, view), layer, cls_label, picks))
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
def on_compare(w, view, layer, cls_label, compare, picks):
|
| 258 |
+
picks = list(picks)[-1:] if not compare else list(picks)
|
| 259 |
+
return (picks, *render(w, view_stem(w, view), layer, cls_label, picks))
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
# ------------------------------------------------------------------------------------------------- layout
|
| 263 |
+
CSS = """
|
| 264 |
+
.gradio-container {max-width: 1320px !important; margin: 0 auto;}
|
| 265 |
+
#swr-head h1 {font-size: 1.75rem; margin: 0.2rem 0 0.1rem 0; letter-spacing: -0.01em;}
|
| 266 |
+
#swr-head p {margin: 0.25rem 0; opacity: 0.85;}
|
| 267 |
+
.swr-links a {display: inline-block; margin: 0.25rem 0.35rem 0 0; padding: 0.22rem 0.7rem; border-radius: 999px;
|
| 268 |
+
border: 1px solid var(--border-color-primary); text-decoration: none !important; font-size: 0.86rem;}
|
| 269 |
+
.swr-links a:hover {background: var(--background-fill-secondary);}
|
| 270 |
+
.swr-legend {display: flex; flex-wrap: wrap; gap: 0.35rem 0.9rem; font-size: 0.85rem; padding: 0.2rem 0;}
|
| 271 |
+
.swr-chip {display: inline-flex; align-items: center; gap: 0.35rem;}
|
| 272 |
+
.swr-sw {width: 0.85rem; height: 0.85rem; border-radius: 3px; border: 1px solid rgba(127,127,127,0.5);}
|
| 273 |
+
#swr-img img {cursor: crosshair;}
|
| 274 |
+
.swr-foot {font-size: 0.8rem; opacity: 0.8; line-height: 1.45;}
|
| 275 |
+
"""
|
| 276 |
+
|
| 277 |
+
HEAD = f"""<div id="swr-head">
|
| 278 |
+
<h1>SWR-Bench Explorer</h1>
|
| 279 |
+
<p>Multi-view <b>hyperspectral</b> renders (64 bands, 420–980 nm) with pixel-aligned material and sub-pixel abundance
|
| 280 |
+
ground truth, from <i>Spectral World Renderer: Unified 3D Hyperspectral Unmixing</i>.
|
| 281 |
+
Pick a world and a view, then <b>click any pixel</b> to see its spectrum.</p>
|
| 282 |
+
<div class="swr-links">{''.join(f'<a href="{u}" target="_blank">{k}</a>' for k, u in LINKS.items())}</div>
|
| 283 |
+
</div>"""
|
| 284 |
+
|
| 285 |
+
FOOT = """<div class="swr-foot">
|
| 286 |
+
<b>About this preview.</b> Three test views per world; spectra and abundances are those of the full-resolution pixel
|
| 287 |
+
nearest to the click on a 3-pixel grid (no averaging), stored as float16. The full dataset (12 datasets, 2,364 views,
|
| 288 |
+
960×540 float32 noisy and clean cubes, shading coefficients, instances, depth, normals, cameras) is at
|
| 289 |
+
<a href="https://huggingface.co/datasets/ming0531/SWR-Bench">ming0531/SWR-Bench</a>. The NVIDIA HQ world is not shown here.<br>
|
| 290 |
+
<b>Licence and attribution.</b> Rendered data and ground truth: CC BY 4.0. Material spectra come from the
|
| 291 |
+
<b>ECOSTRESS Spectral Library</b>, courtesy of the Jet Propulsion Laboratory, California Institute of Technology
|
| 292 |
+
(© 2017 Caltech, <a href="https://speclib.jpl.nasa.gov/">speclib.jpl.nasa.gov</a>; Meerdink et al., 2019; Baldridge et al., 2009;
|
| 293 |
+
not covered by CC BY 4.0), and the <b>USGS Spectral Library Version 7</b> (public domain; Kokaly et al., 2017,
|
| 294 |
+
<a href="https://doi.org/10.5066/F7RR1WDJ">doi:10.5066/F7RR1WDJ</a>).<br>
|
| 295 |
+
<b>Citation.</b> Lee, Hsiao, Chang, Li, Liu, Hsu. <i>Spectral World Renderer: Unified 3D Hyperspectral Unmixing.</i>
|
| 296 |
+
arXiv:2610.19520, 2026.
|
| 297 |
+
</div>"""
|
| 298 |
+
|
| 299 |
+
W0 = "market" if "market" in WORLDS else next(iter(WORLDS))
|
| 300 |
+
PICK0 = [(193, 271)] if W0 == "market" else default_pick() # vegetation pixel: clear red-edge in the first spectrum
|
| 301 |
+
STEM0 = WORLDS[W0]["views"][0]["stem"]
|
| 302 |
+
CLASSES0 = [(pretty(c), i) for i, c in enumerate(WORLDS[W0]["classes"])]
|
| 303 |
+
VIEWS0 = [view_label(W0, v) for v in WORLDS[W0]["views"]]
|
| 304 |
+
IMG0, SPEC0, AB0, INFO0 = render(W0, STEM0, LAYERS[0], 0, PICK0)
|
| 305 |
+
|
| 306 |
+
theme = gr.themes.Soft(primary_hue="blue", neutral_hue="slate",
|
| 307 |
+
font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"])
|
| 308 |
+
|
| 309 |
+
with gr.Blocks(title="SWR-Bench Explorer", theme=theme, css=CSS) as demo:
|
| 310 |
+
picks = gr.State(PICK0)
|
| 311 |
+
gr.HTML(HEAD)
|
| 312 |
+
with gr.Row(equal_height=False):
|
| 313 |
+
with gr.Column(scale=3):
|
| 314 |
+
with gr.Row():
|
| 315 |
+
world = gr.Dropdown([(m["name"], k) for k, m in WORLDS.items()], value=W0, label="World", scale=2)
|
| 316 |
+
view = gr.Dropdown(VIEWS0, value=VIEWS0[0], label="View", scale=2)
|
| 317 |
+
wmd = gr.Markdown(world_md(W0))
|
| 318 |
+
layer = gr.Radio(LAYERS, value=LAYERS[0], label="Layer", container=False)
|
| 319 |
+
cls = gr.Dropdown(CLASSES0, value=0, label="Abundance class", visible=False,
|
| 320 |
+
info="Area fraction per pixel: dark = 0, light blue = 1; black = no surface.")
|
| 321 |
+
img = gr.Image(IMG0, label="Click a pixel", interactive=False, elem_id="swr-img",
|
| 322 |
+
show_download_button=False, show_fullscreen_button=True, show_share_button=False,
|
| 323 |
+
format="jpeg")
|
| 324 |
+
legend = gr.HTML(legend_html(W0, STEM0))
|
| 325 |
+
with gr.Column(scale=2):
|
| 326 |
+
info = gr.Markdown(INFO0)
|
| 327 |
+
gr.Markdown("#### Radiance spectrum")
|
| 328 |
+
spec = gr.Plot(SPEC0, show_label=False)
|
| 329 |
+
compare = gr.Checkbox(False, label=f"Compare mode: keep up to {MAX_PICKS} clicked pixels (clean spectra)")
|
| 330 |
+
gr.Markdown("#### Ground-truth abundances at the last clicked pixel")
|
| 331 |
+
ab = gr.Plot(AB0, show_label=False)
|
| 332 |
+
with gr.Accordion("Load this view from the dataset", open=False):
|
| 333 |
+
code = gr.Markdown(code_md(W0, STEM0))
|
| 334 |
+
gr.HTML(FOOT)
|
| 335 |
+
|
| 336 |
+
outs = [img, spec, ab, info]
|
| 337 |
+
world.change(on_world, [world], [view, cls, wmd, legend, code, picks, *outs, layer])
|
| 338 |
+
view.input(on_view, [world, view, layer, cls], [legend, code, picks, *outs])
|
| 339 |
+
layer.change(on_layer, [world, view, layer, cls, picks], [cls, *outs])
|
| 340 |
+
cls.change(on_layer, [world, view, layer, cls, picks], [cls, *outs])
|
| 341 |
+
img.select(on_click, [world, view, layer, cls, compare, picks], [picks, *outs])
|
| 342 |
+
compare.change(on_compare, [world, view, layer, cls, compare, picks], [picks, *outs])
|
| 343 |
+
|
| 344 |
+
if __name__ == "__main__":
|
| 345 |
+
demo.launch()
|
build_preview.py
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Build the small preview subset shipped with the SWR-Bench Explorer Space.
|
| 3 |
+
|
| 4 |
+
For every world (nvidia_hq excluded) a few TEST views are fetched from the public dataset
|
| 5 |
+
(ming0531/SWR-Bench), read with the official loader (tools/swr_bench.py) and reduced to:
|
| 6 |
+
|
| 7 |
+
data/<world>/<stem>.npz clean + noisy cube, area abundances (every STRIDE-th pixel, float16)
|
| 8 |
+
material id map (full resolution, uint8, 0 = background)
|
| 9 |
+
data/<world>/<stem>_rgb.jpg released sRGB render (full resolution)
|
| 10 |
+
data/<world>/<stem>_mat.png material ground truth, coloured with the world palette
|
| 11 |
+
data/<world>/<stem>_cir.jpg colour-infrared composite (850/650/550 nm) of the clean cube
|
| 12 |
+
data/meta.json worlds, classes, palettes, wavelengths, views
|
| 13 |
+
|
| 14 |
+
Cube and ground-truth spectra are point samples of the full-resolution pixel (STRIDE*i+o, STRIDE*j+o);
|
| 15 |
+
nothing is averaged, so the noisy and clean spectra and the abundances refer to exactly the same pixel.
|
| 16 |
+
Raw downloads go to _raw/ and the large cubes are deleted after use.
|
| 17 |
+
|
| 18 |
+
Usage: .venv/bin/python build_preview.py [--views 3] [--stride 3] [--workers 4]
|
| 19 |
+
"""
|
| 20 |
+
from __future__ import annotations
|
| 21 |
+
|
| 22 |
+
import argparse
|
| 23 |
+
import json
|
| 24 |
+
import os
|
| 25 |
+
import sys
|
| 26 |
+
import time
|
| 27 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 28 |
+
from pathlib import Path
|
| 29 |
+
|
| 30 |
+
import numpy as np
|
| 31 |
+
from huggingface_hub import hf_hub_download
|
| 32 |
+
from PIL import Image
|
| 33 |
+
|
| 34 |
+
REPO = "ming0531/SWR-Bench"
|
| 35 |
+
HERE = Path(__file__).resolve().parent
|
| 36 |
+
RAW = HERE / "_raw"
|
| 37 |
+
OUT = HERE / "data"
|
| 38 |
+
|
| 39 |
+
WORLDS = [ # (key, display name, setting); nvidia_hq deliberately excluded (trademark notice on the card)
|
| 40 |
+
("forbidden_city", "Forbidden City", "outdoor · palace complex"),
|
| 41 |
+
("market", "Market", "outdoor · market square with stalls and pottery"),
|
| 42 |
+
("botanical", "Botanical", "outdoor · botanical garden"),
|
| 43 |
+
("karst", "Karst", "outdoor · karst river valley with clear water"),
|
| 44 |
+
("city", "City", "outdoor · campus block in a city"),
|
| 45 |
+
("study", "Study", "indoor · scholar's study, spectral path tracing"),
|
| 46 |
+
("office", "Office", "indoor · open-plan office, spectral path tracing"),
|
| 47 |
+
("city_metamer", "City · metamers", "City variant · RGB metamers for vegetation and car paint"),
|
| 48 |
+
("city_stress", "City · stress", "City variant · dry or senescent foliage on ~25% of trees"),
|
| 49 |
+
("city_morning", "City · morning", "City variant · morning sun position"),
|
| 50 |
+
("city_afternoon", "City · afternoon", "City variant · afternoon sun position"),
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
+
# fallback categorical order (validated reference palette) for worlds without a palette in their protocol
|
| 54 |
+
FALLBACK = ["#257de0", "#f47230", "#00b894", "#f2a600", "#ee7fac", "#008a17", "#6a4ce2", "#ec4647"]
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def fetch(rel):
|
| 58 |
+
return Path(hf_hub_download(REPO, rel, repo_type="dataset", local_dir=RAW))
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def hexrgb(c):
|
| 62 |
+
return "#%02x%02x%02x" % tuple(int(v) for v in c[:3])
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def world_palette(sc, key, names, stem):
|
| 66 |
+
if sc.family == "indoor":
|
| 67 |
+
pal = json.load(open(sc.shared / "scene_protocol.json")).get("material_palette")
|
| 68 |
+
else:
|
| 69 |
+
proto = json.load(open(sc.dir / "material_class_protocol.json"))
|
| 70 |
+
pal = proto.get("primary_palette") or proto.get("palette_rgb")
|
| 71 |
+
if pal and len(pal) >= len(names):
|
| 72 |
+
return [hexrgb(c) for c in pal[: len(names)]]
|
| 73 |
+
# derive from the released merged material preview of one view (per-class median colour)
|
| 74 |
+
try:
|
| 75 |
+
prev = np.asarray(Image.open(fetch(f"{key}/material_gt_rgb_merged/{stem}.png")).convert("RGB"))
|
| 76 |
+
mat = sc.load_gt(stem)["material"]
|
| 77 |
+
out = []
|
| 78 |
+
for c in range(len(names)):
|
| 79 |
+
m = mat == c
|
| 80 |
+
out.append(hexrgb(np.median(prev[m], 0)) if m.sum() > 20 else FALLBACK[c % len(FALLBACK)])
|
| 81 |
+
return out
|
| 82 |
+
except Exception as e: # pragma: no cover
|
| 83 |
+
print(f"[{key}] palette fallback: {e}", file=sys.stderr)
|
| 84 |
+
return [FALLBACK[c % len(FALLBACK)] for c in range(len(names))]
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def build_world(key, name, setting, n_views, stride, keep_raw):
|
| 88 |
+
t0 = time.time()
|
| 89 |
+
for s in ("train", "val", "test"):
|
| 90 |
+
fetch(f"{key}/transforms_{s}.json")
|
| 91 |
+
for rel in (f"{key}/noise_settings.json", f"{key}/gt/spectral_sample_bank.npz",
|
| 92 |
+
f"{key}/material_class_protocol.json", f"{key}/scene_protocol.json",
|
| 93 |
+
f"{key}/spectral_materials.npz"):
|
| 94 |
+
try:
|
| 95 |
+
fetch(rel)
|
| 96 |
+
except Exception:
|
| 97 |
+
pass
|
| 98 |
+
sys.path.insert(0, str(RAW / "tools"))
|
| 99 |
+
from swr_bench import SWRScene, false_colour # official loader
|
| 100 |
+
|
| 101 |
+
sc = SWRScene(RAW, key, "noisy")
|
| 102 |
+
names = sc.class_names()
|
| 103 |
+
wl = sc.wavelengths()
|
| 104 |
+
n_test = len(sc.stems("test"))
|
| 105 |
+
idx = sorted(set(np.linspace(0, n_test - 1, n_views).round().astype(int).tolist()))
|
| 106 |
+
od = OUT / key
|
| 107 |
+
od.mkdir(parents=True, exist_ok=True)
|
| 108 |
+
views, palette = [], None
|
| 109 |
+
o = stride // 2
|
| 110 |
+
for i in idx:
|
| 111 |
+
cam = sc.camera("test", i)
|
| 112 |
+
stem = cam["stem"]
|
| 113 |
+
rels = [f"{key}/hsi_clean/{stem}.npy", f"{key}/hsi_noisy/{stem}.npy", f"{key}/gt/{stem}.npz",
|
| 114 |
+
f"{key}/images/{stem}.png"]
|
| 115 |
+
for r in rels:
|
| 116 |
+
fetch(r)
|
| 117 |
+
gt = sc.load_gt(stem)
|
| 118 |
+
if palette is None:
|
| 119 |
+
palette = world_palette(sc, key, names, stem)
|
| 120 |
+
clean = np.asarray(sc.load_cube(stem))
|
| 121 |
+
noisy = np.asarray(sc.load_cube(stem, other=True))
|
| 122 |
+
sl = (slice(o, None, stride), slice(o, None, stride))
|
| 123 |
+
c_s, n_s = clean[sl].astype(np.float32), noisy[sl].astype(np.float32)
|
| 124 |
+
scale = float(max(np.abs(c_s).max(), np.abs(n_s).max(), 1e-30))
|
| 125 |
+
mat = gt["material"].astype(np.int16)
|
| 126 |
+
ab = gt["abundance_area"][sl].astype(np.float16)
|
| 127 |
+
np.savez_compressed(
|
| 128 |
+
od / f"{stem}.npz",
|
| 129 |
+
clean=(c_s / scale).astype(np.float16), noisy=(n_s / scale).astype(np.float16),
|
| 130 |
+
scale=np.float32(scale), abundance=ab, material=(mat + 1).astype(np.uint8),
|
| 131 |
+
stride=np.int32(stride), offset=np.int32(o))
|
| 132 |
+
# images
|
| 133 |
+
Image.fromarray(sc.load_rgb(stem)[..., :3]).save(od / f"{stem}_rgb.jpg", quality=90)
|
| 134 |
+
lut = np.zeros((len(names) + 1, 3), np.uint8)
|
| 135 |
+
lut[0] = (24, 24, 27)
|
| 136 |
+
for c, h in enumerate(palette):
|
| 137 |
+
lut[c + 1] = [int(h[k:k + 2], 16) for k in (1, 3, 5)]
|
| 138 |
+
Image.fromarray(lut[mat + 1]).save(od / f"{stem}_mat.png", optimize=True)
|
| 139 |
+
Image.fromarray(false_colour(clean, wl)).save(od / f"{stem}_cir.jpg", quality=90)
|
| 140 |
+
present = sorted(int(c) for c in np.unique(mat) if c >= 0)
|
| 141 |
+
views.append(dict(stem=stem, split="test", test_index=int(i), present_classes=present))
|
| 142 |
+
del clean, noisy, c_s, n_s, gt
|
| 143 |
+
if not keep_raw:
|
| 144 |
+
for r in rels[:3]:
|
| 145 |
+
try:
|
| 146 |
+
os.remove(RAW / r)
|
| 147 |
+
except FileNotFoundError:
|
| 148 |
+
pass
|
| 149 |
+
print(f"[{key}] {stem} done ({time.time() - t0:.0f}s)", flush=True)
|
| 150 |
+
fam = sc.family
|
| 151 |
+
return key, dict(name=name, setting=setting, family=fam, classes=names, palette=palette,
|
| 152 |
+
views=views, n_test=n_test, wavelengths=[float(x) for x in wl])
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def main():
|
| 156 |
+
ap = argparse.ArgumentParser()
|
| 157 |
+
ap.add_argument("--views", type=int, default=3)
|
| 158 |
+
ap.add_argument("--stride", type=int, default=3)
|
| 159 |
+
ap.add_argument("--workers", type=int, default=4)
|
| 160 |
+
ap.add_argument("--worlds", nargs="*")
|
| 161 |
+
ap.add_argument("--keep-raw", action="store_true")
|
| 162 |
+
a = ap.parse_args()
|
| 163 |
+
fetch("tools/swr_bench.py")
|
| 164 |
+
OUT.mkdir(exist_ok=True)
|
| 165 |
+
todo = [w for w in WORLDS if not a.worlds or w[0] in a.worlds]
|
| 166 |
+
meta_p = OUT / "meta.json"
|
| 167 |
+
meta = json.load(open(meta_p)) if meta_p.is_file() else {"worlds": {}}
|
| 168 |
+
with ThreadPoolExecutor(a.workers) as ex:
|
| 169 |
+
res = list(ex.map(lambda w: build_world(*w, a.views, a.stride, a.keep_raw), todo))
|
| 170 |
+
for k, v in res:
|
| 171 |
+
meta["worlds"][k] = v
|
| 172 |
+
order = [w[0] for w in WORLDS]
|
| 173 |
+
meta["worlds"] = {k: meta["worlds"][k] for k in order if k in meta["worlds"]}
|
| 174 |
+
meta.update(repo=REPO, units="W m^-2 sr^-1 nm^-1", resolution=[540, 960], stride=a.stride)
|
| 175 |
+
json.dump(meta, open(meta_p, "w"), indent=1)
|
| 176 |
+
print("wrote", meta_p)
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
if __name__ == "__main__":
|
| 180 |
+
main()
|
data/botanical/f_0000.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d61bc0ac384548115dc6928b4be236ff217bc23c2d0daca0a269f3fdb3e18dbb
|
| 3 |
+
size 12303957
|
data/botanical/f_0000_cir.jpg
ADDED
|
Git LFS Details
|
data/botanical/f_0000_mat.png
ADDED
|
data/botanical/f_0000_rgb.jpg
ADDED
|
Git LFS Details
|
data/botanical/f_0092.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:87ddf249debc0d237608352db974a2e43630e1d6e162ca37fc92718659471bf5
|
| 3 |
+
size 12582641
|
data/botanical/f_0092_cir.jpg
ADDED
|
Git LFS Details
|
data/botanical/f_0092_mat.png
ADDED
|
data/botanical/f_0092_rgb.jpg
ADDED
|
Git LFS Details
|
data/botanical/f_0176.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:91d507d439ee363a0dfeace7f51482321faca7882c383f1e9b016ec290253b3a
|
| 3 |
+
size 12423808
|
data/botanical/f_0176_cir.jpg
ADDED
|
Git LFS Details
|
data/botanical/f_0176_mat.png
ADDED
|
data/botanical/f_0176_rgb.jpg
ADDED
|
Git LFS Details
|
data/city/f_0000.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:87461d4a8ec39aa41e53bef6e61e80c18607cc71e96280620a446c2be63ffff3
|
| 3 |
+
size 11055905
|
data/city/f_0000_cir.jpg
ADDED
|
Git LFS Details
|
data/city/f_0000_mat.png
ADDED
|
data/city/f_0000_rgb.jpg
ADDED
|
Git LFS Details
|
data/city/f_0120.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:62baf2019ed36e84430b65facec1cb9ac2184f8601cb77767ff419a5a85992b6
|
| 3 |
+
size 11443891
|
data/city/f_0120_cir.jpg
ADDED
|
Git LFS Details
|
data/city/f_0120_mat.png
ADDED
|
data/city/f_0120_rgb.jpg
ADDED
|
Git LFS Details
|
data/city/f_0236.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6376c83b8a16ca9bc14758250bac9c98dac03a54d92493e00a9e124c7b1d629d
|
| 3 |
+
size 11286164
|
data/city/f_0236_cir.jpg
ADDED
|
Git LFS Details
|
data/city/f_0236_mat.png
ADDED
|
data/city/f_0236_rgb.jpg
ADDED
|
Git LFS Details
|
data/city_afternoon/f_0000.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dda260f7f70dac5a807ed73c4110bd0a454394fc01b7fd2d5de8676372171e08
|
| 3 |
+
size 11156368
|
data/city_afternoon/f_0000_cir.jpg
ADDED
|
Git LFS Details
|
data/city_afternoon/f_0000_mat.png
ADDED
|
data/city_afternoon/f_0000_rgb.jpg
ADDED
|
Git LFS Details
|
data/city_afternoon/f_0120.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ddeba0f322bc75be1e7497dea0553fc1c705366b4ed96b33983d63e1aee08778
|
| 3 |
+
size 11488064
|
data/city_afternoon/f_0120_cir.jpg
ADDED
|
Git LFS Details
|
data/city_afternoon/f_0120_mat.png
ADDED
|
data/city_afternoon/f_0120_rgb.jpg
ADDED
|
Git LFS Details
|
data/city_afternoon/f_0236.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:eb844f23738e65c35ca6db01e15190173a97f02c8454b3ca2c671eb9c656c2f4
|
| 3 |
+
size 11552399
|
data/city_afternoon/f_0236_cir.jpg
ADDED
|
Git LFS Details
|
data/city_afternoon/f_0236_mat.png
ADDED
|
data/city_afternoon/f_0236_rgb.jpg
ADDED
|
Git LFS Details
|
data/city_metamer/f_0000.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bc6749c95164e9c5bf6265ce03a410d218e35b8b64d3890ecb68669f72f9c8a1
|
| 3 |
+
size 11062041
|
data/city_metamer/f_0000_cir.jpg
ADDED
|
Git LFS Details
|
data/city_metamer/f_0000_mat.png
ADDED
|
data/city_metamer/f_0000_rgb.jpg
ADDED
|
Git LFS Details
|
data/city_metamer/f_0120.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ec37b6e7f5fdddbe994d41ca6f3be3670553f9c010480efadf05abcc1350cb61
|
| 3 |
+
size 11459715
|
data/city_metamer/f_0120_cir.jpg
ADDED
|
Git LFS Details
|
data/city_metamer/f_0120_mat.png
ADDED
|
data/city_metamer/f_0120_rgb.jpg
ADDED
|
Git LFS Details
|
data/city_metamer/f_0236.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c8683efa16671bafaf22167cbcfa1f76ad062211df2494d2dc47c224b192a5fd
|
| 3 |
+
size 11305311
|