-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathmodel.py
36 lines (28 loc) · 1000 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
33
34
35
36
from torch import nn
import torch.nn.functional as F
import torch
from utils import make_layers
class activation():
def __init__(self, act_type, negative_slope=0.2, inplace=True):
super().__init__()
self._act_type = act_type
self.negative_slope = negative_slope
self.inplace = inplace
def __call__(self, input):
if self._act_type == 'leaky':
return F.leaky_relu(input, negative_slope=self.negative_slope, inplace=self.inplace)
elif self._act_type == 'relu':
return F.relu(input, inplace=self.inplace)
elif self._act_type == 'sigmoid':
return torch.sigmoid(input)
else:
raise NotImplementedError
class ED(nn.Module):
def __init__(self, encoder, decoder):
super().__init__()
self.encoder = encoder
self.decoder = decoder
def forward(self, input):
state = self.encoder(input)
output = self.decoder(state)
return output