return F.conv2d(input, weight, bias, self.stride,
RuntimeError: Expected 4-dimensional input for 4-dimensional weight [8, 4, 3, 3], but got 1-dimensional input of size [16] instead
class QNetwork(nn.Module):
def init(self, in_channels=4, num_actions=200):
super(QNetwork, self).init()
self.conv1 = nn.Conv2d(in_channels, 8, kernel_size=3, stride=1, padding=1)
self.conv2 = nn.Conv2d(8, 16, 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)
def select_action(self, x):
with torch.no_grad():
fc5 = self.forward(x)
action_index = torch.argmax(fc5, dim=1)
return action_index.item()