summaryrefslogtreecommitdiff
path: root/models/layers.py
diff options
context:
space:
mode:
authorJordan Gong <jordan.gong@protonmail.com>2020-12-24 18:58:08 +0800
committerJordan Gong <jordan.gong@protonmail.com>2020-12-24 18:58:08 +0800
commit6f6cf10def7913b8d6bc60a4092cf1b0587f15f1 (patch)
tree0cbf790ddbb4cd8354bafb5039092531e964a68a /models/layers.py
parentfbbc6a2dc533c480059dd8b621ff5abef349b593 (diff)
Implement Horizontal Pyramid Matching (HPM)
Diffstat (limited to 'models/layers.py')
-rw-r--r--models/layers.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/models/layers.py b/models/layers.py
index 2dc87a1..9b17205 100644
--- a/models/layers.py
+++ b/models/layers.py
@@ -117,3 +117,24 @@ class BasicConv1d(nn.Module):
def forward(self, x):
return self.conv(x)
+
+
+class HorizontalPyramidPooling(BasicConv2d):
+ def __init__(
+ self,
+ in_channels: int,
+ out_channels: int,
+ kernel_size: Union[int, Tuple[int, int]] = 1,
+ use_avg_pool: bool = False,
+ **kwargs
+ ):
+ super().__init__(in_channels, out_channels, kernel_size, **kwargs)
+ if use_avg_pool:
+ self.pool = nn.AdaptiveAvgPool2d(1)
+ else:
+ self.pool = nn.AdaptiveMaxPool2d(1)
+
+ def forward(self, x):
+ x = self.pool(x)
+ x = super().forward(x)
+ return x