Datasets:
Initial upload: 100 controlled bimodal demos (50 LEFT + 50 RIGHT)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- README.md +135 -0
- demo_pusht.py +258 -0
- pusht_controlled_mixed.zarr/.zgroup +3 -0
- pusht_controlled_mixed.zarr/data/.zgroup +3 -0
- pusht_controlled_mixed.zarr/data/action/.zarray +23 -0
- pusht_controlled_mixed.zarr/data/action/0.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/1.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/10.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/11.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/12.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/13.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/14.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/15.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/16.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/17.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/18.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/19.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/2.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/20.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/21.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/22.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/23.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/24.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/25.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/26.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/27.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/28.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/29.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/3.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/30.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/31.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/32.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/33.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/34.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/35.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/36.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/37.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/38.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/39.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/4.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/40.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/41.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/42.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/43.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/44.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/45.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/46.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/47.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/48.0 +0 -0
- pusht_controlled_mixed.zarr/data/action/49.0 +0 -0
README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
task_categories:
|
| 4 |
+
- robotics
|
| 5 |
+
tags:
|
| 6 |
+
- behavior-cloning
|
| 7 |
+
- diffusion-policy
|
| 8 |
+
- pusht
|
| 9 |
+
- bimodal
|
| 10 |
+
- mode-editing
|
| 11 |
+
size_categories:
|
| 12 |
+
- n<1K
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# Push-T Controlled Bimodal Teleop Dataset
|
| 16 |
+
|
| 17 |
+
100 human-teleoperated Push-T demonstrations (50 LEFT-wrap + 50 RIGHT-wrap), collected
|
| 18 |
+
under a **controlled fixed initial state** so the two modes have kinematically equivalent
|
| 19 |
+
costs. Intended for downstream bimodal behavior-cloning and mode-editing experiments.
|
| 20 |
+
|
| 21 |
+
All demos reach `coverage >= 0.95` shapely-IoU success threshold (env-defined). Demos
|
| 22 |
+
were collected at 10 Hz mouse-driven teleop on the 2D pygame Push-T env from the
|
| 23 |
+
Diffusion Policy paper (Chi et al., RSS 2023).
|
| 24 |
+
|
| 25 |
+
## What "LEFT" vs "RIGHT" means
|
| 26 |
+
|
| 27 |
+
T starts at lower-left `(185, 327, π/4)` and must translate up-right to the green goal
|
| 28 |
+
silhouette at `(256, 256, π/4)`. The agent (blue circle) spawns upper-right of the T
|
| 29 |
+
at `(327, 185) ± 15 px`. Two equal-cost wrap paths exist:
|
| 30 |
+
|
| 31 |
+
- **LEFT** — agent wraps the **upper-left** side of the T (counter-clockwise about T's center)
|
| 32 |
+
- **RIGHT** — agent wraps the **lower-right** side of the T (clockwise about T's center)
|
| 33 |
+
|
| 34 |
+
Modes alternate by seed parity: even seed → LEFT, odd seed → RIGHT.
|
| 35 |
+
|
| 36 |
+

|
| 37 |
+
|
| 38 |
+
## Files
|
| 39 |
+
|
| 40 |
+
| File | Purpose |
|
| 41 |
+
|------|---------|
|
| 42 |
+
| `pusht_controlled_mixed.zarr/` | The dataset (zarr v2 directory store, 100 episodes / 8060 steps) |
|
| 43 |
+
| `pusht_controlled_mixed_paths.png` | All 100 agent paths, split by mode (visual sanity check) |
|
| 44 |
+
| `demo_pusht.py` | The patched collection script used to generate this dataset |
|
| 45 |
+
|
| 46 |
+
## Zarr layout
|
| 47 |
+
|
| 48 |
+
```
|
| 49 |
+
pusht_controlled_mixed.zarr/
|
| 50 |
+
├── data/ # 8060 timesteps total, 10 Hz
|
| 51 |
+
│ ├── state (8060, 5) float32 # [agent_x, agent_y, T_x, T_y, T_angle]
|
| 52 |
+
│ ├── action (8060, 2) float32 # teleop mouse-target action
|
| 53 |
+
│ ├── img (8060, 96, 96, 3) uint8 # 96×96 RGB env render
|
| 54 |
+
│ ├── keypoint (8060, 9, 2) float32 # 9 T-block keypoints
|
| 55 |
+
│ └── n_contacts (8060, 1) float32
|
| 56 |
+
└── meta/ # 100 episodes
|
| 57 |
+
├── episode_ends (100,) int64 # cumulative end-indices (DP standard)
|
| 58 |
+
├── episode_modes (100,) int8 # 0 = LEFT, 1 = RIGHT ← extra
|
| 59 |
+
└── episode_coverages (100,) float32 # final IoU coverage ← extra
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
The `data/*` arrays and `meta/episode_ends` follow the **same layout** as the canonical
|
| 63 |
+
`pusht_cchi_v7_replay.zarr` from the DP repo. The two extra `meta/*` arrays are
|
| 64 |
+
additions for mode-editing work; the original DP training code ignores them.
|
| 65 |
+
|
| 66 |
+
## Loading
|
| 67 |
+
|
| 68 |
+
```python
|
| 69 |
+
import zarr, numpy as np
|
| 70 |
+
from huggingface_hub import snapshot_download
|
| 71 |
+
|
| 72 |
+
local_dir = snapshot_download(
|
| 73 |
+
repo_id='haohw/pusht-controlled-mixed',
|
| 74 |
+
repo_type='dataset',
|
| 75 |
+
)
|
| 76 |
+
r = zarr.open(f'{local_dir}/pusht_controlled_mixed.zarr', mode='r')
|
| 77 |
+
|
| 78 |
+
ends = np.asarray(r['meta/episode_ends'])
|
| 79 |
+
modes = np.asarray(r['meta/episode_modes']) # 0=LEFT, 1=RIGHT
|
| 80 |
+
covs = np.asarray(r['meta/episode_coverages'])
|
| 81 |
+
state = np.asarray(r['data/state'])
|
| 82 |
+
action = np.asarray(r['data/action'])
|
| 83 |
+
|
| 84 |
+
# Per-episode iteration
|
| 85 |
+
starts = np.concatenate([[0], ends[:-1]])
|
| 86 |
+
for s, e, m in zip(starts, ends, modes):
|
| 87 |
+
ep_state = state[s:e]
|
| 88 |
+
ep_action = action[s:e]
|
| 89 |
+
mode_name = 'LEFT' if m == 0 else 'RIGHT'
|
| 90 |
+
...
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
For fast pulls on a cluster, set `HF_HUB_ENABLE_HF_TRANSFER=1` and install `hf_transfer`.
|
| 94 |
+
|
| 95 |
+
## Splitting into per-mode zarrs
|
| 96 |
+
|
| 97 |
+
If downstream code expects two single-mode zarr files
|
| 98 |
+
(`pusht_controlled_left.zarr` + `pusht_controlled_right.zarr`), the split is just a
|
| 99 |
+
filter on `meta/episode_modes`. The original DP collection guide's two-file format
|
| 100 |
+
can be reconstructed from this single mixed file at training time.
|
| 101 |
+
|
| 102 |
+
## Collection spec
|
| 103 |
+
|
| 104 |
+
**Env**: `PushTKeypointsEnv` from `diffusion_policy.env.pusht.pusht_keypoints_env`,
|
| 105 |
+
render_size=96, control_hz=10.
|
| 106 |
+
|
| 107 |
+
**Per-episode init** (overrides env's random init via `env.reset_to_state`):
|
| 108 |
+
|
| 109 |
+
| Object | Position | Angle |
|
| 110 |
+
|--------|----------|-------|
|
| 111 |
+
| T block | fixed `(185, 327)` | fixed `π/4` |
|
| 112 |
+
| Goal | fixed `(256, 256)` (env default) | fixed `π/4` |
|
| 113 |
+
| Agent | `(327, 185) + uniform(-15, +15)` (seeded by episode index) | — |
|
| 114 |
+
|
| 115 |
+
**Success**: shapely-IoU between current T polygon and goal T polygon `>= 0.95`.
|
| 116 |
+
DP paper reports continuous max-coverage per episode (clipped at 0.95), not binary
|
| 117 |
+
success rate — so 95% is the env's done flag, not the eval metric.
|
| 118 |
+
|
| 119 |
+
## Episode-length stats
|
| 120 |
+
|
| 121 |
+
Mean 80.6 steps (≈8.1 s @ 10 Hz), median 78, min 60, max 141.
|
| 122 |
+
|
| 123 |
+
## Reproducing
|
| 124 |
+
|
| 125 |
+
See `demo_pusht.py`. Key changes from the stock DP script:
|
| 126 |
+
|
| 127 |
+
1. Controlled init via `env.reset_to_state` (T fixed, agent perturbed ±15 px)
|
| 128 |
+
2. Mode auto-assigned by seed parity, displayed in-window (red/blue overlay + IoU bar)
|
| 129 |
+
3. Extra `meta/episode_modes` and `meta/episode_coverages` saved per episode
|
| 130 |
+
4. `S` key to save partial demos before 95%, `C` key to cancel and restart same seed
|
| 131 |
+
|
| 132 |
+
## License
|
| 133 |
+
|
| 134 |
+
MIT. Re-uses geometry / env from
|
| 135 |
+
[real-stanford/diffusion_policy](https://github.com/real-stanford/diffusion_policy).
|
demo_pusht.py
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import click
|
| 3 |
+
import zarr
|
| 4 |
+
from diffusion_policy.common.replay_buffer import ReplayBuffer
|
| 5 |
+
from diffusion_policy.env.pusht.pusht_keypoints_env import PushTKeypointsEnv
|
| 6 |
+
import pygame
|
| 7 |
+
|
| 8 |
+
# --- Mixed-mode controlled collection ---
|
| 9 |
+
# Seed parity determines mode: even = LEFT, odd = RIGHT.
|
| 10 |
+
# After each saved episode, the integer mode (0=LEFT, 1=RIGHT) and the final
|
| 11 |
+
# coverage are appended to meta/episode_modes and meta/episode_coverages in
|
| 12 |
+
# the zarr, alongside the standard meta/episode_ends.
|
| 13 |
+
MODE_NAMES = {0: 'LEFT', 1: 'RIGHT'}
|
| 14 |
+
MODE_COLORS = {0: (220, 30, 30), 1: (30, 80, 220)} # red for LEFT, blue for RIGHT
|
| 15 |
+
SUCCESS_THRESHOLD = 0.95 # matches PushTEnv.success_threshold
|
| 16 |
+
|
| 17 |
+
_FONT_CACHE = {}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _font(size, bold=False):
|
| 21 |
+
key = (size, bold)
|
| 22 |
+
if key not in _FONT_CACHE:
|
| 23 |
+
if not pygame.font.get_init():
|
| 24 |
+
pygame.font.init()
|
| 25 |
+
_FONT_CACHE[key] = pygame.font.SysFont(None, size, bold=bold)
|
| 26 |
+
return _FONT_CACHE[key]
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def draw_overlay(mode_int, seed, coverage):
|
| 30 |
+
"""Blit mode label + live coverage bar over the env render and flip."""
|
| 31 |
+
screen = pygame.display.get_surface()
|
| 32 |
+
if screen is None:
|
| 33 |
+
return
|
| 34 |
+
w = screen.get_width()
|
| 35 |
+
color = MODE_COLORS[mode_int]
|
| 36 |
+
name = MODE_NAMES[mode_int]
|
| 37 |
+
pad = 6
|
| 38 |
+
|
| 39 |
+
# Mode label: large text top-left with translucent backdrop
|
| 40 |
+
mode_font = _font(56, bold=True)
|
| 41 |
+
mode_surf = mode_font.render(name, True, color)
|
| 42 |
+
mode_rect = mode_surf.get_rect(topleft=(10, 6))
|
| 43 |
+
bg = pygame.Surface((mode_rect.width + pad * 2, mode_rect.height + pad * 2),
|
| 44 |
+
pygame.SRCALPHA)
|
| 45 |
+
bg.fill((255, 255, 255, 200))
|
| 46 |
+
screen.blit(bg, (mode_rect.x - pad, mode_rect.y - pad))
|
| 47 |
+
screen.blit(mode_surf, mode_rect)
|
| 48 |
+
|
| 49 |
+
# Seed number under the mode label
|
| 50 |
+
seed_font = _font(20)
|
| 51 |
+
seed_surf = seed_font.render(f'seed {seed}', True, (40, 40, 40))
|
| 52 |
+
seed_rect = seed_surf.get_rect(topleft=(10, mode_rect.bottom + 4))
|
| 53 |
+
sbg = pygame.Surface((seed_rect.width + pad * 2, seed_rect.height + pad),
|
| 54 |
+
pygame.SRCALPHA)
|
| 55 |
+
sbg.fill((255, 255, 255, 180))
|
| 56 |
+
screen.blit(sbg, (seed_rect.x - pad, seed_rect.y - pad // 2))
|
| 57 |
+
screen.blit(seed_surf, seed_rect)
|
| 58 |
+
|
| 59 |
+
# Coverage bar across the top-right: shows current IoU coverage out of 95%
|
| 60 |
+
bar_w = 200
|
| 61 |
+
bar_h = 18
|
| 62 |
+
bar_x = w - bar_w - 10
|
| 63 |
+
bar_y = 12
|
| 64 |
+
pygame.draw.rect(screen, (255, 255, 255), (bar_x, bar_y, bar_w, bar_h))
|
| 65 |
+
pygame.draw.rect(screen, (60, 60, 60), (bar_x, bar_y, bar_w, bar_h), 1)
|
| 66 |
+
cov_frac = float(min(coverage, SUCCESS_THRESHOLD)) / SUCCESS_THRESHOLD
|
| 67 |
+
fill_w = int(bar_w * cov_frac)
|
| 68 |
+
if cov_frac < 0.6:
|
| 69 |
+
bar_color = (180, 40, 40)
|
| 70 |
+
elif cov_frac < 0.9:
|
| 71 |
+
bar_color = (200, 150, 30)
|
| 72 |
+
else:
|
| 73 |
+
bar_color = (40, 170, 60)
|
| 74 |
+
pygame.draw.rect(screen, bar_color, (bar_x, bar_y, fill_w, bar_h))
|
| 75 |
+
|
| 76 |
+
cov_pct = coverage * 100.0
|
| 77 |
+
cov_font = _font(18, bold=True)
|
| 78 |
+
cov_surf = cov_font.render(f'IoU {cov_pct:5.1f}% / 95%', True, (20, 20, 20))
|
| 79 |
+
cov_rect = cov_surf.get_rect(topright=(w - 10, bar_y + bar_h + 4))
|
| 80 |
+
cbg = pygame.Surface((cov_rect.width + pad * 2, cov_rect.height + pad),
|
| 81 |
+
pygame.SRCALPHA)
|
| 82 |
+
cbg.fill((255, 255, 255, 200))
|
| 83 |
+
screen.blit(cbg, (cov_rect.x - pad, cov_rect.y - pad // 2))
|
| 84 |
+
screen.blit(cov_surf, cov_rect)
|
| 85 |
+
|
| 86 |
+
# Keybinding hint at the bottom
|
| 87 |
+
hint_font = _font(16)
|
| 88 |
+
hint_surf = hint_font.render('S save C cancel R retry Q quit',
|
| 89 |
+
True, (30, 30, 30))
|
| 90 |
+
hint_rect = hint_surf.get_rect(midbottom=(w // 2, screen.get_height() - 4))
|
| 91 |
+
hbg = pygame.Surface((hint_rect.width + pad * 2, hint_rect.height + pad),
|
| 92 |
+
pygame.SRCALPHA)
|
| 93 |
+
hbg.fill((255, 255, 255, 200))
|
| 94 |
+
screen.blit(hbg, (hint_rect.x - pad, hint_rect.y - pad // 2))
|
| 95 |
+
screen.blit(hint_surf, hint_rect)
|
| 96 |
+
|
| 97 |
+
pygame.display.flip()
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def append_episode_metadata(zarr_path, mode_int, coverage):
|
| 101 |
+
"""Append (mode, coverage) to meta/episode_modes and meta/episode_coverages."""
|
| 102 |
+
root = zarr.open(zarr_path, mode='a')
|
| 103 |
+
meta = root.require_group('meta')
|
| 104 |
+
if 'episode_modes' in meta:
|
| 105 |
+
arr = meta['episode_modes']
|
| 106 |
+
arr.resize((arr.shape[0] + 1,))
|
| 107 |
+
arr[-1] = mode_int
|
| 108 |
+
else:
|
| 109 |
+
meta.create_dataset(
|
| 110 |
+
'episode_modes',
|
| 111 |
+
data=np.array([mode_int], dtype='i1'),
|
| 112 |
+
chunks=(64,), dtype='i1',
|
| 113 |
+
)
|
| 114 |
+
if 'episode_coverages' in meta:
|
| 115 |
+
arr = meta['episode_coverages']
|
| 116 |
+
arr.resize((arr.shape[0] + 1,))
|
| 117 |
+
arr[-1] = float(coverage)
|
| 118 |
+
else:
|
| 119 |
+
meta.create_dataset(
|
| 120 |
+
'episode_coverages',
|
| 121 |
+
data=np.array([coverage], dtype='f4'),
|
| 122 |
+
chunks=(64,), dtype='f4',
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
@click.command()
|
| 127 |
+
@click.option('-o', '--output', required=True)
|
| 128 |
+
@click.option('-rs', '--render_size', default=96, type=int)
|
| 129 |
+
@click.option('-hz', '--control_hz', default=10, type=int)
|
| 130 |
+
def main(output, render_size, control_hz):
|
| 131 |
+
"""
|
| 132 |
+
Mixed-mode Push-T teleop with controlled init.
|
| 133 |
+
|
| 134 |
+
Mode auto-assigned by seed parity:
|
| 135 |
+
seed even = LEFT (wrap T from upper-left side, red label)
|
| 136 |
+
seed odd = RIGHT (wrap T from lower-right side, blue label)
|
| 137 |
+
|
| 138 |
+
Saved per episode in the zarr:
|
| 139 |
+
data/{state,action,img,keypoint,n_contacts}
|
| 140 |
+
meta/episode_ends (standard DP layout)
|
| 141 |
+
meta/episode_modes (int8: 0=LEFT, 1=RIGHT)
|
| 142 |
+
meta/episode_coverages (float32: final IoU coverage, 0..1)
|
| 143 |
+
|
| 144 |
+
Keys:
|
| 145 |
+
S = save current episode now (no need to reach 95% IoU)
|
| 146 |
+
C = cancel current episode and restart same seed
|
| 147 |
+
R = same as C (retry)
|
| 148 |
+
Q = quit (script exits; saved episodes persist)
|
| 149 |
+
Space = pause
|
| 150 |
+
"""
|
| 151 |
+
replay_buffer = ReplayBuffer.create_from_path(output, mode='a')
|
| 152 |
+
|
| 153 |
+
kp_kwargs = PushTKeypointsEnv.genenerate_keypoint_manager_params()
|
| 154 |
+
env = PushTKeypointsEnv(render_size=render_size, render_action=False, **kp_kwargs)
|
| 155 |
+
agent = env.teleop_agent()
|
| 156 |
+
clock = pygame.time.Clock()
|
| 157 |
+
|
| 158 |
+
while True:
|
| 159 |
+
episode = list()
|
| 160 |
+
seed = replay_buffer.n_episodes
|
| 161 |
+
mode_int = seed % 2
|
| 162 |
+
mode_name = MODE_NAMES[mode_int]
|
| 163 |
+
print(f'starting seed {seed} mode={mode_name}', flush=True)
|
| 164 |
+
|
| 165 |
+
# --- Controlled init: T fixed on 45-deg symmetry axis through goal,
|
| 166 |
+
# agent perturbed +/- 15 px around (327, 185).
|
| 167 |
+
T_INIT_XY = np.array([185.0, 327.0])
|
| 168 |
+
T_INIT_ANG = np.pi / 4
|
| 169 |
+
AGENT_NOMINAL = np.array([327.0, 185.0])
|
| 170 |
+
|
| 171 |
+
np.random.seed(seed)
|
| 172 |
+
agent_xy = AGENT_NOMINAL + np.random.uniform(-15, 15, size=2)
|
| 173 |
+
init_state = np.array(
|
| 174 |
+
[agent_xy[0], agent_xy[1], T_INIT_XY[0], T_INIT_XY[1], T_INIT_ANG],
|
| 175 |
+
dtype=np.float64,
|
| 176 |
+
)
|
| 177 |
+
env.reset_to_state = init_state
|
| 178 |
+
env.seed(seed)
|
| 179 |
+
# --- end controlled init
|
| 180 |
+
|
| 181 |
+
obs = env.reset()
|
| 182 |
+
info = env._get_info()
|
| 183 |
+
img = env.render(mode='human')
|
| 184 |
+
|
| 185 |
+
retry = False
|
| 186 |
+
force_save = False
|
| 187 |
+
pause = False
|
| 188 |
+
done = False
|
| 189 |
+
coverage = 0.0
|
| 190 |
+
pygame.display.set_caption(
|
| 191 |
+
f'[{mode_name}] seed {seed} IoU {coverage*100:.1f}% / 95%')
|
| 192 |
+
draw_overlay(mode_int, seed, coverage)
|
| 193 |
+
|
| 194 |
+
while not (done or force_save or retry):
|
| 195 |
+
for event in pygame.event.get():
|
| 196 |
+
if event.type == pygame.KEYDOWN:
|
| 197 |
+
if event.key == pygame.K_SPACE:
|
| 198 |
+
pause = True
|
| 199 |
+
elif event.key in (pygame.K_r, pygame.K_c):
|
| 200 |
+
retry = True
|
| 201 |
+
elif event.key == pygame.K_s:
|
| 202 |
+
force_save = True
|
| 203 |
+
elif event.key == pygame.K_q:
|
| 204 |
+
exit(0)
|
| 205 |
+
if event.type == pygame.KEYUP:
|
| 206 |
+
if event.key == pygame.K_SPACE:
|
| 207 |
+
pause = False
|
| 208 |
+
|
| 209 |
+
if retry or force_save:
|
| 210 |
+
break
|
| 211 |
+
if pause:
|
| 212 |
+
continue
|
| 213 |
+
|
| 214 |
+
act = agent.act(obs)
|
| 215 |
+
if act is not None:
|
| 216 |
+
state = np.concatenate([info['pos_agent'], info['block_pose']])
|
| 217 |
+
keypoint = obs.reshape(2, -1)[0].reshape(-1, 2)[:9]
|
| 218 |
+
data = {
|
| 219 |
+
'img': img,
|
| 220 |
+
'state': np.float32(state),
|
| 221 |
+
'keypoint': np.float32(keypoint),
|
| 222 |
+
'action': np.float32(act),
|
| 223 |
+
'n_contacts': np.float32([info['n_contacts']]),
|
| 224 |
+
}
|
| 225 |
+
episode.append(data)
|
| 226 |
+
|
| 227 |
+
obs, reward, done, info = env.step(act)
|
| 228 |
+
# reward = clip(coverage / 0.95, 0, 1) per PushTEnv.step
|
| 229 |
+
coverage = float(reward) * SUCCESS_THRESHOLD
|
| 230 |
+
img = env.render(mode='human')
|
| 231 |
+
pygame.display.set_caption(
|
| 232 |
+
f'[{mode_name}] seed {seed} IoU {coverage*100:.1f}% / 95%')
|
| 233 |
+
draw_overlay(mode_int, seed, coverage)
|
| 234 |
+
|
| 235 |
+
clock.tick(control_hz)
|
| 236 |
+
|
| 237 |
+
if retry:
|
| 238 |
+
print(f'cancel seed {seed} mode={mode_name}', flush=True)
|
| 239 |
+
continue
|
| 240 |
+
|
| 241 |
+
if not episode:
|
| 242 |
+
print(f'skip seed {seed} (no teleop data — mouse never engaged)',
|
| 243 |
+
flush=True)
|
| 244 |
+
continue
|
| 245 |
+
|
| 246 |
+
data_dict = dict()
|
| 247 |
+
for key in episode[0].keys():
|
| 248 |
+
data_dict[key] = np.stack([x[key] for x in episode])
|
| 249 |
+
replay_buffer.add_episode(data_dict, compressors='disk')
|
| 250 |
+
append_episode_metadata(output, mode_int, coverage)
|
| 251 |
+
suffix = ' [PARTIAL]' if force_save and not done else ''
|
| 252 |
+
print(f'saved seed {seed} mode={mode_name} '
|
| 253 |
+
f'IoU={coverage*100:.1f}%{suffix} '
|
| 254 |
+
f'(total {replay_buffer.n_episodes} episodes)', flush=True)
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
if __name__ == "__main__":
|
| 258 |
+
main()
|
pusht_controlled_mixed.zarr/.zgroup
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"zarr_format": 2
|
| 3 |
+
}
|
pusht_controlled_mixed.zarr/data/.zgroup
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"zarr_format": 2
|
| 3 |
+
}
|
pusht_controlled_mixed.zarr/data/action/.zarray
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"chunks": [
|
| 3 |
+
121,
|
| 4 |
+
2
|
| 5 |
+
],
|
| 6 |
+
"compressor": {
|
| 7 |
+
"blocksize": 0,
|
| 8 |
+
"clevel": 5,
|
| 9 |
+
"cname": "zstd",
|
| 10 |
+
"id": "blosc",
|
| 11 |
+
"shuffle": 2
|
| 12 |
+
},
|
| 13 |
+
"dimension_separator": ".",
|
| 14 |
+
"dtype": "<f4",
|
| 15 |
+
"fill_value": 0.0,
|
| 16 |
+
"filters": null,
|
| 17 |
+
"order": "C",
|
| 18 |
+
"shape": [
|
| 19 |
+
8060,
|
| 20 |
+
2
|
| 21 |
+
],
|
| 22 |
+
"zarr_format": 2
|
| 23 |
+
}
|
pusht_controlled_mixed.zarr/data/action/0.0
ADDED
|
Binary file (495 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/1.0
ADDED
|
Binary file (422 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/10.0
ADDED
|
Binary file (469 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/11.0
ADDED
|
Binary file (470 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/12.0
ADDED
|
Binary file (479 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/13.0
ADDED
|
Binary file (474 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/14.0
ADDED
|
Binary file (494 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/15.0
ADDED
|
Binary file (466 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/16.0
ADDED
|
Binary file (471 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/17.0
ADDED
|
Binary file (470 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/18.0
ADDED
|
Binary file (526 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/19.0
ADDED
|
Binary file (462 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/2.0
ADDED
|
Binary file (473 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/20.0
ADDED
|
Binary file (463 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/21.0
ADDED
|
Binary file (495 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/22.0
ADDED
|
Binary file (466 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/23.0
ADDED
|
Binary file (510 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/24.0
ADDED
|
Binary file (476 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/25.0
ADDED
|
Binary file (468 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/26.0
ADDED
|
Binary file (532 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/27.0
ADDED
|
Binary file (476 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/28.0
ADDED
|
Binary file (487 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/29.0
ADDED
|
Binary file (494 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/3.0
ADDED
|
Binary file (473 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/30.0
ADDED
|
Binary file (516 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/31.0
ADDED
|
Binary file (481 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/32.0
ADDED
|
Binary file (500 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/33.0
ADDED
|
Binary file (474 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/34.0
ADDED
|
Binary file (464 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/35.0
ADDED
|
Binary file (523 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/36.0
ADDED
|
Binary file (444 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/37.0
ADDED
|
Binary file (445 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/38.0
ADDED
|
Binary file (544 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/39.0
ADDED
|
Binary file (536 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/4.0
ADDED
|
Binary file (447 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/40.0
ADDED
|
Binary file (522 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/41.0
ADDED
|
Binary file (505 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/42.0
ADDED
|
Binary file (539 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/43.0
ADDED
|
Binary file (543 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/44.0
ADDED
|
Binary file (528 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/45.0
ADDED
|
Binary file (514 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/46.0
ADDED
|
Binary file (485 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/47.0
ADDED
|
Binary file (544 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/48.0
ADDED
|
Binary file (496 Bytes). View file
|
|
|
pusht_controlled_mixed.zarr/data/action/49.0
ADDED
|
Binary file (532 Bytes). View file
|
|
|