Download examples/inspect_episode.py from tower-benchmark/TOWER-SimData: direct link, hf CLI and curl.
- Browser
- Download file 3.14 kB
-
https://huggingface.co/datasets/tower-benchmark/TOWER-SimData/resolve/refs%2Fpr%2F2/examples/inspect_episode.py
- Command line
-
hf download hf://datasets/tower-benchmark/TOWER-SimData@refs/pr/2/examples/inspect_episode.py
-
curl -L -o inspect_episode.py https://huggingface.co/datasets/tower-benchmark/TOWER-SimData/resolve/refs%2Fpr%2F2/examples/inspect_episode.py
3.14 kB
| """Inspect a v9 raw episode; does not construct aligned training targets.""" | |
| import argparse | |
| import io | |
| import json | |
| import h5py | |
| import numpy as np | |
| from PIL import Image | |
| def inspect(path): | |
| with h5py.File(path, "r") as episode: | |
| times = episode["sim/time"][:] | |
| if times.ndim != 1 or len(times) == 0: | |
| raise ValueError("Expected a nonempty sim/time vector") | |
| if not np.isfinite(times).all() or not np.all(np.diff(times) > 0): | |
| raise ValueError("sim/time must be finite and strictly increasing") | |
| count = len(times) | |
| fields = {} | |
| for key, width in [("observations/qpos", 16), ("leader/qpos", 16), | |
| ("observations/eef", 14), ("leader/eef", 14), | |
| ("lifter/action_mm", 2)]: | |
| dataset = episode[key] | |
| if dataset.shape != (count, width): | |
| raise ValueError(f"Unexpected shape for {key}: {dataset.shape}") | |
| if not np.isfinite(dataset[:]).all(): | |
| raise ValueError(f"Nonfinite values in {key}") | |
| fields[key] = { | |
| "shape": list(dataset.shape), | |
| "dtype": str(dataset.dtype), | |
| "attributes": {k: str(v) for k, v in dataset.attrs.items()}, | |
| } | |
| cameras = {} | |
| for camera in ["right_front_camera", "left_back_camera", | |
| "left_wrist_camera", "back_wrist_camera"]: | |
| frames = episode[f"observations/images/{camera}"] | |
| if frames.shape != (count,): | |
| raise ValueError(f"Camera length mismatch: {camera}") | |
| samples = [] | |
| for index in sorted({0, count // 2, count - 1}): | |
| payload = frames[index] | |
| blob = payload.tobytes() if hasattr(payload, "tobytes") else payload | |
| with Image.open(io.BytesIO(blob)) as image: | |
| image.load() | |
| samples.append({"frame": index, "size": list(image.size)}) | |
| cameras[camera] = samples | |
| timing = {} | |
| for key in ["physical/issued_command/tick", "physical/applied_command/tick"]: | |
| if key in episode: | |
| data = episode[key] | |
| timing[key] = {"shape": list(data.shape), | |
| "first": int(data[0]), "last": int(data[-1])} | |
| return { | |
| "frames": count, | |
| "sim_time_first_last": [float(times[0]), float(times[-1])], | |
| "metadata": {k: str(episode.attrs[k]) for k in | |
| ["schema_version", "fps", "physics_hz", "command_hz", | |
| "extra_command_delay_ms", "task_success", "timestamp_clock"] | |
| if k in episode.attrs}, | |
| "fields": fields, "sampled_images": cameras, "command_ticks": timing, | |
| "scope": "Raw inspection only; no action alignment, posture or success certification.", | |
| } | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("episode", help="Local HDF5 episode path") | |
| print(json.dumps(inspect(parser.parse_args().episode), indent=2)) | |