rollingoat commited on
Commit
5d4eec2
·
verified ·
1 Parent(s): 079681e

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +113 -0
README.md ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Robot Data Processing
2
+
3
+ Utilities for turning raw robot HDF5 recordings into a synchronized dataset and then into the [LeRobot v2.1](https://github.com/huggingface/lerobot) format for training.
4
+
5
+ Pipeline:
6
+
7
+ ```
8
+ raw image + low-dim HDF5
9
+ │ sync_image_low_dim.py
10
+
11
+ synced HDF5 ──► visualize_synced_data.py (per-demo MP4 previews)
12
+
13
+ │ convert_synced_h5_to_lerobot.py
14
+
15
+ LeRobot v2.1 dataset folder
16
+ ```
17
+
18
+ ## Environment setup
19
+
20
+ Create and activate a conda env, then install the dependencies:
21
+
22
+ ```
23
+ conda create -n robotdata python=3.10 -y
24
+ conda activate robotdata
25
+ pip install h5py numpy opencv-python datasets
26
+ pip install lerobot
27
+ ```
28
+
29
+ Notes:
30
+ - Python 3.10 is the most broadly compatible with LeRobot; 3.11 also works.
31
+ - `lerobot` pulls in `torch`, `huggingface_hub`, and other heavy deps. If the resolver is slow, install `lerobot` first and add the smaller packages after.
32
+ - If you need a specific CUDA build of `torch`, install it before `lerobot` using the selector on pytorch.org.
33
+
34
+ Quick sanity check:
35
+
36
+ ```
37
+ python -c "import h5py, numpy, cv2, datasets, lerobot; print('ok')"
38
+ ```
39
+
40
+ ## Scripts
41
+
42
+ ### 1. `sync_image_low_dim.py` — align two HDF5 streams
43
+
44
+ Merges an image HDF5 and a low-dimensional HDF5 into a single synced file. Image timestamps are the master timeline; low-dim samples are aligned by nearest timestamp. Handles zero-valued timestamps, sudden timestamp jumps, and non-overlapping intervals by skipping affected demos. Demos excluded or skipped are **renamed to be consecutive** (`demo_0`, `demo_1`, …) in the output so there are no gaps.
45
+
46
+ **Inputs (per HDF5):** `data/<demo>/obs/<timestamp_key>` plus any number of per-demo datasets.
47
+
48
+ **Output:** `data/<demo>/obs/{timestamp, <image_keys…>, <lowdim_keys…>}` and optional `data/<demo>/actions`.
49
+
50
+ **Example:**
51
+
52
+ ```
53
+ python sync_image_low_dim.py --image-h5 /path/raw_images.hdf5 --lowdim-h5 /path/raw_lowdim.hdf5 --output-h5 /path/synced.h5 --allow-missing
54
+ ```
55
+
56
+ **Useful flags:**
57
+ - `--image-keys`, `--lowdim-keys` — restrict which obs datasets to copy (defaults to all except timestamp).
58
+ - `--exclude-demo demo_4 demo_5` — drop specific demos. Remaining demos are reindexed.
59
+ - `--skip-n N` — keep every `(N+1)`-th frame after syncing (e.g. `--skip-n 2` → keep 0, 3, 6, …).
60
+ - `--allow-missing` — log and skip demos with missing keys instead of failing.
61
+
62
+ ### 2. `visualize_synced_data.py` — render per-demo MP4 previews
63
+
64
+ Renders each demo to an MP4 with selected camera views side-by-side and optional lowdim overlays as on-frame text. Useful to sanity-check a sync before running the LeRobot conversion.
65
+
66
+ **Example:**
67
+
68
+ ```
69
+ python visualize_synced_data.py /path/synced.h5 --out-dir ./vis --fps 10 --image-keys agentview_image oak_image --overlay-keys robot0_eef_pos robot0_gripper_qpos
70
+ ```
71
+
72
+ Outputs `./vis/<demo>.mp4` for each demo.
73
+
74
+ ### 3. `convert_synced_h5_to_lerobot.py` — synced HDF5 → LeRobot v2.1
75
+
76
+ Produces a LeRobot dataset directly in `--output-dir`. The folder must not already exist.
77
+
78
+ **Example (30 Hz → 10 Hz, 2 cameras, 8-dim state):**
79
+
80
+ ```
81
+ python convert_synced_h5_to_lerobot.py --synced-h5 /path/synced.h5 --output-dir /path/lerobot_dataset --fps 10 --source-fps 30 --task "pass the knife by the sharp side" --image-map agentview_image:base_rgb oak_image:wrist_rgb --state-keys robot0_joint_pos robot0_gripper_qpos --action-source next_state --image-size 256 256
82
+ ```
83
+
84
+ **Key flags:**
85
+ - `--output-dir PATH` — final dataset folder (must not exist; parent is created if needed).
86
+ - `--fps N` / `--source-fps M` — target and source frame rates. `M` must be divisible by `N`; the script subsamples by stride `M/N`. If `--source-fps` is omitted, it is estimated from the first demo's timestamps.
87
+ - `--image-map src:dst [...]` — rename HDF5 image keys to LeRobot feature names.
88
+ - `--state-keys k1 k2 [...]` — concatenate these lowdim datasets into a single `state` vector (order matters).
89
+ - `--action-source {next_state, hdf5_actions}` — use the next state as the action when the HDF5 has no `actions` dataset.
90
+ - `--image-size H W` — resize images. Omit to keep native resolution.
91
+ - `--task "..."` — language instruction stored with every frame.
92
+ - `--repo-id user/name` + `--push-to-hub` — optional, pushes to HuggingFace.
93
+
94
+ **Output layout** (LeRobot v2.1):
95
+
96
+ ```
97
+ <output-dir>/
98
+ meta/ info.json, episodes.jsonl, tasks.jsonl, episodes_stats.jsonl
99
+ data/ chunk-000/episode_<6digit>.parquet
100
+ ```
101
+
102
+ ## Typical workflow
103
+
104
+ ```
105
+ # 1. sync raw HDF5s
106
+ python sync_image_low_dim.py --image-h5 raw_images.hdf5 --lowdim-h5 raw_lowdim.hdf5 --output-h5 synced.h5 --allow-missing
107
+
108
+ # 2. eyeball the result
109
+ python visualize_synced_data.py synced.h5 --out-dir vis --fps 10 --image-keys agentview_image oak_image --overlay-keys robot0_eef_pos robot0_gripper_qpos
110
+
111
+ # 3. convert to LeRobot
112
+ python convert_synced_h5_to_lerobot.py --synced-h5 synced.h5 --output-dir ./lerobot_dataset --fps 10 --source-fps 30 --task "your instruction" --image-map agentview_image:base_rgb oak_image:wrist_rgb --state-keys robot0_joint_pos robot0_gripper_qpos --action-source next_state --image-size 256 256
113
+ ```