(
self,
batch: Batch,
flows: Flows,
tracks: list[Tracks] | None,
model_output: ModelOutput,
model: Model,
global_step: int,
)
| 41 | |
| 42 | class VisualizerSummary(Visualizer[VisualizerSummaryCfg]): |
| 43 | def visualize( |
| 44 | self, |
| 45 | batch: Batch, |
| 46 | flows: Flows, |
| 47 | tracks: list[Tracks] | None, |
| 48 | model_output: ModelOutput, |
| 49 | model: Model, |
| 50 | global_step: int, |
| 51 | ) -> dict[str, Float[Tensor, "3 _ _"] | Float[Tensor, ""]]: |
| 52 | # For now, only support batch size 1 for visualization. |
| 53 | b, f, _, h, w = batch.videos.shape |
| 54 | assert b == 1 |
| 55 | |
| 56 | # Pick a random interval to visualize. |
| 57 | frames = torch.ones(f, dtype=torch.bool, device=batch.videos.device) |
| 58 | pairs = torch.ones(f - 1, dtype=torch.bool, device=batch.videos.device) |
| 59 | if self.cfg.num_vis_frames < f: |
| 60 | start = torch.randint(f - self.cfg.num_vis_frames, (1,)).item() |
| 61 | frames[:] = False |
| 62 | frames[start : start + self.cfg.num_vis_frames] = True |
| 63 | pairs[:] = False |
| 64 | pairs[start : start + self.cfg.num_vis_frames - 1] = True |
| 65 | |
| 66 | # Color-map the ground-truth optical flow. |
| 67 | # fwd_gt = flow_with_key(flows.forward[0, pairs]) |
| 68 | bwd_gt = flow_with_key(flows.backward[0, pairs]) |
| 69 | |
| 70 | # Color-map the pose-induced optical flow. |
| 71 | xy_flowed_backward = compute_backward_flow( |
| 72 | model_output.surfaces, |
| 73 | model_output.extrinsics, |
| 74 | model_output.intrinsics, |
| 75 | ) |
| 76 | xy, _ = sample_image_grid((h, w), batch.videos.device) |
| 77 | bwd_hat = flow_with_key((xy_flowed_backward - xy)[0, pairs]) |
| 78 | |
| 79 | # Color-map the depth. |
| 80 | depth = color_map_depth(model_output.depths[0, frames]) |
| 81 | |
| 82 | # Color-map the correspondence weights. |
| 83 | bwd_weights = apply_color_map_to_image( |
| 84 | model_output.backward_correspondence_weights[0, pairs], "gray" |
| 85 | ) |
| 86 | |
| 87 | visualization = vcat( |
| 88 | add_label(hcat(*batch.videos[0, frames]), "Video (Ground Truth)"), |
| 89 | add_label(hcat(*depth), "Depth (Predicted)"), |
| 90 | add_label(bwd_gt, "Backward Flow (Ground Truth)"), |
| 91 | add_label(bwd_hat, "Backward Flow (Predicted)"), |
| 92 | add_label(hcat(*(bwd_weights)), "Backward Correspondence Weights"), |
| 93 | ) |
| 94 | |
| 95 | return {"summary": add_border(visualization)} |
nothing calls this directly
no test coverage detected