-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
32 lines (24 loc) · 866 Bytes
/
model.py
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
import F as F
from torch import nn
import torch.nn.functional as F
class ResBlock(nn.Module):
"""
Iniialize a residual block with two convolutions followed by batchnorm layers
"""
def __init__(self, in_size: int, hidden_size: int, out_size: int):
super().__init__()
self.conv1 = nn.Conv2d(in_size, hidden_size, 3, padding=1)
self.conv2 = nn.Conv2d(hidden_size, out_size, 3, padding=1)
self.batchnorm1 = nn.BatchNorm2d(hidden_size)
self.batchnorm2 = nn.BatchNorm2d(out_size)
def convblock(self, x):
x = F.relu(self.batchnorm1(self.conv1(x)))
x = F.relu(self.batchnorm2(self.conv2(x)))
return x
"""
Combine output with the original input
"""
def forward(self, x): return x + self.convblock(x) # skip connection
def make_net():
return nn.Sequential(
)