diff options
author | Jordan Gong <jordan.gong@protonmail.com> | 2020-12-24 18:58:08 +0800 |
---|---|---|
committer | Jordan Gong <jordan.gong@protonmail.com> | 2020-12-24 18:58:08 +0800 |
commit | 6f6cf10def7913b8d6bc60a4092cf1b0587f15f1 (patch) | |
tree | 0cbf790ddbb4cd8354bafb5039092531e964a68a /models/layers.py | |
parent | fbbc6a2dc533c480059dd8b621ff5abef349b593 (diff) |
Implement Horizontal Pyramid Matching (HPM)
Diffstat (limited to 'models/layers.py')
-rw-r--r-- | models/layers.py | 21 |
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 |