-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbottleneckblock.py
More file actions
33 lines (27 loc) · 896 Bytes
/
bottleneckblock.py
File metadata and controls
33 lines (27 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import torch.nn as nn
from torch import Tensor
from .activations import ACTIVATION_FROM_NAME
class BottleneckBlock(nn.Module):
def __init__(
self,
in_channels: int,
out_channels: int,
*,
filter_size: int,
activation: str = "ReLU",
) -> None:
super().__init__()
activation_layer = ACTIVATION_FROM_NAME[activation]
self.model = nn.Sequential(
nn.Conv2d(
in_channels, out_channels, kernel_size=filter_size, padding="same"
),
activation_layer(inplace=True),
nn.Conv2d(
out_channels, out_channels, kernel_size=filter_size, padding="same"
),
activation_layer(inplace=True),
nn.BatchNorm2d(num_features=out_channels),
)
def forward(self, x: Tensor) -> Tensor:
return self.model(x)