MCPcopy Create free account
hub / github.com/drinkingcoder/FlowFormer-Official / AlternateCorrBlock

Class AlternateCorrBlock

core/corr.py:62–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60
61
62class AlternateCorrBlock:
63 def __init__(self, fmap1, fmap2, num_levels=4, radius=4):
64 self.num_levels = num_levels
65 self.radius = radius
66
67 self.pyramid = [(fmap1, fmap2)]
68 for i in range(self.num_levels):
69 fmap1 = F.avg_pool2d(fmap1, 2, stride=2)
70 fmap2 = F.avg_pool2d(fmap2, 2, stride=2)
71 self.pyramid.append((fmap1, fmap2))
72
73 def __call__(self, coords):
74 coords = coords.permute(0, 2, 3, 1)
75 B, H, W, _ = coords.shape
76 dim = self.pyramid[0][0].shape[1]
77
78 corr_list = []
79 for i in range(self.num_levels):
80 r = self.radius
81 fmap1_i = self.pyramid[0][0].permute(0, 2, 3, 1).contiguous()
82 fmap2_i = self.pyramid[i][1].permute(0, 2, 3, 1).contiguous()
83
84 coords_i = (coords / 2**i).reshape(B, 1, H, W, 2).contiguous()
85 corr, = alt_cuda_corr.forward(fmap1_i, fmap2_i, coords_i, r)
86 corr_list.append(corr.squeeze(1))
87
88 corr = torch.stack(corr_list, dim=1)
89 corr = corr.reshape(B, -1, H, W)
90 return corr / torch.sqrt(torch.tensor(dim).float())

Callers 1

forwardMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected