-
Notifications
You must be signed in to change notification settings - Fork 10
/
model.py
34 lines (28 loc) · 1.07 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
import torch.nn as nn
import copy
# based on pytorch tutorial by yfeng997: https://github.com/yfeng997/MadMario/blob/master/neural.py
class DDQN(nn.Module):
def __init__(self, input_dim, output_dim):
super().__init__()
c, h, w = input_dim
self.online = nn.Sequential(
nn.Conv2d(in_channels=c, out_channels=16, kernel_size=4, stride=1),
nn.ReLU(),
nn.Conv2d(in_channels=16, out_channels=32, kernel_size=4, stride=1),
nn.ReLU(),
nn.Conv2d(in_channels=32, out_channels=32, kernel_size=2, stride=1),
nn.ReLU(),
nn.Flatten(),
nn.Linear(3744, 512),
nn.ReLU(),
nn.Linear(512, output_dim)
)
self.target = copy.deepcopy(self.online)
# Q_target parameters are frozen.
for p in self.target.parameters():
p.requires_grad = False
def forward(self, input, model):
if model == "online":
return self.online(input)
elif model == "target":
return self.target(input)