Document ~15-frame tactile acquisition latency + loader compensation (tactile_latency=); tasks.json + README + loader
Browse files- README.md +21 -0
- examples/react_video_dataset.py +32 -15
- tasks.json +10 -0
README.md
CHANGED
|
@@ -134,6 +134,27 @@ sample = ds[0]
|
|
| 134 |
```
|
| 135 |
`mode="segment"` iterates clean spans (no bad frames by construction); `mode="window"` slides over whole episodes and skips `bad_frames.json` intervals. Backend: PyAV (install `decord` for faster random access).
|
| 136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
## Data quality
|
| 138 |
Per-task `bad_frames.json` flags `intensity_spikes`, `pose_teleports_{L,R}`, `ot_loss_{L,R}` (OptiTrack track loss). Overall flagged: motherboard 0.90 %, pushT 0.67 %. `segments.json` already excludes them.
|
| 139 |
|
|
|
|
| 134 |
```
|
| 135 |
`mode="segment"` iterates clean spans (no bad frames by construction); `mode="window"` slides over whole episodes and skips `bad_frames.json` intervals. Backend: PyAV (install `decord` for faster random access).
|
| 136 |
|
| 137 |
+
## ⚠️ Known issue: tactile acquisition latency (~15 frames)
|
| 138 |
+
|
| 139 |
+
Recordings **up to and including 2026-06-18** have a GelSight-vs-camera capture
|
| 140 |
+
lag of **≈15 frames (~0.5 s)**: the tactile stream at index `i` was physically
|
| 141 |
+
captured ~15 frames *before* the camera/pose at the same index. Cause: a
|
| 142 |
+
recording-side `cv2.VideoCapture` V4L2 buffer that was never flushed
|
| 143 |
+
(throttled reads + no `BUFFERSIZE=1` + default pixel format). Fixed in the rig
|
| 144 |
+
on 2026-06-27; **future recordings will not have this lag**.
|
| 145 |
+
|
| 146 |
+
The streams are stored frame-aligned by tick index, so this lag is baked in but
|
| 147 |
+
**correctable**. The reference loader compensates at load time:
|
| 148 |
+
|
| 149 |
+
```python
|
| 150 |
+
ds = ReactVideoDataset("data/motherboard", tactile_latency=15) # pairs view[i] with tactile[i+15]
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
`tactile_latency` shifts both the tactile videos and the tactile contact-scalar
|
| 154 |
+
columns; poses/views/depth are unchanged. Set `tactile_latency=0` for the raw
|
| 155 |
+
(uncompensated) data. The exact per-session value should be re-measured with
|
| 156 |
+
`camera_stream/measure_gelsight_latency.py`.
|
| 157 |
+
|
| 158 |
## Data quality
|
| 159 |
Per-task `bad_frames.json` flags `intensity_spikes`, `pose_teleports_{L,R}`, `ot_loss_{L,R}` (OptiTrack track loss). Overall flagged: motherboard 0.90 %, pushT 0.67 %. `segments.json` already excludes them.
|
| 160 |
|
examples/react_video_dataset.py
CHANGED
|
@@ -80,7 +80,7 @@ def _decode_frames(mp4_path: Path, frame_indices, depth=False):
|
|
| 80 |
class ReactVideoDataset:
|
| 81 |
def __init__(self, task_root, window_length=16, stride=1, window_step=None,
|
| 82 |
mode="segment", streams=ALL_STREAMS, skip_bad=True,
|
| 83 |
-
which_sensors="any", load_depth=False):
|
| 84 |
self.root = Path(task_root)
|
| 85 |
self.W = window_length
|
| 86 |
self.stride = stride
|
|
@@ -91,6 +91,16 @@ class ReactVideoDataset:
|
|
| 91 |
self.which = which_sensors
|
| 92 |
# depth only if requested AND present on disk for this task
|
| 93 |
self.load_depth = load_depth and (self.root / "depth").is_dir()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
self.segments = json.loads((self.root / "segments.json").read_text())["segments"]
|
| 96 |
self.bad = json.loads((self.root / "bad_frames.json").read_text())["episodes"]
|
|
@@ -116,22 +126,21 @@ class ReactVideoDataset:
|
|
| 116 |
def _build_index(self):
|
| 117 |
items = []
|
| 118 |
span = (self.W - 1) * self.stride + 1
|
|
|
|
| 119 |
if self.mode == "segment":
|
| 120 |
for s in self.segments:
|
| 121 |
ek, a, b = s["source_episode"], s["frame_range"][0], s["frame_range"][1]
|
| 122 |
start = a
|
| 123 |
-
while start + span - 1 <= b:
|
| 124 |
items.append((ek, start))
|
| 125 |
start += self.step
|
| 126 |
else: # window over whole episode
|
| 127 |
-
for s in self.segments: # reuse episode list via segments' episodes
|
| 128 |
-
pass
|
| 129 |
eps = sorted({s["source_episode"] for s in self.segments})
|
| 130 |
for ek in eps:
|
| 131 |
T = self.bad.get(ek, {}).get("n_frames", 0)
|
| 132 |
bad = self._bad_mask(ek, T) if self.skip_bad else np.zeros(T, bool)
|
| 133 |
start = 0
|
| 134 |
-
while start + span - 1 < T:
|
| 135 |
idx = range(start, start + span, self.stride)
|
| 136 |
if not (self.skip_bad and bad[list(idx)].any()):
|
| 137 |
items.append((ek, start))
|
|
@@ -143,28 +152,36 @@ class ReactVideoDataset:
|
|
| 143 |
|
| 144 |
def __getitem__(self, i):
|
| 145 |
ek, start = self.index[i]
|
|
|
|
| 146 |
idx = list(range(start, start + (self.W - 1) * self.stride + 1, self.stride))
|
|
|
|
| 147 |
vd = self._video_dir(ek)
|
| 148 |
-
out = {
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
| 150 |
date, ep = ek.split("/")
|
| 151 |
dd = self.root / "depth" / date / ep
|
| 152 |
for s in DEPTH_STREAMS:
|
| 153 |
p = dd / f"{s}.mkv"
|
| 154 |
if p.exists():
|
| 155 |
out[s] = _decode_frames(p, idx, depth=True) # (T,H,W) uint16 mm
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
| 159 |
for c in ("sensor_left_pose", "sensor_right_pose"):
|
| 160 |
-
out[c] = np.array(tbl.column(c).to_pylist(), np.float32)[
|
| 161 |
if "object_pose" in tbl.column_names:
|
| 162 |
-
out["object_pose"] = np.array(tbl.column("object_pose").to_pylist(), np.float32)[
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
out[c] = np.array(tbl.column(c).to_pylist(), np.float32)[
|
| 166 |
out["episode"] = ek
|
| 167 |
out["frame_start"] = start
|
|
|
|
| 168 |
return out
|
| 169 |
|
| 170 |
|
|
|
|
| 80 |
class ReactVideoDataset:
|
| 81 |
def __init__(self, task_root, window_length=16, stride=1, window_step=None,
|
| 82 |
mode="segment", streams=ALL_STREAMS, skip_bad=True,
|
| 83 |
+
which_sensors="any", load_depth=False, tactile_latency=0):
|
| 84 |
self.root = Path(task_root)
|
| 85 |
self.W = window_length
|
| 86 |
self.stride = stride
|
|
|
|
| 91 |
self.which = which_sensors
|
| 92 |
# depth only if requested AND present on disk for this task
|
| 93 |
self.load_depth = load_depth and (self.root / "depth").is_dir()
|
| 94 |
+
# GelSight acquisition lag (frames): tactile stream was captured
|
| 95 |
+
# `tactile_latency` frames BEFORE the view at the same index, due to a
|
| 96 |
+
# recording-side V4L2 buffer bug (fixed in the rig from 2026-06-27).
|
| 97 |
+
# When >0, the loader pairs view[i] with tactile[i+latency] (and the
|
| 98 |
+
# tactile contact scalars likewise), and trims `latency` frames from
|
| 99 |
+
# the end of each window range so the shifted index stays in bounds.
|
| 100 |
+
self.tactile_latency = int(tactile_latency)
|
| 101 |
+
self._TACT = ("tactile_left", "tactile_right")
|
| 102 |
+
self._TACT_COLS = ("tactile_left_intensity", "tactile_right_intensity",
|
| 103 |
+
"tactile_left_mixed", "tactile_right_mixed")
|
| 104 |
|
| 105 |
self.segments = json.loads((self.root / "segments.json").read_text())["segments"]
|
| 106 |
self.bad = json.loads((self.root / "bad_frames.json").read_text())["episodes"]
|
|
|
|
| 126 |
def _build_index(self):
|
| 127 |
items = []
|
| 128 |
span = (self.W - 1) * self.stride + 1
|
| 129 |
+
lat = self.tactile_latency # tactile read at idx+lat must stay in bounds
|
| 130 |
if self.mode == "segment":
|
| 131 |
for s in self.segments:
|
| 132 |
ek, a, b = s["source_episode"], s["frame_range"][0], s["frame_range"][1]
|
| 133 |
start = a
|
| 134 |
+
while start + span - 1 + lat <= b:
|
| 135 |
items.append((ek, start))
|
| 136 |
start += self.step
|
| 137 |
else: # window over whole episode
|
|
|
|
|
|
|
| 138 |
eps = sorted({s["source_episode"] for s in self.segments})
|
| 139 |
for ek in eps:
|
| 140 |
T = self.bad.get(ek, {}).get("n_frames", 0)
|
| 141 |
bad = self._bad_mask(ek, T) if self.skip_bad else np.zeros(T, bool)
|
| 142 |
start = 0
|
| 143 |
+
while start + span - 1 + lat < T:
|
| 144 |
idx = range(start, start + span, self.stride)
|
| 145 |
if not (self.skip_bad and bad[list(idx)].any()):
|
| 146 |
items.append((ek, start))
|
|
|
|
| 152 |
|
| 153 |
def __getitem__(self, i):
|
| 154 |
ek, start = self.index[i]
|
| 155 |
+
lat = self.tactile_latency
|
| 156 |
idx = list(range(start, start + (self.W - 1) * self.stride + 1, self.stride))
|
| 157 |
+
idx_tac = [r + lat for r in idx] # tactile is `lat` frames behind view
|
| 158 |
vd = self._video_dir(ek)
|
| 159 |
+
out = {}
|
| 160 |
+
for s in self.streams:
|
| 161 |
+
read_idx = idx_tac if s in self._TACT else idx # shift only tactile
|
| 162 |
+
out[s] = _decode_frames(vd / f"{s}.mp4", read_idx)
|
| 163 |
+
if self.load_depth: # depth is a view-side cam, no shift
|
| 164 |
date, ep = ek.split("/")
|
| 165 |
dd = self.root / "depth" / date / ep
|
| 166 |
for s in DEPTH_STREAMS:
|
| 167 |
p = dd / f"{s}.mkv"
|
| 168 |
if p.exists():
|
| 169 |
out[s] = _decode_frames(p, idx, depth=True) # (T,H,W) uint16 mm
|
| 170 |
+
# parquet: read a range covering both idx and idx_tac
|
| 171 |
+
lo, hi = start, idx_tac[-1]
|
| 172 |
+
tbl = pq.read_table(self._parquet(ek)).slice(lo, hi - lo + 1)
|
| 173 |
+
v_rows = [r - lo for r in idx]
|
| 174 |
+
t_rows = [r - lo for r in idx_tac]
|
| 175 |
for c in ("sensor_left_pose", "sensor_right_pose"):
|
| 176 |
+
out[c] = np.array(tbl.column(c).to_pylist(), np.float32)[v_rows]
|
| 177 |
if "object_pose" in tbl.column_names:
|
| 178 |
+
out["object_pose"] = np.array(tbl.column("object_pose").to_pylist(), np.float32)[v_rows]
|
| 179 |
+
# tactile contact scalars follow the tactile frames -> shifted rows
|
| 180 |
+
for c in self._TACT_COLS:
|
| 181 |
+
out[c] = np.array(tbl.column(c).to_pylist(), np.float32)[t_rows]
|
| 182 |
out["episode"] = ek
|
| 183 |
out["frame_start"] = start
|
| 184 |
+
out["tactile_latency"] = lat
|
| 185 |
return out
|
| 186 |
|
| 187 |
|
tasks.json
CHANGED
|
@@ -88,5 +88,15 @@
|
|
| 88 |
"with_depth": "python examples/download.py",
|
| 89 |
"middle_depth_only": "python examples/download.py --depth-cams middle"
|
| 90 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
}
|
| 92 |
}
|
|
|
|
| 88 |
"with_depth": "python examples/download.py",
|
| 89 |
"middle_depth_only": "python examples/download.py --depth-cams middle"
|
| 90 |
}
|
| 91 |
+
},
|
| 92 |
+
"tactile_latency": {
|
| 93 |
+
"frames_estimate": 15,
|
| 94 |
+
"fps": 30,
|
| 95 |
+
"seconds_estimate": 0.5,
|
| 96 |
+
"applies_to": "all recordings up to and including 2026-06-18",
|
| 97 |
+
"fixed_in_rig": "2026-06-27",
|
| 98 |
+
"cause": "recording-side cv2.VideoCapture V4L2 buffer never flushed (throttled reads + no BUFFERSIZE=1 + default pixfmt)",
|
| 99 |
+
"compensation": "ReactVideoDataset(tactile_latency=15) pairs view[i] with tactile[i+15]; shifts tactile videos + contact scalars only",
|
| 100 |
+
"note": "tactile[i] was captured ~15 frames BEFORE view[i] at the same index; streams stored frame-aligned by tick so lag is baked in but correctable."
|
| 101 |
}
|
| 102 |
}
|