Use wrapped pose deltas for DeMemWM dynamic scoring
Browse files
algorithms/dememwm/df_video.py
CHANGED
|
@@ -21,6 +21,7 @@ from algorithms.common.metrics import (
|
|
| 21 |
from datasets.video.memory_selection import (
|
| 22 |
_event_triggered_anchor_candidates_from_deltas,
|
| 23 |
_nearest_unique_event_anchors,
|
|
|
|
| 24 |
_select_anchor,
|
| 25 |
_select_dynamic_by_policy,
|
| 26 |
_select_revisit,
|
|
@@ -442,7 +443,8 @@ def _extend_online_event_cache(cache, latents, actions, poses, stop: int) -> Non
|
|
| 442 |
cosine = torch.where(valid_pair, cosine.clamp(-1.0, 1.0), torch.ones_like(cosine))
|
| 443 |
d_vis.index_copy_(0, curr_rows - old_stop, 1.0 - cosine)
|
| 444 |
|
| 445 |
-
|
|
|
|
| 446 |
d_act = _online_l2_new_deltas(actions, old_stop, target_stop, device)
|
| 447 |
cache["d_vis"] = _append_online_event_values(cache["d_vis"], d_vis, old_stop, target_stop, capacity)
|
| 448 |
cache["d_pose"] = _append_online_event_values(cache["d_pose"], d_pose, old_stop, target_stop, capacity)
|
|
|
|
| 21 |
from datasets.video.memory_selection import (
|
| 22 |
_event_triggered_anchor_candidates_from_deltas,
|
| 23 |
_nearest_unique_event_anchors,
|
| 24 |
+
_pose_delta_values,
|
| 25 |
_select_anchor,
|
| 26 |
_select_dynamic_by_policy,
|
| 27 |
_select_revisit,
|
|
|
|
| 443 |
cosine = torch.where(valid_pair, cosine.clamp(-1.0, 1.0), torch.ones_like(cosine))
|
| 444 |
d_vis.index_copy_(0, curr_rows - old_stop, 1.0 - cosine)
|
| 445 |
|
| 446 |
+
pose_frames = np.arange(old_stop, target_stop, dtype=np.int64)
|
| 447 |
+
d_pose = _pose_delta_values(poses, pose_frames, max(0, old_stop - 1), target_stop, device)
|
| 448 |
d_act = _online_l2_new_deltas(actions, old_stop, target_stop, device)
|
| 449 |
cache["d_vis"] = _append_online_event_values(cache["d_vis"], d_vis, old_stop, target_stop, capacity)
|
| 450 |
cache["d_pose"] = _append_online_event_values(cache["d_pose"], d_pose, old_stop, target_stop, capacity)
|
datasets/video/memory_selection.py
CHANGED
|
@@ -13,6 +13,8 @@ _FOV_NUM_POINTS = 10000
|
|
| 13 |
_FOV_RADIUS = 30.0
|
| 14 |
_FOV_HALF_H = 105.0 / 2.0
|
| 15 |
_FOV_HALF_V = 75.0 / 2.0
|
|
|
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
def cfg_get(cfg, key: str, default=None):
|
|
@@ -413,6 +415,30 @@ def _frame_l2_deltas(values, frames: np.ndarray, history_start: int, stop: int,
|
|
| 413 |
return deltas
|
| 414 |
|
| 415 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 416 |
def _robust_z(values: torch.Tensor, eps: float = 1e-6) -> torch.Tensor:
|
| 417 |
if values.numel() == 0:
|
| 418 |
return values
|
|
@@ -534,7 +560,7 @@ def _event_triggered_anchor_candidates(
|
|
| 534 |
rows = torch.as_tensor(frames[valid_vis] - (history_start + 1), device=vectors.device, dtype=torch.long)
|
| 535 |
d_vis[torch.as_tensor(valid_vis, device=vectors.device, dtype=torch.bool)] = consecutive_vis.index_select(0, rows)
|
| 536 |
|
| 537 |
-
d_pose =
|
| 538 |
d_act = _frame_l2_deltas(actions, frames, history_start, stop, vectors.device)
|
| 539 |
return _event_triggered_anchor_candidates_from_deltas(frames, d_vis, d_pose, d_act, cfg)
|
| 540 |
|
|
|
|
| 13 |
_FOV_RADIUS = 30.0
|
| 14 |
_FOV_HALF_H = 105.0 / 2.0
|
| 15 |
_FOV_HALF_V = 75.0 / 2.0
|
| 16 |
+
_POSE_DISTANCE_SCALE = 30.0
|
| 17 |
+
_ANGLE_DISTANCE_SCALE = 180.0
|
| 18 |
|
| 19 |
|
| 20 |
def cfg_get(cfg, key: str, default=None):
|
|
|
|
| 415 |
return deltas
|
| 416 |
|
| 417 |
|
| 418 |
+
def _pose_delta_values(poses, frames: np.ndarray, history_start: int, stop: int, device) -> torch.Tensor:
|
| 419 |
+
deltas = torch.zeros((len(frames),), device=device, dtype=torch.float32)
|
| 420 |
+
if poses is None or len(frames) == 0:
|
| 421 |
+
return deltas
|
| 422 |
+
|
| 423 |
+
length = len(poses)
|
| 424 |
+
value_start = max(0, min(int(history_start), length))
|
| 425 |
+
value_stop = max(value_start, min(int(stop), length))
|
| 426 |
+
if value_stop - value_start <= 1:
|
| 427 |
+
return deltas
|
| 428 |
+
|
| 429 |
+
pose_tensor = _as_pose_tensor(poses[value_start:value_stop]).to(device=device, dtype=torch.float32)
|
| 430 |
+
# Consecutive pose novelty keeps yaw/pitch in degrees modulo 360.
|
| 431 |
+
spatial = torch.linalg.vector_norm(pose_tensor[1:, :3] - pose_tensor[:-1, :3], dim=-1) / _POSE_DISTANCE_SCALE
|
| 432 |
+
angular = torch.linalg.vector_norm(_wrap_degrees(pose_tensor[1:, 3:5] - pose_tensor[:-1, 3:5]), dim=-1) / _ANGLE_DISTANCE_SCALE
|
| 433 |
+
consecutive = spatial + angular
|
| 434 |
+
|
| 435 |
+
valid = (frames >= value_start + 1) & (frames < value_stop)
|
| 436 |
+
if bool(valid.any()):
|
| 437 |
+
rows = torch.as_tensor(frames[valid] - (value_start + 1), device=device, dtype=torch.long)
|
| 438 |
+
deltas[torch.as_tensor(valid, device=device, dtype=torch.bool)] = consecutive.index_select(0, rows)
|
| 439 |
+
return deltas
|
| 440 |
+
|
| 441 |
+
|
| 442 |
def _robust_z(values: torch.Tensor, eps: float = 1e-6) -> torch.Tensor:
|
| 443 |
if values.numel() == 0:
|
| 444 |
return values
|
|
|
|
| 560 |
rows = torch.as_tensor(frames[valid_vis] - (history_start + 1), device=vectors.device, dtype=torch.long)
|
| 561 |
d_vis[torch.as_tensor(valid_vis, device=vectors.device, dtype=torch.bool)] = consecutive_vis.index_select(0, rows)
|
| 562 |
|
| 563 |
+
d_pose = _pose_delta_values(poses, frames, history_start, stop, vectors.device)
|
| 564 |
d_act = _frame_l2_deltas(actions, frames, history_start, stop, vectors.device)
|
| 565 |
return _event_triggered_anchor_candidates_from_deltas(frames, d_vis, d_pose, d_act, cfg)
|
| 566 |
|