Embed synchronized perception states in benchmark rows
#2
by hynky - opened
- README.md +27 -0
- data/annotations.parquet +2 -2
- data/annotations.parquet.provenance.json +38 -0
- scripts/embed_perception_states.py +149 -0
- scripts/perception_sources.lock.json +49 -0
- scripts/perception_states.py +271 -0
README.md
CHANGED
|
@@ -44,6 +44,7 @@ Each row contains one video episode, a high-level task instruction, and gold sub
|
|
| 44 |
| Source families | 3 |
|
| 45 |
| Format | Parquet |
|
| 46 |
| Video storage | MP4 bytes embedded in each row |
|
|
|
|
| 47 |
|
| 48 |
## Sources
|
| 49 |
|
|
@@ -62,6 +63,12 @@ Each row contains one video episode, a high-level task instruction, and gold sub
|
|
| 62 |
| `instruction` | string | High-level task instruction for the episode. |
|
| 63 |
| `segments` | list | Gold `{start_sec, end_sec, subtask}` annotations. |
|
| 64 |
| `metadata` | string | JSON metadata with source-specific fields. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
## Quick Start
|
| 67 |
|
|
@@ -73,6 +80,7 @@ example = dataset[0]
|
|
| 73 |
|
| 74 |
print(example["instruction"])
|
| 75 |
print(example["segments"])
|
|
|
|
| 76 |
```
|
| 77 |
|
| 78 |
To use the parquet directly:
|
|
@@ -83,6 +91,25 @@ import pandas as pd
|
|
| 83 |
df = pd.read_parquet("hf://datasets/macrodata/WGO-Bench/data/annotations.parquet")
|
| 84 |
```
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
## Annotation Policy
|
| 87 |
|
| 88 |
Segments are intended to describe completed manipulation events, not every small pose adjustment. A new segment should generally correspond to a visible state change such as picking up, placing, opening, closing, moving, pouring, wiping, cutting, or transferring an object.
|
|
|
|
| 44 |
| Source families | 3 |
|
| 45 |
| Format | Parquet |
|
| 46 |
| Video storage | MP4 bytes embedded in each row |
|
| 47 |
+
| Robot-state coverage | 75 robotic episodes; HomER is video-only |
|
| 48 |
|
| 49 |
## Sources
|
| 50 |
|
|
|
|
| 63 |
| `instruction` | string | High-level task instruction for the episode. |
|
| 64 |
| `segments` | list | Gold `{start_sec, end_sec, subtask}` annotations. |
|
| 65 |
| `metadata` | string | JSON metadata with source-specific fields. |
|
| 66 |
+
| `perception_state` | struct or null | Synchronized, named robot-state channels for DROID/Galaxea; null for HomER. |
|
| 67 |
+
|
| 68 |
+
DROID retains EEF position, rotation, and gripper state. Galaxea retains
|
| 69 |
+
bilateral arm joints and grippers plus its available EEF- and gripper-derived
|
| 70 |
+
channels. Actions are not included. HomER has no robot telemetry, so its rows
|
| 71 |
+
contain `null` rather than synthetic zeros.
|
| 72 |
|
| 73 |
## Quick Start
|
| 74 |
|
|
|
|
| 80 |
|
| 81 |
print(example["instruction"])
|
| 82 |
print(example["segments"])
|
| 83 |
+
print(example["perception_state"])
|
| 84 |
```
|
| 85 |
|
| 86 |
To use the parquet directly:
|
|
|
|
| 91 |
df = pd.read_parquet("hf://datasets/macrodata/WGO-Bench/data/annotations.parquet")
|
| 92 |
```
|
| 93 |
|
| 94 |
+
## Rebuilding Robot States
|
| 95 |
+
|
| 96 |
+
`scripts/perception_sources.lock.json` pins both annotation maps and all 26
|
| 97 |
+
upstream robot-dataset revisions. Rebuild the enriched table from the original
|
| 98 |
+
annotations Parquet:
|
| 99 |
+
|
| 100 |
+
```bash
|
| 101 |
+
python scripts/embed_perception_states.py \
|
| 102 |
+
data/annotations.original.parquet \
|
| 103 |
+
data/annotations.parquet
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
Requirements are Python 3.11+, `huggingface_hub`, and `pyarrow`. The exporter
|
| 107 |
+
validates episode coverage, frame counts, channel widths, and timestamp order,
|
| 108 |
+
then writes a SHA-256 provenance file next to the enriched Parquet. Hugging Face
|
| 109 |
+
caches all state sources; pass `--cache-dir` to use a shared cache. The DROID
|
| 110 |
+
state data comes from one roughly 241 MB upstream tar archive. The embedded
|
| 111 |
+
state payload adds roughly 1.5 MB before Parquet-level recompression.
|
| 112 |
+
|
| 113 |
## Annotation Policy
|
| 114 |
|
| 115 |
Segments are intended to describe completed manipulation events, not every small pose adjustment. A new segment should generally correspond to a visible state change such as picking up, placing, opening, closing, moving, pouring, wiping, cutting, or transferring an object.
|
data/annotations.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:24c6c23447753385b9cea0d17f17d7a8aa74131d800d9bc9ab74d7669d7404ab
|
| 3 |
+
size 1401440590
|
data/annotations.parquet.provenance.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema_version": 1,
|
| 3 |
+
"artifact": "annotations.parquet",
|
| 4 |
+
"input_sha256": "3b4320b76c1b1fb6150bf2d192343dc62eed39db54a89584b7c6f31f511e73d4",
|
| 5 |
+
"output_sha256": "24c6c23447753385b9cea0d17f17d7a8aa74131d800d9bc9ab74d7669d7404ab",
|
| 6 |
+
"source_lock": "perception_sources.lock.json",
|
| 7 |
+
"source_lock_sha256": "0a7da2033dc2007207c9dc77e5e36172ec01fe2ed2a286501b48e169ce6dce8b",
|
| 8 |
+
"rows": 100,
|
| 9 |
+
"robot_state_rows": 75,
|
| 10 |
+
"video_only_rows": 25,
|
| 11 |
+
"video_only_ids": [
|
| 12 |
+
"homer_1",
|
| 13 |
+
"homer_2",
|
| 14 |
+
"homer_3",
|
| 15 |
+
"homer_4",
|
| 16 |
+
"homer_5",
|
| 17 |
+
"homer_7",
|
| 18 |
+
"homer_9",
|
| 19 |
+
"homer_10",
|
| 20 |
+
"homer_11",
|
| 21 |
+
"homer_12",
|
| 22 |
+
"homer_15",
|
| 23 |
+
"homer_29",
|
| 24 |
+
"homer_33",
|
| 25 |
+
"homer_37",
|
| 26 |
+
"homer_38",
|
| 27 |
+
"homer_39",
|
| 28 |
+
"homer_40",
|
| 29 |
+
"homer_41",
|
| 30 |
+
"homer_48",
|
| 31 |
+
"homer_50",
|
| 32 |
+
"homer_52",
|
| 33 |
+
"homer_53",
|
| 34 |
+
"homer_56",
|
| 35 |
+
"homer_59",
|
| 36 |
+
"homer_60"
|
| 37 |
+
]
|
| 38 |
+
}
|
scripts/embed_perception_states.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import hashlib
|
| 5 |
+
import json
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
from typing import Any
|
| 8 |
+
|
| 9 |
+
import pyarrow as pa
|
| 10 |
+
import pyarrow.parquet as pq
|
| 11 |
+
|
| 12 |
+
from perception_states import (
|
| 13 |
+
LOCK_PATH,
|
| 14 |
+
_load_episode,
|
| 15 |
+
discover_robot_episodes,
|
| 16 |
+
load_source_lock,
|
| 17 |
+
normalize_episode,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def state_type() -> pa.DataType:
|
| 22 |
+
return pa.struct(
|
| 23 |
+
[
|
| 24 |
+
("robot_family", pa.string()),
|
| 25 |
+
("source_dataset", pa.string()),
|
| 26 |
+
("source_revision", pa.string()),
|
| 27 |
+
("source_episode_index", pa.int64()),
|
| 28 |
+
("fps", pa.float64()),
|
| 29 |
+
("num_frames", pa.int64()),
|
| 30 |
+
("frame_index", pa.list_(pa.int64())),
|
| 31 |
+
("timestamp_sec", pa.list_(pa.float64())),
|
| 32 |
+
("primary_channel", pa.string()),
|
| 33 |
+
(
|
| 34 |
+
"channels",
|
| 35 |
+
pa.list_(
|
| 36 |
+
pa.struct(
|
| 37 |
+
[
|
| 38 |
+
("name", pa.string()),
|
| 39 |
+
("value_names", pa.list_(pa.string())),
|
| 40 |
+
("values", pa.list_(pa.list_(pa.float64()))),
|
| 41 |
+
]
|
| 42 |
+
)
|
| 43 |
+
),
|
| 44 |
+
),
|
| 45 |
+
]
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def collect_states(lock_path: Path, cache_dir: Path | None) -> dict[str, dict[str, Any]]:
|
| 50 |
+
lock = load_source_lock(lock_path)
|
| 51 |
+
states: dict[str, dict[str, Any]] = {}
|
| 52 |
+
for episode in discover_robot_episodes(lock, cache_dir):
|
| 53 |
+
table, feature_info = _load_episode(episode, cache_dir)
|
| 54 |
+
row = normalize_episode(table, episode, feature_info)
|
| 55 |
+
bench_id = row.pop("bench_id")
|
| 56 |
+
states[bench_id] = row
|
| 57 |
+
return states
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def embed_perception_states(
|
| 61 |
+
input_path: Path,
|
| 62 |
+
output_path: Path,
|
| 63 |
+
*,
|
| 64 |
+
lock_path: Path = LOCK_PATH,
|
| 65 |
+
cache_dir: Path | None = None,
|
| 66 |
+
) -> dict[str, Any]:
|
| 67 |
+
if input_path.resolve() == output_path.resolve():
|
| 68 |
+
raise ValueError("Input and output paths must differ")
|
| 69 |
+
|
| 70 |
+
states = collect_states(lock_path, cache_dir)
|
| 71 |
+
source = pq.ParquetFile(input_path)
|
| 72 |
+
if "perception_state" in source.schema_arrow.names:
|
| 73 |
+
raise ValueError("Input already contains perception_state")
|
| 74 |
+
if source.metadata.num_rows != 100:
|
| 75 |
+
raise ValueError(f"Expected 100 benchmark rows, found {source.metadata.num_rows}")
|
| 76 |
+
|
| 77 |
+
output_path.parent.mkdir(parents=True, exist_ok=True)
|
| 78 |
+
output_schema = source.schema_arrow.append(pa.field("perception_state", state_type()))
|
| 79 |
+
matched: set[str] = set()
|
| 80 |
+
video_only: list[str] = []
|
| 81 |
+
with pq.ParquetWriter(output_path, output_schema, compression="zstd") as writer:
|
| 82 |
+
for batch in source.iter_batches(batch_size=1):
|
| 83 |
+
table = pa.Table.from_batches([batch])
|
| 84 |
+
bench_id = str(table["id"][0].as_py())
|
| 85 |
+
state = states.get(bench_id)
|
| 86 |
+
if state is None:
|
| 87 |
+
video_only.append(bench_id)
|
| 88 |
+
else:
|
| 89 |
+
matched.add(bench_id)
|
| 90 |
+
enriched = table.append_column(
|
| 91 |
+
"perception_state", pa.array([state], type=state_type())
|
| 92 |
+
)
|
| 93 |
+
writer.write_table(enriched, row_group_size=1)
|
| 94 |
+
|
| 95 |
+
missing = set(states) - matched
|
| 96 |
+
if missing:
|
| 97 |
+
output_path.unlink(missing_ok=True)
|
| 98 |
+
raise ValueError(f"State IDs absent from benchmark: {sorted(missing)}")
|
| 99 |
+
if len(matched) != 75 or len(video_only) != 25:
|
| 100 |
+
output_path.unlink(missing_ok=True)
|
| 101 |
+
raise ValueError(
|
| 102 |
+
f"Expected 75 state rows and 25 video-only rows, got {len(matched)} and {len(video_only)}"
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
provenance = {
|
| 106 |
+
"schema_version": 1,
|
| 107 |
+
"artifact": output_path.name,
|
| 108 |
+
"input_sha256": _sha256(input_path),
|
| 109 |
+
"output_sha256": _sha256(output_path),
|
| 110 |
+
"source_lock": lock_path.name,
|
| 111 |
+
"source_lock_sha256": _sha256(lock_path),
|
| 112 |
+
"rows": source.metadata.num_rows,
|
| 113 |
+
"robot_state_rows": len(matched),
|
| 114 |
+
"video_only_rows": len(video_only),
|
| 115 |
+
"video_only_ids": video_only,
|
| 116 |
+
}
|
| 117 |
+
provenance_path = output_path.with_suffix(output_path.suffix + ".provenance.json")
|
| 118 |
+
provenance_path.write_text(json.dumps(provenance, indent=2) + "\n", encoding="utf-8")
|
| 119 |
+
return provenance
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def _sha256(path: Path) -> str:
|
| 123 |
+
digest = hashlib.sha256()
|
| 124 |
+
with path.open("rb") as handle:
|
| 125 |
+
for chunk in iter(lambda: handle.read(8 * 1024 * 1024), b""):
|
| 126 |
+
digest.update(chunk)
|
| 127 |
+
return digest.hexdigest()
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def main() -> None:
|
| 131 |
+
parser = argparse.ArgumentParser(
|
| 132 |
+
description="Embed pinned robot proprioception into existing WGO-Bench rows."
|
| 133 |
+
)
|
| 134 |
+
parser.add_argument("input", type=Path)
|
| 135 |
+
parser.add_argument("output", type=Path)
|
| 136 |
+
parser.add_argument("--lock", type=Path, default=LOCK_PATH)
|
| 137 |
+
parser.add_argument("--cache-dir", type=Path)
|
| 138 |
+
args = parser.parse_args()
|
| 139 |
+
result = embed_perception_states(
|
| 140 |
+
args.input,
|
| 141 |
+
args.output,
|
| 142 |
+
lock_path=args.lock,
|
| 143 |
+
cache_dir=args.cache_dir,
|
| 144 |
+
)
|
| 145 |
+
print(json.dumps(result, indent=2))
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
if __name__ == "__main__":
|
| 149 |
+
main()
|
scripts/perception_sources.lock.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema_version": 1,
|
| 3 |
+
"coverage": {
|
| 4 |
+
"benchmark_episodes": 100,
|
| 5 |
+
"robot_episodes": 75,
|
| 6 |
+
"video_only_episodes": 25,
|
| 7 |
+
"video_only_subset": "HomER"
|
| 8 |
+
},
|
| 9 |
+
"annotation_sources": {
|
| 10 |
+
"droid": {
|
| 11 |
+
"repo_id": "macrodata/robointer-droid-50-subtask-annotations",
|
| 12 |
+
"revision": "39342b5e3a7603748d97fbfe25aa0e54e6b45326",
|
| 13 |
+
"parquet_path": "data/annotations.parquet"
|
| 14 |
+
},
|
| 15 |
+
"galaxea": {
|
| 16 |
+
"repo_id": "macrodata/robocoin-galaxea-head-25-subtask-annotations",
|
| 17 |
+
"revision": "e974f9bd6c6cb46289fd54586c10385f43f0ec6e",
|
| 18 |
+
"parquet_path": "data/annotations.parquet"
|
| 19 |
+
}
|
| 20 |
+
},
|
| 21 |
+
"upstream_revisions": {
|
| 22 |
+
"InternRobotics/RoboInter-Data": "0208b79c34eca4d214cdb5d07f5ae0f7cc634340",
|
| 23 |
+
"RoboCOIN/Galaxea_R1_Lite_change_baai_into_brain": "98393798142b2b99a386d9bbc8ca9a6a8cdd5d5c",
|
| 24 |
+
"RoboCOIN/Galaxea_R1_Lite_classify_object_four": "1b8fbd8d24b9ca70476b2945e8bd61b8a3ab2ad2",
|
| 25 |
+
"RoboCOIN/Galaxea_R1_Lite_classify_object_green_tablecloth": "e99edefc3df9f0864d1cadc81af60e916b8dcf74",
|
| 26 |
+
"RoboCOIN/Galaxea_R1_Lite_classify_object_six": "ffcb9eba5977763d6bc0ddfca6f99e4213d42ad4",
|
| 27 |
+
"RoboCOIN/Galaxea_R1_Lite_classify_object_three": "cd40bb70b6d943c644f643fbe9fabefedee24e69",
|
| 28 |
+
"RoboCOIN/Galaxea_R1_Lite_mix_color_small_test_tube": "03649ca80d0349b7369f0ed2b3c225eb3959d35d",
|
| 29 |
+
"RoboCOIN/Galaxea_R1_Lite_mix_red_blue_left_large_test_tube": "6257a59fc9b74059295460f8c00cba3d21bcfe74",
|
| 30 |
+
"RoboCOIN/Galaxea_R1_Lite_mix_red_yellow_large_test_tube": "a7eae049447f13ecf936305460feabb120b033bb",
|
| 31 |
+
"RoboCOIN/Galaxea_R1_Lite_mix_red_yellow_left_large_test_tube": "f32383071e90569802df0ac52de690d4908c4e64",
|
| 32 |
+
"RoboCOIN/Galaxea_R1_Lite_mix_red_yellow_right": "696a2d3a867ccc3a7cef7eb0d12924b8737ee297",
|
| 33 |
+
"RoboCOIN/Galaxea_R1_Lite_move_mouse": "cc841d0478cb2b95ea41396b93b17310f74d341c",
|
| 34 |
+
"RoboCOIN/Galaxea_R1_Lite_pour_liquid_mrable_bar_counter": "879dcddeccf12315577791bfff24f585eb2efdda",
|
| 35 |
+
"RoboCOIN/Galaxea_R1_Lite_pour_powder_marble_bar_counter": "e76ae5ae555f30b2cf79e4fec049c1101ec81c14",
|
| 36 |
+
"RoboCOIN/Galaxea_R1_Lite_pour_solid": "5e856053cd65e3c383cbb3c96a4ace230399073b",
|
| 37 |
+
"RoboCOIN/Galaxea_R1_Lite_pour_solid_marble_bar_counter": "28958bd97ad782a850d3282b3a7535ce9809fbed",
|
| 38 |
+
"RoboCOIN/Galaxea_R1_Lite_pour_water_black_tablecloth": "e67c5774c4b961393ade0769ec8072e7cab76f8d",
|
| 39 |
+
"RoboCOIN/Galaxea_R1_Lite_storage_object_brown_bowl": "d518e4efd84024e20a8108ec40ab668c47e6b277",
|
| 40 |
+
"RoboCOIN/Galaxea_R1_Lite_storage_object_brown_plate": "4acca05909f7d52845c0569bf699b77de30b820a",
|
| 41 |
+
"RoboCOIN/Galaxea_R1_Lite_storage_object_dish": "39525f063a9b1b158f8b7152be76b3d6cad1935d",
|
| 42 |
+
"RoboCOIN/Galaxea_R1_Lite_storage_object_gray_plate": "88bd99242337b756f1ebb9ccb4d363731abf8576",
|
| 43 |
+
"RoboCOIN/Galaxea_R1_Lite_storage_object_pink_bowl": "eaad5ed3a6087907d2d64495b437ff7911314b51",
|
| 44 |
+
"RoboCOIN/Galaxea_R1_Lite_storage_object_white_box": "817a191f19f6c9bdc64f620869d10b7343f240d0",
|
| 45 |
+
"RoboCOIN/Galaxea_R1_Lite_storage_object_yellow_basket": "d12c143bf81dd56a535ef5e2483c50712463cae5",
|
| 46 |
+
"RoboCOIN/Galaxea_R1_Lite_toggle_drawer_red": "bd2fb11362203299f0b95aa07e33975e3141cd04",
|
| 47 |
+
"RoboCOIN/Galaxea_R1_Lite_toggle_drawer_yellow": "1676795e4c0bb4ce786243a6711a1b3dc4f7346f"
|
| 48 |
+
}
|
| 49 |
+
}
|
scripts/perception_states.py
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import hashlib
|
| 5 |
+
import io
|
| 6 |
+
import json
|
| 7 |
+
import tarfile
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
from typing import Any, Iterable
|
| 10 |
+
|
| 11 |
+
import pyarrow as pa
|
| 12 |
+
import pyarrow.parquet as pq
|
| 13 |
+
from huggingface_hub import hf_hub_download
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
LOCK_PATH = Path(__file__).with_name("perception_sources.lock.json")
|
| 17 |
+
PRIMARY_STATE_COLUMNS = ("observation.state", "state")
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def load_source_lock(path: Path = LOCK_PATH) -> dict[str, Any]:
|
| 21 |
+
lock = json.loads(path.read_text(encoding="utf-8"))
|
| 22 |
+
if lock.get("schema_version") != 1:
|
| 23 |
+
raise ValueError(f"Unsupported perception-source lock schema: {lock.get('schema_version')!r}")
|
| 24 |
+
return lock
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def discover_robot_episodes(lock: dict[str, Any], cache_dir: Path | None = None) -> list[dict[str, Any]]:
|
| 28 |
+
episodes: list[dict[str, Any]] = []
|
| 29 |
+
for source_name, source in lock["annotation_sources"].items():
|
| 30 |
+
parquet_path = _download(
|
| 31 |
+
source["repo_id"], source["revision"], source["parquet_path"], cache_dir
|
| 32 |
+
)
|
| 33 |
+
for row in pq.read_table(parquet_path).to_pylist():
|
| 34 |
+
if source_name == "droid":
|
| 35 |
+
repo_id = row["source_dataset"]
|
| 36 |
+
episode_index = int(row["episode_index"])
|
| 37 |
+
episodes.append(
|
| 38 |
+
{
|
| 39 |
+
"bench_id": row["bench_id"],
|
| 40 |
+
"robot_family": "droid",
|
| 41 |
+
"repo_id": repo_id,
|
| 42 |
+
"revision": lock["upstream_revisions"][repo_id],
|
| 43 |
+
"episode_index": episode_index,
|
| 44 |
+
"fps": float(row["fps"]),
|
| 45 |
+
"expected_num_frames": int(row["num_frames"]),
|
| 46 |
+
"source_subset": row["source_subset"],
|
| 47 |
+
"data_path": f"{row['source_subset']}/data/chunk-000.tar",
|
| 48 |
+
"tar_member": f"chunk-000/episode_{episode_index:06d}.parquet",
|
| 49 |
+
"info_path": f"{row['source_subset']}/meta/info.json",
|
| 50 |
+
}
|
| 51 |
+
)
|
| 52 |
+
elif source_name == "galaxea":
|
| 53 |
+
repo_id = row["source_dataset"]
|
| 54 |
+
episode_index = int(row["source_episode_index"])
|
| 55 |
+
episodes.append(
|
| 56 |
+
{
|
| 57 |
+
"bench_id": row["bench_id"],
|
| 58 |
+
"robot_family": "galaxea",
|
| 59 |
+
"repo_id": repo_id,
|
| 60 |
+
"revision": lock["upstream_revisions"][repo_id],
|
| 61 |
+
"episode_index": episode_index,
|
| 62 |
+
"fps": float(row["fps"]),
|
| 63 |
+
"expected_num_frames": int(row["num_frames"]),
|
| 64 |
+
"data_path": f"data/chunk-000/episode_{episode_index:06d}.parquet",
|
| 65 |
+
"info_path": "meta/info.json",
|
| 66 |
+
}
|
| 67 |
+
)
|
| 68 |
+
else:
|
| 69 |
+
raise ValueError(f"Unknown annotation source {source_name!r}")
|
| 70 |
+
|
| 71 |
+
episodes.sort(key=lambda item: item["bench_id"])
|
| 72 |
+
bench_ids = [item["bench_id"] for item in episodes]
|
| 73 |
+
if len(bench_ids) != len(set(bench_ids)):
|
| 74 |
+
raise ValueError("Duplicate bench_id in robotic source mappings")
|
| 75 |
+
expected = int(lock["coverage"]["robot_episodes"])
|
| 76 |
+
if len(episodes) != expected:
|
| 77 |
+
raise ValueError(f"Expected {expected} robotic episodes, found {len(episodes)}")
|
| 78 |
+
return episodes
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def normalize_episode(
|
| 82 |
+
table: pa.Table,
|
| 83 |
+
episode: dict[str, Any],
|
| 84 |
+
feature_info: dict[str, Any],
|
| 85 |
+
) -> dict[str, Any]:
|
| 86 |
+
columns = set(table.column_names)
|
| 87 |
+
primary = next((name for name in PRIMARY_STATE_COLUMNS if name in columns), None)
|
| 88 |
+
if primary is None:
|
| 89 |
+
raise ValueError(f"{episode['bench_id']} has no supported proprioception column")
|
| 90 |
+
if "frame_index" not in columns or "timestamp" not in columns:
|
| 91 |
+
raise ValueError(f"{episode['bench_id']} is missing frame_index or timestamp")
|
| 92 |
+
|
| 93 |
+
frame_index = [int(_scalar(value)) for value in table["frame_index"].to_pylist()]
|
| 94 |
+
timestamps = [float(_scalar(value)) for value in table["timestamp"].to_pylist()]
|
| 95 |
+
if frame_index != sorted(frame_index) or timestamps != sorted(timestamps):
|
| 96 |
+
raise ValueError(f"{episode['bench_id']} state rows are not ordered")
|
| 97 |
+
if len(frame_index) != episode["expected_num_frames"]:
|
| 98 |
+
raise ValueError(
|
| 99 |
+
f"{episode['bench_id']} expected {episode['expected_num_frames']} frames, "
|
| 100 |
+
f"found {len(frame_index)} state rows"
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
channel_names = [primary]
|
| 104 |
+
channel_names.extend(
|
| 105 |
+
sorted(name for name in columns if name.endswith("_state") and name != primary)
|
| 106 |
+
)
|
| 107 |
+
channels = []
|
| 108 |
+
for name in channel_names:
|
| 109 |
+
values = [_vector(value) for value in table[name].to_pylist()]
|
| 110 |
+
names = list((feature_info.get(name) or {}).get("names") or [])
|
| 111 |
+
width = len(values[0]) if values else 0
|
| 112 |
+
if any(len(value) != width for value in values):
|
| 113 |
+
raise ValueError(f"{episode['bench_id']} channel {name!r} changes width")
|
| 114 |
+
if names and len(names) != width:
|
| 115 |
+
raise ValueError(f"{episode['bench_id']} channel {name!r} names do not match width")
|
| 116 |
+
if not names:
|
| 117 |
+
names = [f"value_{index}" for index in range(width)]
|
| 118 |
+
channels.append({"name": name, "value_names": names, "values": values})
|
| 119 |
+
|
| 120 |
+
return {
|
| 121 |
+
"bench_id": episode["bench_id"],
|
| 122 |
+
"robot_family": episode["robot_family"],
|
| 123 |
+
"source_dataset": episode["repo_id"],
|
| 124 |
+
"source_revision": episode["revision"],
|
| 125 |
+
"source_episode_index": episode["episode_index"],
|
| 126 |
+
"fps": episode["fps"],
|
| 127 |
+
"num_frames": len(frame_index),
|
| 128 |
+
"frame_index": frame_index,
|
| 129 |
+
"timestamp_sec": timestamps,
|
| 130 |
+
"primary_channel": primary,
|
| 131 |
+
"channels": channels,
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def export_perception_states(
|
| 136 |
+
output_path: Path,
|
| 137 |
+
*,
|
| 138 |
+
lock_path: Path = LOCK_PATH,
|
| 139 |
+
cache_dir: Path | None = None,
|
| 140 |
+
bench_ids: Iterable[str] | None = None,
|
| 141 |
+
) -> dict[str, Any]:
|
| 142 |
+
lock = load_source_lock(lock_path)
|
| 143 |
+
episodes = discover_robot_episodes(lock, cache_dir)
|
| 144 |
+
selected = set(bench_ids or [])
|
| 145 |
+
if selected:
|
| 146 |
+
known = {episode["bench_id"] for episode in episodes}
|
| 147 |
+
unknown = selected - known
|
| 148 |
+
if unknown:
|
| 149 |
+
raise ValueError(f"Unknown robotic bench IDs: {sorted(unknown)}")
|
| 150 |
+
episodes = [episode for episode in episodes if episode["bench_id"] in selected]
|
| 151 |
+
|
| 152 |
+
rows = []
|
| 153 |
+
for episode in episodes:
|
| 154 |
+
table, feature_info = _load_episode(episode, cache_dir)
|
| 155 |
+
rows.append(normalize_episode(table, episode, feature_info))
|
| 156 |
+
|
| 157 |
+
output_path.parent.mkdir(parents=True, exist_ok=True)
|
| 158 |
+
table = pa.Table.from_pylist(rows, schema=perception_schema())
|
| 159 |
+
pq.write_table(table, output_path, compression="zstd")
|
| 160 |
+
digest = hashlib.sha256(output_path.read_bytes()).hexdigest()
|
| 161 |
+
provenance = {
|
| 162 |
+
"schema_version": 1,
|
| 163 |
+
"artifact": output_path.name,
|
| 164 |
+
"sha256": digest,
|
| 165 |
+
"episodes": len(rows),
|
| 166 |
+
"bench_ids": [row["bench_id"] for row in rows],
|
| 167 |
+
"source_lock": lock_path.name,
|
| 168 |
+
"source_lock_sha256": hashlib.sha256(lock_path.read_bytes()).hexdigest(),
|
| 169 |
+
"video_only_episodes": lock["coverage"]["video_only_episodes"],
|
| 170 |
+
}
|
| 171 |
+
provenance_path = output_path.with_suffix(output_path.suffix + ".provenance.json")
|
| 172 |
+
provenance_path.write_text(json.dumps(provenance, indent=2) + "\n", encoding="utf-8")
|
| 173 |
+
return provenance
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def perception_schema() -> pa.Schema:
|
| 177 |
+
return pa.schema(
|
| 178 |
+
[
|
| 179 |
+
("bench_id", pa.string()),
|
| 180 |
+
("robot_family", pa.string()),
|
| 181 |
+
("source_dataset", pa.string()),
|
| 182 |
+
("source_revision", pa.string()),
|
| 183 |
+
("source_episode_index", pa.int64()),
|
| 184 |
+
("fps", pa.float64()),
|
| 185 |
+
("num_frames", pa.int64()),
|
| 186 |
+
("frame_index", pa.list_(pa.int64())),
|
| 187 |
+
("timestamp_sec", pa.list_(pa.float64())),
|
| 188 |
+
("primary_channel", pa.string()),
|
| 189 |
+
(
|
| 190 |
+
"channels",
|
| 191 |
+
pa.list_(
|
| 192 |
+
pa.struct(
|
| 193 |
+
[
|
| 194 |
+
("name", pa.string()),
|
| 195 |
+
("value_names", pa.list_(pa.string())),
|
| 196 |
+
("values", pa.list_(pa.list_(pa.float64()))),
|
| 197 |
+
]
|
| 198 |
+
)
|
| 199 |
+
),
|
| 200 |
+
),
|
| 201 |
+
]
|
| 202 |
+
)
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def _load_episode(episode: dict[str, Any], cache_dir: Path | None) -> tuple[pa.Table, dict[str, Any]]:
|
| 206 |
+
info_path = _download(
|
| 207 |
+
episode["repo_id"], episode["revision"], episode["info_path"], cache_dir
|
| 208 |
+
)
|
| 209 |
+
feature_info = json.loads(info_path.read_text(encoding="utf-8")).get("features", {})
|
| 210 |
+
data_path = _download(
|
| 211 |
+
episode["repo_id"], episode["revision"], episode["data_path"], cache_dir
|
| 212 |
+
)
|
| 213 |
+
if episode.get("tar_member"):
|
| 214 |
+
with tarfile.open(data_path) as archive:
|
| 215 |
+
member = archive.extractfile(episode["tar_member"])
|
| 216 |
+
if member is None:
|
| 217 |
+
raise FileNotFoundError(episode["tar_member"])
|
| 218 |
+
table = pq.read_table(io.BytesIO(member.read()))
|
| 219 |
+
else:
|
| 220 |
+
table = pq.read_table(data_path)
|
| 221 |
+
return table, feature_info
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def _download(repo_id: str, revision: str, filename: str, cache_dir: Path | None) -> Path:
|
| 225 |
+
return Path(
|
| 226 |
+
hf_hub_download(
|
| 227 |
+
repo_id=repo_id,
|
| 228 |
+
repo_type="dataset",
|
| 229 |
+
revision=revision,
|
| 230 |
+
filename=filename,
|
| 231 |
+
cache_dir=str(cache_dir) if cache_dir else None,
|
| 232 |
+
)
|
| 233 |
+
)
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def _scalar(value: Any) -> Any:
|
| 237 |
+
if isinstance(value, (list, tuple)):
|
| 238 |
+
if len(value) != 1:
|
| 239 |
+
raise ValueError(f"Expected a scalar or one-element sequence, got {value!r}")
|
| 240 |
+
return value[0]
|
| 241 |
+
return value
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
def _vector(value: Any) -> list[float]:
|
| 245 |
+
if value is None:
|
| 246 |
+
return []
|
| 247 |
+
if not isinstance(value, (list, tuple)):
|
| 248 |
+
value = [value]
|
| 249 |
+
return [float(item) for item in value]
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
def main() -> None:
|
| 253 |
+
parser = argparse.ArgumentParser(
|
| 254 |
+
description="Export pinned proprioception sidecars for WGO-Bench robotic episodes."
|
| 255 |
+
)
|
| 256 |
+
parser.add_argument("output", type=Path)
|
| 257 |
+
parser.add_argument("--lock", type=Path, default=LOCK_PATH)
|
| 258 |
+
parser.add_argument("--cache-dir", type=Path)
|
| 259 |
+
parser.add_argument("--bench-id", action="append", default=[])
|
| 260 |
+
args = parser.parse_args()
|
| 261 |
+
result = export_perception_states(
|
| 262 |
+
args.output,
|
| 263 |
+
lock_path=args.lock,
|
| 264 |
+
cache_dir=args.cache_dir,
|
| 265 |
+
bench_ids=args.bench_id,
|
| 266 |
+
)
|
| 267 |
+
print(json.dumps(result, indent=2))
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
if __name__ == "__main__":
|
| 271 |
+
main()
|