|
| 1 | +<!-- |
| 2 | +Copyright 2018 Google LLC. All Rights Reserved. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +============================================================================== |
| 16 | +--> |
| 17 | + |
| 18 | +<!doctype html> |
| 19 | + |
| 20 | +<head> |
| 21 | + <meta charset="UTF-8"> |
| 22 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 23 | + <link rel="stylesheet" href="../shared/tfjs-examples.css" /> |
| 24 | +</head> |
| 25 | + |
| 26 | +<style> |
| 27 | + #load-model-div { |
| 28 | + margin-top: 10px; |
| 29 | + margin-bottom: 10px; |
| 30 | + } |
| 31 | + |
| 32 | + #reset { |
| 33 | + margin-left: 100px; |
| 34 | + } |
| 35 | + |
| 36 | + #show-q-values-div { |
| 37 | + margin-top: 5px; |
| 38 | + } |
| 39 | + |
| 40 | + #game-status-div { |
| 41 | + margin-top: 15px; |
| 42 | + } |
| 43 | +</style> |
| 44 | + |
| 45 | +<body> |
| 46 | + <div class='tfjs-example-container centered-container'> |
| 47 | + <section class='title-area'> |
| 48 | + <h1>TensorFlow.js Reinforcement Learning: Snake DQN</h1> |
| 49 | + <p class='subtitle'>Deep Q-Network for the Snake Game</p> |
| 50 | + </section> |
| 51 | + <section> |
| 52 | + <p class='section-head'>Description</p> |
| 53 | + <p> |
| 54 | + This page loads a trained Deep Q-Network (DQN) and use it to play the |
| 55 | + snake game. |
| 56 | + The training is done in Node.js using <a href="https://github.com/tensorflow/tfjs-node">tfjs-node</a>. |
| 57 | + See <a href="https://github.com/tensorflow/tfjs-examples/blob/master/snake-dqn/train.js">train.js</a>. |
| 58 | + </p> |
| 59 | + </section> |
| 60 | + <section> |
| 61 | + <p class='section-head'>Algorithm</p> |
| 62 | + <p> |
| 63 | + A <a href="https://en.wikipedia.org/wiki/Q-learning#Variants">DQN</a> is trained to estimate the value of actions given the current game state. |
| 64 | + The DQN is a 2D convolutional network. See <a href="https://github.com/tensorflow/tfjs-examples/blob/master/snake-dqn/dqn.js">dqn.js</a>. |
| 65 | + The epsilon-greedy algorithm is used to balance exploration and exploitation during training. |
| 66 | + </p> |
| 67 | + </section> |
| 68 | + |
| 69 | + <section> |
| 70 | + <div id="load-model-div"> |
| 71 | + <button id="load-hosted-model" width="200px" disabled>Load hosted model</button> |
| 72 | + </div> |
| 73 | + |
| 74 | + <div> |
| 75 | + <button id="auto-play-stop" disabled>Auto Play</button> |
| 76 | + <button id="step" disabled>Step</button> |
| 77 | + <button id="reset" disabled>Reset</button> |
| 78 | + </div> |
| 79 | + <div id="show-q-values-div"> |
| 80 | + <input type="checkbox" id="show-q-values" checked> |
| 81 | + <span>Show Q-values</span> |
| 82 | + </div> |
| 83 | + <div id="game-status-div"> |
| 84 | + <span id="game-status">Game started.</span> |
| 85 | + </div> |
| 86 | + <div> |
| 87 | + <canvas id="game-canvas" height="400px" width="400px"></canvas> |
| 88 | + </div> |
| 89 | + </section> |
| 90 | + |
| 91 | + </div> |
| 92 | + |
| 93 | +</body> |
| 94 | + |
| 95 | +<script src="index.js"></script> |
0 commit comments