summaryrefslogtreecommitdiff
path: root/models/hpm.py
diff options
context:
space:
mode:
authorJordan Gong <jordan.gong@protonmail.com>2021-04-10 22:38:23 +0800
committerJordan Gong <jordan.gong@protonmail.com>2021-04-10 22:38:23 +0800
commitf7df51490f9c3cc932672493e6c91595686df9ce (patch)
tree04975117a0f4a6b0d559a38091aba1db51a7a048 /models/hpm.py
parent5e00cd7de1729db12329e793a4e84b6c7900a948 (diff)
parent20110729ab450c84d90965f5b8930236035f093a (diff)
Merge branch 'python3.8' into python3.7python3.7
Diffstat (limited to 'models/hpm.py')
-rw-r--r--models/hpm.py20
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