| 37 | |
| 38 | # Standard Nature CNN. |
| 39 | class QNetwork(nn.Module): |
| 40 | def __init__(self, n_actions): |
| 41 | super().__init__() |
| 42 | self.conv = nn.Sequential( |
| 43 | nn.Conv2d(4, 32, kernel_size=8, stride=4), nn.ReLU(), |
| 44 | nn.Conv2d(32, 64, kernel_size=4, stride=2), nn.ReLU(), |
| 45 | nn.Conv2d(64, 64, kernel_size=3, stride=1), nn.ReLU(), |
| 46 | nn.Flatten(), |
| 47 | ) |
| 48 | self.fc = nn.Sequential( |
| 49 | nn.Linear(64 * 7 * 7, 512), nn.ReLU(), |
| 50 | nn.Linear(512, n_actions), |
| 51 | ) |
| 52 | |
| 53 | def forward(self, x): |
| 54 | # Inputs are uint8 in [0, 255]; normalize on the GPU to save bus bandwidth. |
| 55 | return self.fc(self.conv(x.float() / 255.0)) |
| 56 | |
| 57 | |
| 58 | class ReplayBuffer: |