MCPcopy Create free account
hub / github.com/dcharatan/flowmap / forward

Method forward

flowmap/flow/flow_predictor_raft.py:29–57  ·  view source on GitHub ↗
(
        self,
        videos: Float[Tensor, "batch frame 3 height width"],
    )

Source from the content-addressed store, hash-verified

27 self.raft = raft_large(weights=Raft_Large_Weights.DEFAULT)
28
29 def forward(
30 self,
31 videos: Float[Tensor, "batch frame 3 height width"],
32 ) -> Float[Tensor, "batch frame-1 height width 2"]:
33 source, target, b, f = split_videos(videos)
34
35 # RAFT seems to be unhappy with large batch sizes.
36 bar = (
37 partial(tqdm, desc="Computing RAFT flow")
38 if self.cfg.show_progress_bar
39 else lambda x: x
40 )
41 flow = [
42 self.raft(
43 source_chunk * 2 - 1,
44 target_chunk * 2 - 1,
45 num_flow_updates=self.cfg.num_flow_updates,
46 )[-1]
47 for source_chunk, target_chunk in zip(
48 bar(source.split(self.cfg.max_batch_size)),
49 target.split(self.cfg.max_batch_size),
50 )
51 ]
52 flow = torch.cat(flow)
53
54 # Normalize the optical flow.
55 _, _, h, w = source.shape
56 wh = torch.tensor((w, h), dtype=torch.float32, device=flow.device)
57 return rearrange(flow, "(b f) xy h w -> b f h w xy", b=b, f=f - 1) / wh

Callers

nothing calls this directly

Calls 2

split_videosFunction · 0.85
catMethod · 0.80

Tested by

no test coverage detected