Skip to content

Commit

Permalink
Update to run on torch 0.4
Browse files Browse the repository at this point in the history
Trying to address two issues:
- return `action` as an item to fix runtime error
 ```
 UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
 ```
may related to: SeanNaren/deepspeech.pytorch#277

- change number of actions from global to a local one which I believe that was your intention
  • Loading branch information
tsaoyu committed Jul 16, 2018
1 parent 0f82b69 commit cd83094
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions 1.dqn.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@
" super(DQN, self).__init__()\n",
" \n",
" self.layers = nn.Sequential(\n",
" nn.Linear(env.observation_space.shape[0], 128),\n",
" nn.Linear(num_inputs, 128),\n",
" nn.ReLU(),\n",
" nn.Linear(128, 128),\n",
" nn.ReLU(),\n",
" nn.Linear(128, env.action_space.n)\n",
" nn.Linear(128, num_actions)\n",
" )\n",
" \n",
" def forward(self, x):\n",
Expand All @@ -186,7 +186,7 @@
" if random.random() > epsilon:\n",
" state = Variable(torch.FloatTensor(state).unsqueeze(0), volatile=True)\n",
" q_value = self.forward(state)\n",
" action = q_value.max(1)[1].data[0]\n",
" action = q_value.max(1)[1].item()\n",
" else:\n",
" action = random.randrange(env.action_space.n)\n",
" return action"
Expand Down

0 comments on commit cd83094

Please sign in to comment.