-
Notifications
You must be signed in to change notification settings - Fork 1
/
DQN_model.py
27 lines (24 loc) · 1.1 KB
/
DQN_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
import torch.nn as nn
import torch.nn.functional as F
class DQN(nn.Module):
def __init__(self, in_channels=4, num_actions=18):
"""
Initialize a deep Q-learning network as described in
https://storage.googleapis.com/deepmind-data/assets/papers/DeepMindNature14236Paper.pdf
Arguments:
in_channels: number of channel of input.
i.e The number of most recent frames stacked together as describe in the paper
num_actions: number of action-value to output, one-to-one correspondence to action in game.
"""
super(DQN, self).__init__()
self.conv1 = nn.Conv2d(in_channels, 32, kernel_size=8, stride=4)
self.conv2 = nn.Conv2d(32, 64, kernel_size=4, stride=2)
self.conv3 = nn.Conv2d(64, 64, kernel_size=3, stride=1)
self.fc4 = nn.Linear(7 * 7 * 64, 512)
self.fc5 = nn.Linear(512, num_actions)
def forward(self, x):
x = F.relu(self.conv1(x))
x = F.relu(self.conv2(x))
x = F.relu(self.conv3(x))
x = F.relu(self.fc4(x.view(x.size(0), -1)))
return self.fc5(x)