oshd 1.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. oshd-1.1.0/.gitignore +10 -0
  2. oshd-1.1.0/DATA_REQUIREMENTS.md +304 -0
  3. oshd-1.1.0/LICENSE +21 -0
  4. oshd-1.1.0/PKG-INFO +456 -0
  5. oshd-1.1.0/README.md +414 -0
  6. oshd-1.1.0/pyproject.toml +76 -0
  7. oshd-1.1.0/src/oshd/__init__.py +32 -0
  8. oshd-1.1.0/src/oshd/benchmarks/v1.json +2238 -0
  9. oshd-1.1.0/src/oshd/benchmarks/v2.json +6555 -0
  10. oshd-1.1.0/src/oshd/benchmarks/v3.json +6765 -0
  11. oshd-1.1.0/src/oshd/calibrate.py +498 -0
  12. oshd-1.1.0/src/oshd/calibrate_web.py +252 -0
  13. oshd-1.1.0/src/oshd/calibration.py +224 -0
  14. oshd-1.1.0/src/oshd/cli.py +559 -0
  15. oshd-1.1.0/src/oshd/dataset.py +253 -0
  16. oshd-1.1.0/src/oshd/events.py +93 -0
  17. oshd-1.1.0/src/oshd/export/__init__.py +8 -0
  18. oshd-1.1.0/src/oshd/export/_common.py +40 -0
  19. oshd-1.1.0/src/oshd/export/bop.py +96 -0
  20. oshd-1.1.0/src/oshd/export/coco.py +57 -0
  21. oshd-1.1.0/src/oshd/export/frames.py +29 -0
  22. oshd-1.1.0/src/oshd/export/yolo.py +37 -0
  23. oshd-1.1.0/src/oshd/flow.py +127 -0
  24. oshd-1.1.0/src/oshd/geometry.py +239 -0
  25. oshd-1.1.0/src/oshd/hub.py +232 -0
  26. oshd-1.1.0/src/oshd/imaging.py +93 -0
  27. oshd-1.1.0/src/oshd/labels.py +191 -0
  28. oshd-1.1.0/src/oshd/objects.py +175 -0
  29. oshd-1.1.0/src/oshd/quality.py +237 -0
  30. oshd-1.1.0/src/oshd/splits.py +268 -0
  31. oshd-1.1.0/src/oshd/tasks.py +284 -0
  32. oshd-1.1.0/src/oshd/torch.py +66 -0
  33. oshd-1.1.0/src/oshd/trajectory.py +413 -0
  34. oshd-1.1.0/src/oshd/viz.py +485 -0
  35. oshd-1.1.0/tests/conftest.py +207 -0
  36. oshd-1.1.0/tests/test_calibrate.py +192 -0
  37. oshd-1.1.0/tests/test_dataset.py +97 -0
  38. oshd-1.1.0/tests/test_geometry.py +74 -0
  39. oshd-1.1.0/tests/test_quality_viz.py +76 -0
  40. oshd-1.1.0/tests/test_real_targets.py +155 -0
  41. oshd-1.1.0/tests/test_sim.py +173 -0
  42. oshd-1.1.0/tests/test_splits.py +146 -0
  43. oshd-1.1.0/tests/test_tasks.py +85 -0
oshd-1.1.0/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ __pycache__/
2
+ *.egg-info/
3
+ .venv/
4
+ dist/
5
+ build/
6
+ .pytest_cache/
7
+ .ruff_cache/
8
+
9
+ # local outputs of `oshd calibrate` / `oshd align-markers`: the data belongs on the Hub
10
+ oshd_calibration/
@@ -0,0 +1,304 @@
1
+ # Calibration and model files: status and what is still needed
2
+
3
+ `oshd` can download, read and synchronize every modality. Ground-truth **labels**
4
+ (6D pose, masks, boxes, optical flow) are computed from motion capture, and they need the
5
+ calibration and model files below. A label task for a camera or object that is not
6
+ calibrated yet raises `MissingCalibrationError`, pointing here.
7
+
8
+ **Today:** labels work for the `cubesat` in the **RealSense colour** camera in trajectories
9
+ 007–009. The other cameras still need extrinsics (see the checklist).
10
+
11
+ Run `oshd check` at any time to see what is present:
12
+
13
+ ```
14
+ $ oshd check
15
+ models/objects.yaml ok ['cubesat']
16
+ cubesat: size=0.100 x 0.134 x 0.100 m mocap_body=cubesat verts=27354 T_body_model=set ...
17
+ trajectory_007
18
+ reference_body ok SensorStack
19
+ firefly intrinsics ok extrinsics -- source=supplement:...
20
+ realsense_color intrinsics ok extrinsics ok source=ros_camera_info
21
+ realsense_depth intrinsics ok extrinsics --
22
+ events intrinsics -- extrinsics --
23
+ ```
24
+
25
+ All files go in the **Hub dataset repo** (`r3m3c3/oshd`), not in this Python package,
26
+ so everyone gets them with `oshd download` and they can be versioned with the data.
27
+
28
+ Conventions used everywhere:
29
+
30
+ - `T_a_b` is a 4x4 homogeneous transform that maps points in frame `b` to frame `a`
31
+ (it is the pose of `b` expressed in `a`). Metres, right-handed.
32
+ - Quaternions are `[qx, qy, qz, qw]` (the mocap column order).
33
+ - Camera optical frames follow ROS: +z forward, +x right, +y down.
34
+ - A transform can be written as 16 row-major numbers **or** as
35
+ `{translation: [x, y, z], rotation_xyzw: [qx, qy, qz, qw]}`.
36
+
37
+ ---
38
+
39
+ ## Checklist
40
+
41
+ | # | Item | File | Needed for | Status |
42
+ |---|------|------|------------|--------|
43
+ | 1 | Camera extrinsics: `SensorStack` body → each camera optical frame | `calibration/rig.yaml` + `<traj>.yaml` | labels in that camera | **realsense_color done** (`oshd calibrate`, 8.8 px RMS); firefly + events from the rig calibration (`T_realsense_color_cam`, trajectory_010 on); realsense_depth missing |
44
+ | 2 | Event camera intrinsics (1280x720) | `calibration/<traj>.yaml` | event labels / flow | **done** from trajectory_010 (rig calibration accepted 2026-10-16) |
45
+ | 3 | Firefly intrinsics from a real calibration | `calibration/<traj>.yaml` | Firefly labels | **done** from trajectory_010; 001-009 use the older `supplement:` ones |
46
+ | 4 | Cubesat CAD mesh | `models/CubeSat_U1.obj` | masks, boxes, BOP | **done** |
47
+ | 5 | Cubesat marker → CAD transform `T_body_model` | `models/objects.yaml` | all cubesat labels | **done** (`oshd align-markers`, 1.2 mm) |
48
+ | 6 | Floating platform mesh + `T_body_model` (optional, for occlusion + a 2nd class) | `models/objects.yaml` | better masks | optional |
49
+ | 6b | Mockup CAD (trajectory_010 on) + rigid-body → CAD transform | `models/real/<mockup>/`, `models/real/mockups.json`, `models/objects.yaml` | mockup labels | **CAD done**; `T_body_model` see below |
50
+ | 7 | Per-sensor time offsets, if any sensor is not on the host clock | `calibration/rig.yaml` | exact sync | optional |
51
+ | 8 | RealSense depth scale + which frame depth is aligned to | `calibration/<traj>.yaml` | flow | verify |
52
+ | 9 | Official train / val / test split | `splits.json` | comparable results | **done**: simulated per recording run, real per lighting setting |
53
+ | 10 | Per-trajectory metadata (real / synthetic, task type) | `manifest.json` | filtering | optional |
54
+
55
+ ---
56
+
57
+ ## 1. Rig extrinsics — `calibration/rig.yaml`
58
+
59
+ The cameras are rigidly mounted on the rig tracked by the `SensorStack` mocap body. For each
60
+ camera we need `T_body_cam`: the pose of the camera **optical** frame in the SensorStack
61
+ mocap rigid-body frame (the frame Motive/OptiTrack reports for that body, i.e. what the
62
+ `x, y, z, qx..qw` columns in `mocap` describe).
63
+
64
+ ```yaml
65
+ # calibration/rig.yaml — shared by all trajectories unless a <trajectory>.yaml overrides it
66
+ extrinsics:
67
+ reference_body: SensorStack # must match a `body` value in the mocap table
68
+ cameras:
69
+ firefly:
70
+ T_body_cam: {translation: [0.05, 0.00, 0.02], rotation_xyzw: [-0.5, 0.5, -0.5, 0.5]}
71
+ realsense_color:
72
+ T_body_cam: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
73
+ realsense_depth:
74
+ T_body_cam: ...
75
+ events:
76
+ T_body_cam: ...
77
+ ```
78
+
79
+ How to get it: **`oshd calibrate --camera <camera>`** (see the README) solves it from cube
80
+ corners clicked in existing frames, keeping the cube's measured `T_body_model` fixed. That is
81
+ how `realsense_color` was done: 40 frames, 8.8 px RMS overall and about 4 px on far frames.
82
+ Close-up frames are the least accurate, mostly because the foil is over-exposed there.
83
+ Alternatives:
84
+
85
+ - **Hand-eye calibration**: record a checkerboard / AprilTag board that also carries mocap
86
+ markers (or is static in the mocap world), then solve `AX = XB` (e.g. OpenCV
87
+ `calibrateHandEye`) between the SensorStack mocap poses and the board poses per camera.
88
+ - **Camera-to-camera** (Kalibr, OpenCV stereo) for all cameras + a single hand-eye for one of
89
+ them; the package composes them.
90
+ - **From CAD**: `oshd align-markers` with `models/SensorStack.motive` and the SensorStack
91
+ CAD's marker positions gives the rig body → CAD transform; the camera pose in that CAD then
92
+ gives `T_body_cam`.
93
+
94
+ Note: the RealSense is mounted upside down relative to the cube (the marker holder, which is
95
+ under the cube, appears on top in its images). `T_body_cam` accounts for that; nothing to do.
96
+
97
+ If the rig is re-assembled, put a new `extrinsics:` block in that trajectory's
98
+ `calibration/<trajectory>.yaml`: it overrides `rig.yaml` key by key.
99
+
100
+ **Camera-to-camera (trajectory_010 on).** The real pipeline writes the accepted rig calibration
101
+ (OSED `calib.sh`) into every `calibration/<trajectory>.yaml`: each calibrated camera
102
+ (`realsense_color`, `firefly`, `events`) has `T_realsense_color_cam`, its pose in the RealSense
103
+ colour optical frame. A camera without its own `T_body_cam` gets `T_body_cam(realsense_color) @
104
+ T_realsense_color_cam`, so only the RealSense colour camera needs the hand-eye calibration above.
105
+
106
+ ## 2. Event camera intrinsics
107
+
108
+ The calibration files have no `events` entry. Add one in the same schema as the others
109
+ (the event camera needs a regular calibration, e.g. with a blinking-pattern screen and
110
+ Prophesee's calibration tool, or E2VID reconstructions + a checkerboard):
111
+
112
+ ```yaml
113
+ events:
114
+ source: prophesee_calibration # anything not starting with "supplement"
115
+ width: 1280
116
+ height: 720
117
+ distortion_model: plumb_bob
118
+ D: [k1, k2, p1, p2, k3]
119
+ K: [fx, 0, cx, 0, fy, cy, 0, 0, 1]
120
+ ```
121
+
122
+ ## 3. Firefly intrinsics
123
+
124
+ The Firefly entry is marked `source: supplement:/data/calibration.json (driver did not
125
+ publish real intrinsics)`. If that file is a real calibration at 3072x2048, just change the
126
+ `source` to say where it came from. The distortion is significant (k1 = -0.23), so labels
127
+ depend on it being right. The package handles it: projection is exact, and BOP export
128
+ undistorts images.
129
+
130
+ ## 4–6. Object models — `models/objects.yaml`
131
+
132
+ The current entry (generated by `oshd align-markers`):
133
+
134
+ ```yaml
135
+ cubesat:
136
+ class_id: 1 # 1-based; BOP obj_id / COCO category_id (YOLO uses class_id-1)
137
+ mocap_body: cubesat # body name in the mocap table
138
+ mesh: models/CubeSat_U1.obj # Onshape export, metres, Y-up; origin = centre of the face
139
+ # opposite the marker holder
140
+ mesh_scale: 1.0 # CAD units -> metres
141
+ trajectories: [trajectory_007, trajectory_008, trajectory_009] # where the cube was present
142
+ T_body_model: {translation: [...], rotation_xyzw: [...]} # p_body = R @ p_model + t
143
+ cad_markers: [...] # the CAD marker centres it was fitted from (mesh frame, m)
144
+ motive_file: models/CubeSat_U1.motive
145
+ keypoints: [...] # the cube body's 8 corners, clicked by `oshd calibrate`
146
+ ```
147
+
148
+ **How `T_body_model` was measured.** The Motive export (`models/CubeSat_U1.motive`) lists the
149
+ 8 LED positions in the rigid body's own frame (origin = LED centroid, which is the pivot).
150
+ The 4 corner LEDs' positions in the CAD (from Onshape) were matched to them with a rigid fit
151
+ (Kabsch, 0.6–1.2 mm residuals):
152
+
153
+ ```bash
154
+ oshd align-markers --motive models/CubeSat_U1.motive --cad-axes x,-z,y \
155
+ --cad-marker 46.077 -46.03447 -117.99807 --cad-marker -47.35423 -47.40068 -121.5 \
156
+ --cad-marker -47.35423 47.39831 -121.5 --cad-marker 47.44476 47.39831 -121.5
157
+ ```
158
+
159
+ - `--cad-axes x,-z,y`: Onshape is Z-up, the exported mesh is Y-up.
160
+ - Motive stores bodies Y-up and the ROS mocap stream is Z-up. The standard conversion
161
+ `(x, y, z)_ros = (x, -z, y)_motive` is the default (`--motive-to-body`), and it is the one
162
+ consistent with the lab. The marker holder is on the cube's **bottom** face: the cube sits
163
+ on it, tilted about 23° from vertical. The cube centre is 6.8 cm above the LED centroid.
164
+
165
+ **Mockups (trajectory_010 on).** The recording pipeline uploads each mockup's CAD to
166
+ `models/real/<mockup>/model.obj` (metres, textures next to it) and writes
167
+ `models/real/mockups.json`: trajectory -> `{model, static_pose}`. They are loaded as objects
168
+ on the mocap body `target` (`class_id` after those of objects.yaml), present in their
169
+ trajectories; `static_pose` (world frame) replaces the mocap where the mockup's tracking drops
170
+ out. The CAD's origin is the pivot of the Motive rigid body, but the rigid body's axes are the
171
+ ones Motive gave it when it was created, so its rotation relative to the CAD goes in
172
+ `models/objects.yaml` under the mockup's name (`T_body_model`, as for the cubesat); the rest of
173
+ the mockup entry is filled in from mockups.json.
174
+
175
+ For a new object: export its rigid body from Motive, measure its marker centres in the CAD,
176
+ and run the same command. Without a CAD, `box: [sx, sy, sz]` (metres, centred on the model
177
+ origin) instead of `mesh` gives correct boxes and masks for a cuboid.
178
+
179
+ Meshes should be simplified to about 10k faces or fewer. Masks are rasterised per triangle,
180
+ so huge CAD meshes slow down label generation. Masks are hole-filled, because hollow CAD
181
+ shells can be see-through where the real object is solid.
182
+
183
+ ## 7. Time offsets (optional)
184
+
185
+ Every stream is already on the recording host's clock. If a sensor turns out to have a
186
+ constant latency (e.g. the event anchoring is a few ms off, or a camera's exposure midpoint
187
+ differs from its stamp), add:
188
+
189
+ ```yaml
190
+ time_offsets_ns:
191
+ events: 0
192
+ firefly: 0
193
+ realsense_color: 0
194
+ realsense_depth: 0
195
+ mocap: 0
196
+ ```
197
+
198
+ The offset is **added** to that sensor's timestamps everywhere in the package.
199
+
200
+ ## 8. Depth
201
+
202
+ - `depth_scale` (metres per raw unit). The package assumes 0.001 (RealSense default) if
203
+ absent: `realsense_depth: {depth_scale: 0.001, ...}`.
204
+ - The README says depth is "aligned to color", but `realsense_depth` has its own `K` and
205
+ `frame_id: camera_depth_optical_frame`. Which is it? If depth is aligned to color, the
206
+ depth entry should use the colour intrinsics and `T_body_cam` should equal the colour one.
207
+
208
+ ## 9. Splits — `splits.json`
209
+
210
+ ```json
211
+ {
212
+ "version": 3,
213
+ "train": ["trajectory_hera_000001", "..."],
214
+ "val": [],
215
+ "test": ["trajectory_hera_000007", "..."],
216
+ "summary": {"sim_3d/approach": {"train": 378, "val": 0, "test": 93}, "...": {}}
217
+ }
218
+ ```
219
+
220
+ Splits are by whole trajectories: consecutive frames are near-duplicates, so frame-level
221
+ splits leak between train and test. Without this file the package falls back to a stable
222
+ hash of the trajectory name and prints a warning. Add new trajectories to the file as
223
+ they are uploaded, and never move old ones between splits. Bump `version` whenever the
224
+ file changes, so results can cite it.
225
+
226
+ The simulated trajectories are added by `oshd.splits.update_sim_splits`, which the sim
227
+ publisher (`osh_dataset_pipeline/sim/publish_hf.py`) runs on every upload; `oshd splits update
228
+ --push` does the same by hand. It is append-only, keeps every listed trajectory (real ones
229
+ too), puts all episodes of a recording run in one split and sends ~20% of the runs of each
230
+ scenario config to `test`. Simulated trajectories not listed yet are in no split.
231
+
232
+ The real trajectories with a target model (`models/objects.yaml` `trajectories`, or a mockup
233
+ in `models/real/mockups.json`) are added by `update_real_splits` (`oshd splits update`), also
234
+ append-only: grouped by lighting setting (target, light colour temperature and intensity from
235
+ `manifest.json`'s `light`), whole settings go to `test` until ~20% of each target's
236
+ trajectories are there, in order of colour temperature so the test settings spread over the
237
+ range. Real trajectories without a target model are in no split. Files before version 3 still
238
+ give unlisted real trajectories the hash fallback. The `splits` key of `manifest.json` (the real converter's `--split`) and the
239
+ simulation scenarios are the *Hub viewer's* splits: they group the data for browsing and are
240
+ exposed as `ds.hub_splits`, not used for training.
241
+
242
+ Frozen benchmarks for papers (`benchmark_v1`: Hub revision `8205a11`, 2195 sim + 3 real
243
+ trajectories, train 1762 / test 436) ship with the package (`oshd/benchmarks/`). They
244
+ are copied unchanged into `splits.json` and fix the split of their trajectories. A
245
+ new benchmark is a new file, never an edit. `benchmark_v2` (oshd 1.0.0: Hub revision
246
+ `df3530b`, 6413 sim + 92 real trajectories, train 5474 / test 1031) is the final collection.
247
+
248
+ ## 10. Trajectory metadata — `manifest.json`
249
+
250
+ Add an optional `trajectory_info` block next to the existing `trajectories` counts:
251
+
252
+ ```json
253
+ "trajectory_info": {
254
+ "trajectory_007": {"domain": "real", "task": "go_to_pose", "notes": "..."},
255
+ "sim_000001": {"domain": "synthetic", "task": "waypoints", "generator": "isaac-sim 4.5"}
256
+ }
257
+ ```
258
+
259
+ `domain` lets people filter (`ds.split("train", domain="synthetic")`).
260
+
261
+ The simulation pipeline does not use this block: its trajectories are listed in
262
+ `sim_manifest.json` (group, scenario, counts, goal errors) and stored as
263
+ `sim_<group>_<modality>/<trajectory>/*.parquet`, with `calibration/<trajectory>.yaml` in the
264
+ simulation format (`T_base_sensor` per sensor) and `metadata/<trajectory>.yaml`. The package
265
+ reads both (domain `synthetic`, or `sim_3d` / `sim_zerog`). Every table also has a
266
+ `trajectory_id` column, which the readers drop.
267
+
268
+ ---
269
+
270
+ ## Data-quality notes found while building the package
271
+
272
+ Run `oshd quality` for the current numbers. Found so far:
273
+
274
+ - **trajectory_008 has no `floatingplatform` mocap body** (only SensorStack and cubesat),
275
+ so its robot trajectory and goal error cannot be evaluated.
276
+ - **IMU at ~20 Hz with gaps up to 0.6 s** in all three trajectories. The Mid-360 IMU normally
277
+ publishes at 200 Hz, so most samples were dropped at recording time.
278
+ - **Mocap dropouts**: all three bodies show ~75 gaps longer than 50 ms (max 130 ms) at the
279
+ same instants, which points to recorder / network drops rather than occlusion. With the
280
+ default 50 ms interpolation limit about 11% of frames get no label; tune with
281
+ `max_gap_ns=`, or fix at the recorder (e.g. record mocap on a dedicated QoS / higher queue).
282
+ - **RealSense rates**: colour is at 7.3 Hz (135 ms period) and depth at 14.5 Hz, so only 60% of
283
+ colour frames have a depth frame within 20 ms. That suggests frames were dropped at 15 fps
284
+ (or a 7.5 fps colour profile).
285
+ - The first Firefly frame is almost black (max pixel value 48). Exposure may still have
286
+ been settling; only that one frame was checked.
287
+ - **Mocap timestamps arrive in bursts** (median 0.4 ms between samples at ~215 Hz on
288
+ average), so they are receipt times rather than capture times. Labels are not very
289
+ sensitive to this (a constant camera time offset of -150 to +100 ms changes little), but
290
+ it is one of the remaining error sources in the camera calibration.
291
+ - **Cube orientation noise** is up to ~2° (p95) between consecutive samples: its LEDs are
292
+ close together. That is worth a few pixels of label error in close-up frames.
293
+
294
+ ## Checking labels
295
+
296
+ After calibrating a camera, look at the labels before uploading:
297
+
298
+ ```bash
299
+ oshd viz -t trajectory_009 -m realsense_color -m mocap # add --web over SSH
300
+ ```
301
+
302
+ The camera view shows the mask, box and cube wireframe on every frame. Scrub the timeline:
303
+ the overlay should stay on the cube. `oshd calibrate` also writes
304
+ `oshd_calibration/overlays_<camera>/*.png` for the clicked frames.
oshd-1.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ricard Marsal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.