Adding CNN layers

Now that we understand the basic premise behind CNN layers, it's time to take an in-depth look at how they work. Open up code example, which can be found in the Chapter_7_DQN_CNN.py file, and follow these steps:

  1. At this point, the only code we need to focus on is for a new class called CnnDQN, as shown here:
class CnnDQN(nn.Module): def __init__(self, input_shape, num_actions):   super(CnnDQN, self).__init__()   self.input_shape = input_shape   self.num_actions = num_actions   self.features = 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())   self.fc = nn.Sequential( nn.Linear(self.feature_size(), ...

Get Hands-On Reinforcement Learning for Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.