diff options
author | Jordan Gong <jordan.gong@protonmail.com> | 2020-12-23 18:59:08 +0800 |
---|---|---|
committer | Jordan Gong <jordan.gong@protonmail.com> | 2020-12-23 18:59:08 +0800 |
commit | 96f345d25237c7e616ea5f524a2fc2d340ed8aff (patch) | |
tree | 9791c394d147f39d45ecab2a1ea5f83b396f3568 /models/layers.py | |
parent | 74a3df70a47630b7e95abc09197d23de9b81d4de (diff) |
Split modules to different files
Diffstat (limited to 'models/layers.py')
-rw-r--r-- | models/layers.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/models/layers.py b/models/layers.py new file mode 100644 index 0000000..e737df2 --- /dev/null +++ b/models/layers.py @@ -0,0 +1,27 @@ +from typing import Union, Tuple + +import torch +import torch.nn as nn +import torch.nn.functional as F + + +class FocalConv2d(nn.Module): + def __init__( + self, + in_channels: int, + out_channels: int, + kernel_size: Union[int, Tuple[int, int]], + halving: int, + **kwargs + ): + super(FocalConv2d, self).__init__() + self.halving = halving + self.conv = nn.Conv2d(in_channels, out_channels, kernel_size, + bias=False, **kwargs) + + def forward(self, x): + h = x.size(2) + split_size = h // 2 ** self.halving + z = x.split(split_size, dim=2) + z = torch.cat([self.conv(_) for _ in z], dim=2) + return F.leaky_relu(z, inplace=True) |