yxma commited on
Commit
3dbf5cd
·
verified ·
1 Parent(s): f407ce5

scripts: tactile context

Browse files
Files changed (1) hide show
  1. scripts/build_probe_testset.py +57 -10
scripts/build_probe_testset.py CHANGED
@@ -43,6 +43,11 @@ REL = force_meta("motherboard")
43
  H5R = raw_root("motherboard")
44
  CAM_H5 = {"left": 1, "middle": 2, "right": 0}
45
  VIEWS = ("left", "middle", "right")
 
 
 
 
 
46
  # All three sessions. 2026-05-19 is included with the translation-only
47
  # correction the release already applies, (230, 0, 175) mm; its residual — the
48
  # unmeasured yaw about the table normal — is published in the manifest under
@@ -99,6 +104,11 @@ def main() -> int:
99
  "format": FORMAT_VERSION,
100
  "task": "motherboard",
101
  "views": list(VIEWS),
 
 
 
 
 
102
  "context_frames": CONTEXT,
103
  "view_margin_px": VIEW_MARGIN_PX,
104
  "image_size": [640, 480],
@@ -145,9 +155,7 @@ def main() -> int:
145
  while made < args.runs and tried < args.runs * 14:
146
  tried += 1
147
  date, ep = eps[int(rng.integers(len(eps)))]
148
- t = pq.read_table(REL / date / f"{ep}.parquet",
149
- columns=["sensor_left_pose", "sensor_right_pose",
150
- "source_h5_frame"]).to_pydict()
151
  poses = {s: np.asarray([x for x in t[f"sensor_{s}_pose"]], float)
152
  for s in ("left", "right")}
153
  trim = int(np.asarray(t["source_h5_frame"])[0])
@@ -176,16 +184,46 @@ def main() -> int:
176
  assert allow[np.asarray(r["context_rows"], int)].all(), \
177
  "start frame outside a held-out interval"
178
  rows = np.asarray(r["context_rows"], int)
179
- with h5py.File(str(H5R / date / f"{ep}.h5"), "r") as f5:
180
- ctx = {v: [f5[f"realsense/cam{CAM_H5[v]}/color"][trim + int(rr)][..., ::-1]
181
- for rr in rows] for v in VIEWS}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
 
183
  run_dir = out / "probes" / f"run{made}"
184
  (run_dir / "context").mkdir(parents=True)
185
- for v in VIEWS:
186
- for i, im in enumerate(ctx[v]):
187
- cv2.imwrite(str(run_dir / "context" / f"ctx{i}_{v}.jpg"),
188
- im[..., ::-1], [cv2.IMWRITE_JPEG_QUALITY, 95])
189
 
190
  side, other = r["moving_side"], r["held_side"]
191
  gel_m, gel_o = cal[f"gel_{side}"], cal[f"gel_{other}"]
@@ -202,6 +240,15 @@ def main() -> int:
202
  npz = {"poses": P, "held_pose": np.asarray(r["held_pose"], float),
203
  "context_poses_moving": poses[side][rows],
204
  "context_poses_held": poses[other][rows]}
 
 
 
 
 
 
 
 
 
205
  for v in VIEWS:
206
  npz[f"gt_px_{v}"] = project_gt(P, gel_m, cal["cams"][v])
207
  # THE ACTION, IN THE GEL FRAME. Each probe moves along exactly one
 
43
  H5R = raw_root("motherboard")
44
  CAM_H5 = {"left": 1, "middle": 2, "right": 0}
45
  VIEWS = ("left", "middle", "right")
46
+ # The context a tactile world model conditions on is not three camera views.
47
+ # The first export shipped only those, which made the package unusable for the
48
+ # thing it exists to test.
49
+ TACTILE = ("tactile_left", "tactile_right")
50
+ STREAMS = tuple(f"view_{v}" for v in VIEWS) + TACTILE
51
  # All three sessions. 2026-05-19 is included with the translation-only
52
  # correction the release already applies, (230, 0, 175) mm; its residual — the
53
  # unmeasured yaw about the table normal — is published in the manifest under
 
104
  "format": FORMAT_VERSION,
105
  "task": "motherboard",
106
  "views": list(VIEWS),
107
+ "context_streams": list(STREAMS),
108
+ "context_note": ("ctx{i}_{stream}.jpg for i in 0..3. Video frame r is "
109
+ "parquet row r for every stream; the tactile videos "
110
+ "are already row-aligned (the +15 acquisition lag was "
111
+ "applied at encode time), so nothing is re-applied."),
112
  "context_frames": CONTEXT,
113
  "view_margin_px": VIEW_MARGIN_PX,
114
  "image_size": [640, 480],
 
155
  while made < args.runs and tried < args.runs * 14:
156
  tried += 1
157
  date, ep = eps[int(rng.integers(len(eps)))]
158
+ t = pq.read_table(REL / date / f"{ep}.parquet").to_pydict()
 
 
159
  poses = {s: np.asarray([x for x in t[f"sensor_{s}_pose"]], float)
160
  for s in ("left", "right")}
161
  trim = int(np.asarray(t["source_h5_frame"])[0])
 
184
  assert allow[np.asarray(r["context_rows"], int)].all(), \
185
  "start frame outside a held-out interval"
186
  rows = np.asarray(r["context_rows"], int)
187
+ # FROM THE PUBLISHED VIDEOS, not the raw HDF5. The release ships
188
+ # view_{left,middle,right}.mp4 and tactile_{left,right}.mp4, and video
189
+ # frame r IS parquet row r: measured against the raw H5 at 1.88 mean
190
+ # pixel difference, where two ADJACENT raw frames differ by 4.89. (My
191
+ # first comparison said 11.46 because I compared cv2's BGR against an
192
+ # already channel-flipped array — the data was fine, the test was not.)
193
+ #
194
+ # The tactile videos are already row-aligned: cross-correlating a
195
+ # contact measure from the video against the parquet's
196
+ # tactile_left_intensity peaks at lag 0 with r = 0.980, falling off
197
+ # symmetrically. The +15 acquisition lag was applied at encode time, so
198
+ # nothing must be re-applied here.
199
+ #
200
+ # This removes the last dependency on the unpublished ~1 TB raw tree,
201
+ # so the test set can be rebuilt from what the dataset ships.
202
+ ctx = {}
203
+ for stream in STREAMS:
204
+ f = REL.parent / "videos" / date / ep / f"{stream}.mp4"
205
+ if not f.is_file():
206
+ f = release_root("motherboard") / "videos" / date / ep / f"{stream}.mp4"
207
+ cap = cv2.VideoCapture(str(f))
208
+ got = []
209
+ for rr in rows:
210
+ cap.set(cv2.CAP_PROP_POS_FRAMES, int(rr))
211
+ ok, fr = cap.read()
212
+ got.append(fr if ok else None)
213
+ cap.release()
214
+ if any(g is None for g in got):
215
+ ctx = None
216
+ break
217
+ ctx[stream] = got
218
+ if ctx is None:
219
+ continue
220
 
221
  run_dir = out / "probes" / f"run{made}"
222
  (run_dir / "context").mkdir(parents=True)
223
+ for stream, frames in ctx.items():
224
+ for i, im in enumerate(frames):
225
+ cv2.imwrite(str(run_dir / "context" / f"ctx{i}_{stream}.jpg"),
226
+ im, [cv2.IMWRITE_JPEG_QUALITY, 95])
227
 
228
  side, other = r["moving_side"], r["held_side"]
229
  gel_m, gel_o = cal[f"gel_{side}"], cal[f"gel_{other}"]
 
240
  npz = {"poses": P, "held_pose": np.asarray(r["held_pose"], float),
241
  "context_poses_moving": poses[side][rows],
242
  "context_poses_held": poses[other][rows]}
243
+ # the numeric channels AT the context rows, so a model that reads
244
+ # scalars sees the same instants as the images
245
+ for col in ("tactile_left_intensity", "tactile_right_intensity",
246
+ "tactile_left_area", "tactile_right_area",
247
+ "tactile_left_is_new", "tactile_right_is_new",
248
+ "force_left_normal_n", "force_right_normal_n",
249
+ "force_left_penetration_mm", "force_right_penetration_mm"):
250
+ if col in t:
251
+ npz[f"context_{col}"] = np.asarray(t[col])[rows]
252
  for v in VIEWS:
253
  npz[f"gt_px_{v}"] = project_gt(P, gel_m, cal["cams"][v])
254
  # THE ACTION, IN THE GEL FRAME. Each probe moves along exactly one