Thread DeMemWM frame memory pose metadata
Browse files
algorithms/dememwm/models/diffusion.py
CHANGED
|
@@ -171,9 +171,13 @@ class Diffusion(nn.Module):
|
|
| 171 |
except:
|
| 172 |
pass
|
| 173 |
t = t.permute(1,0)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
model_kwargs = {
|
| 175 |
"current_frame": current_frame,
|
| 176 |
-
"pose_cond": pose_cond,
|
| 177 |
"mode": mode,
|
| 178 |
"reference_length": reference_length,
|
| 179 |
"frame_idx": frame_idx,
|
|
|
|
| 171 |
except:
|
| 172 |
pass
|
| 173 |
t = t.permute(1,0)
|
| 174 |
+
if frame_memory_segments is not None and frame_memory_pose is not None:
|
| 175 |
+
# Algorithm preprocessing keeps packed metadata as T_all x B x 5;
|
| 176 |
+
# DiT receives the same batch-first layout as x, t, and actions.
|
| 177 |
+
frame_memory_pose = frame_memory_pose.permute(1,0,2)
|
| 178 |
model_kwargs = {
|
| 179 |
"current_frame": current_frame,
|
| 180 |
+
"pose_cond": None if frame_memory_segments is not None else pose_cond,
|
| 181 |
"mode": mode,
|
| 182 |
"reference_length": reference_length,
|
| 183 |
"frame_idx": frame_idx,
|
tests/test_dememwm_diffusion.py
CHANGED
|
@@ -106,6 +106,54 @@ class DeMemWMDiffusionTargetOnlyTests(unittest.TestCase):
|
|
| 106 |
self.assertEqual(tuple(x_pred.shape), tuple(x.shape))
|
| 107 |
self.assertEqual(tuple(loss.shape), tuple(x.shape))
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
def test_posterior_and_sample_steps_return_target_frames_for_frame_memory(self):
|
| 110 |
torch.manual_seed(0)
|
| 111 |
x, action_cond, _, segments = _packed_inputs()
|
|
|
|
| 106 |
self.assertEqual(tuple(x_pred.shape), tuple(x.shape))
|
| 107 |
self.assertEqual(tuple(loss.shape), tuple(x.shape))
|
| 108 |
|
| 109 |
+
def test_frame_memory_pose_is_batch_first_and_separate_from_pose_cond(self):
|
| 110 |
+
torch.manual_seed(0)
|
| 111 |
+
diffusion = _make_diffusion(output_frames=2)
|
| 112 |
+
x = torch.zeros((5, 2, 1, 1, 1), dtype=torch.float32)
|
| 113 |
+
action_cond = torch.zeros((5, 2, 3), dtype=torch.float32)
|
| 114 |
+
noise_levels = torch.zeros((5, 2), dtype=torch.long)
|
| 115 |
+
pose_cond = torch.full((5, 2, 5), 99.0, dtype=torch.float32)
|
| 116 |
+
frame_memory_pose = torch.arange(5 * 2 * 5, dtype=torch.float32).view(5, 2, 5)
|
| 117 |
+
image_hw = torch.tensor([[360, 640], [720, 1280]], dtype=torch.long)
|
| 118 |
+
segments = {"target": 2, "anchor": 1, "dynamic": 1, "revisit": 1}
|
| 119 |
+
|
| 120 |
+
diffusion(
|
| 121 |
+
x,
|
| 122 |
+
action_cond,
|
| 123 |
+
pose_cond,
|
| 124 |
+
noise_levels=noise_levels,
|
| 125 |
+
reference_length=0,
|
| 126 |
+
frame_memory_segments=segments,
|
| 127 |
+
frame_memory_pose=frame_memory_pose,
|
| 128 |
+
image_hw=image_hw,
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
kwargs = diffusion.model.calls[0]["kwargs"]
|
| 132 |
+
self.assertIsNone(kwargs["pose_cond"])
|
| 133 |
+
self.assertEqual(tuple(kwargs["frame_memory_pose"].shape), (2, 5, 5))
|
| 134 |
+
self.assertTrue(torch.equal(kwargs["frame_memory_pose"], frame_memory_pose.permute(1, 0, 2)))
|
| 135 |
+
self.assertIs(kwargs["image_hw"], image_hw)
|
| 136 |
+
|
| 137 |
+
def test_baseline_pose_cond_still_reaches_dit_batch_first(self):
|
| 138 |
+
torch.manual_seed(0)
|
| 139 |
+
diffusion = _make_diffusion()
|
| 140 |
+
x = torch.zeros((5, 2, 1, 1, 1), dtype=torch.float32)
|
| 141 |
+
action_cond = torch.zeros((5, 2, 3), dtype=torch.float32)
|
| 142 |
+
noise_levels = torch.zeros((5, 2), dtype=torch.long)
|
| 143 |
+
pose_cond = torch.arange(5 * 2 * 5, dtype=torch.float32).view(5, 2, 5)
|
| 144 |
+
|
| 145 |
+
diffusion(
|
| 146 |
+
x,
|
| 147 |
+
action_cond,
|
| 148 |
+
pose_cond,
|
| 149 |
+
noise_levels=noise_levels,
|
| 150 |
+
reference_length=0,
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
kwargs = diffusion.model.calls[0]["kwargs"]
|
| 154 |
+
self.assertTrue(torch.equal(kwargs["pose_cond"], pose_cond.permute(1, 0, 2)))
|
| 155 |
+
self.assertNotIn("frame_memory_pose", kwargs)
|
| 156 |
+
|
| 157 |
def test_posterior_and_sample_steps_return_target_frames_for_frame_memory(self):
|
| 158 |
torch.manual_seed(0)
|
| 159 |
x, action_cond, _, segments = _packed_inputs()
|