Created
February 15, 2019 03:04
-
-
Save LiamHz/c466dbdb68736ab00ad860ddc80c3b87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DQN(nn.Module): | |
def __init__(self, input_shape, n_actions): | |
super(DQN, self).__init__() | |
self.conv = nn.Sequential( | |
nn.Conv2d(input_shape[0], 32, kernel_size=8, stride=4), | |
nn.ReLU(), | |
nn.Conv2d(32, 64, kernel_size=4, stride=2), | |
nn.ReLU(), | |
nn.Conv2d(64, 64, kernel_size=3, stride=1), | |
nn.ReLU() | |
) | |
conv_out_size = self._get_conv_out(input_shape) | |
self.fc = nn.Sequential( | |
nn.Linear(conv_out_size, 512), | |
nn.ReLU(), | |
nn.Linear(512, n_actions) | |
) | |
def _get_conv_out(self, shape): | |
o = self.conv(torch.zeros(1, *shape)) | |
return int(np.prod(o.size())) | |
def forward(self, x): | |
conv_out = self.conv(x).view(x.size()[0], -1) | |
return self.fc(conv_out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment