Return target-only DeMemWM DiT outputs
Browse files
algorithms/dememwm/models/dit.py
CHANGED
|
@@ -769,6 +769,11 @@ class DiT(nn.Module):
|
|
| 769 |
frame_memory_pose=frame_memory_pose,
|
| 770 |
image_hw=image_hw,
|
| 771 |
frame_memory_geometry=frame_memory_geometry) # (N, T, H, W, D)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 772 |
x = self.final_layer(x, c) # (N, T, H, W, patch_size ** 2 * out_channels)
|
| 773 |
# unpatchify
|
| 774 |
x = rearrange(x, "b t h w d -> (b t) h w d")
|
|
|
|
| 769 |
frame_memory_pose=frame_memory_pose,
|
| 770 |
image_hw=image_hw,
|
| 771 |
frame_memory_geometry=frame_memory_geometry) # (N, T, H, W, D)
|
| 772 |
+
if frame_memory_segments is not None:
|
| 773 |
+
target_frames = int(frame_memory_segments.get("target", 0))
|
| 774 |
+
x = x[:, :target_frames]
|
| 775 |
+
c = c[:, :target_frames]
|
| 776 |
+
T = target_frames
|
| 777 |
x = self.final_layer(x, c) # (N, T, H, W, patch_size ** 2 * out_channels)
|
| 778 |
# unpatchify
|
| 779 |
x = rearrange(x, "b t h w d -> (b t) h w d")
|
tests/test_dememwm_temporal_attention.py
CHANGED
|
@@ -129,8 +129,9 @@ class DeMemWMTemporalAttentionTests(unittest.TestCase):
|
|
| 129 |
masks = {"dynamic": torch.ones((1, 1), dtype=torch.bool)}
|
| 130 |
|
| 131 |
with torch.no_grad():
|
| 132 |
-
model(x, t, action_cond, frame_memory_segments=segments, frame_memory_masks=masks)
|
| 133 |
|
|
|
|
| 134 |
self.assertIs(spy.calls[0]["frame_memory_segments"], segments)
|
| 135 |
self.assertIs(spy.calls[0]["frame_memory_masks"], masks)
|
| 136 |
|
|
|
|
| 129 |
masks = {"dynamic": torch.ones((1, 1), dtype=torch.bool)}
|
| 130 |
|
| 131 |
with torch.no_grad():
|
| 132 |
+
out = model(x, t, action_cond, frame_memory_segments=segments, frame_memory_masks=masks)
|
| 133 |
|
| 134 |
+
self.assertEqual(tuple(out.shape), (1, 2, 1, 2, 2))
|
| 135 |
self.assertIs(spy.calls[0]["frame_memory_segments"], segments)
|
| 136 |
self.assertIs(spy.calls[0]["frame_memory_masks"], masks)
|
| 137 |
|