diff options
author | Jordan Gong <jordan.gong@protonmail.com> | 2021-04-10 22:37:21 +0800 |
---|---|---|
committer | Jordan Gong <jordan.gong@protonmail.com> | 2021-04-10 22:37:21 +0800 |
commit | 20110729ab450c84d90965f5b8930236035f093a (patch) | |
tree | fc50d9fe067d625de57bdaa2e2478daa685ad299 /models/hpm.py | |
parent | fbffa65010bb876844ca538f6de8b15dcaa9876c (diff) | |
parent | b294b715ec0de6ba94199f3b068dc828095fd2f1 (diff) |
Merge branch 'master' into python3.8python3.8
Diffstat (limited to 'models/hpm.py')
-rw-r--r-- | models/hpm.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/models/hpm.py b/models/hpm.py index 8320569..e1cdff3 100644 --- a/models/hpm.py +++ b/models/hpm.py @@ -35,8 +35,9 @@ class HorizontalPyramidMatching(nn.Module): ]) return pyramid - def forward(self, x): - n, c, h, w = x.size() + def _horizontal_pyramid_pool(self, x): + n, t, c, h, w = x.size() + x = x.view(n * t, c, h, w) feature = [] for scale, pyramid in zip(self.scales, self.pyramids): h_per_hpp = h // scale @@ -45,12 +46,23 @@ class HorizontalPyramidMatching(nn.Module): (hpp_index + 1) * h_per_hpp) x_slice = x[:, :, h_filter, :] x_slice = hpp(x_slice) - x_slice = x_slice.view(n, -1) + x_slice = x_slice.view(n, t, c) feature.append(x_slice) x = torch.stack(feature) + return x + def forward(self, f_c1_t2, f_c1_t1=None, f_c2_t2=None): + # n, t, c, h, w + f_c1_t2_ = self._horizontal_pyramid_pool(f_c1_t2) + # p, n, t, c + x = f_c1_t2_.mean(2) # p, n, c x = x @ self.fc_mat # p, n, d - return x + if self.training: + f_c1_t1_ = self._horizontal_pyramid_pool(f_c1_t1) + f_c2_t2_ = self._horizontal_pyramid_pool(f_c2_t2) + return x, (f_c1_t2_, f_c1_t1_, f_c2_t2_) + else: + return x |