-
Notifications
You must be signed in to change notification settings - Fork 2
/
model.py
44 lines (32 loc) · 1.38 KB
/
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
37
38
39
40
41
42
43
44
import torch.nn as nn
import torch.nn.functional as F
class Model(nn.Module):
def __init__(self, action_space, in_channels=3, num_features=4):
super(Model, self).__init__()
self.action_space = action_space
self.main = nn.Sequential(
# in_channels, out_channels, kernel_size, stride, padding
nn.Conv2d(in_channels, num_features, 4,
stride=2, padding=1, bias=False),
nn.ELU(inplace=True),
nn.Conv2d(num_features, num_features * 2, 4,
stride=2, padding=1, bias=False),
nn.ELU(inplace=True),
nn.Conv2d(num_features * 2, num_features * 4,
4, stride=2, padding=1, bias=False),
nn.ELU(inplace=True),
nn.Conv2d(num_features * 4, num_features * 8,
4, stride=2, padding=1, bias=False),
nn.ELU(inplace=True),
nn.Conv2d(num_features * 8, num_features *
16, 4, stride=2, padding=1, bias=False),
nn.ELU(inplace=True),
nn.Conv2d(num_features * 16, self.action_space, 4,
stride=1, padding=0, bias=False),
nn.Softmax(1)
)
def forward(self, input):
main = self.main(input)
return main
def count_parameters(self):
return sum(p.numel() for p in self.parameters())