Skip to content

Commit

Permalink
Merge pull request #26 from thibo73800/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
thibo73800 authored Jun 27, 2018
2 parents e3aa6f4 + fe5bc82 commit 678ed4f
Show file tree
Hide file tree
Showing 46 changed files with 2,734 additions and 227 deletions.
2 changes: 1 addition & 1 deletion demo/dist/metacar.min.js

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions demo/webapp/ddpg-traffic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Metacar: Continous control in traffic</title>
<link rel="icon" href="/public/img/icon.png">
<link rel="stylesheet" href="/public/css/general.css">
<link href="https://fonts.googleapis.com/css?family=Tajawal" rel="stylesheet">
</head>
<body>

<header>
<div class="header_container">
<h1><a href="/">Metacar</a></h1>
<a href="https://github.com/thibo73800/metacar"><img src="/public/img/github-logo.png" /></a>
</div>
</header>

<div class="canvas_container">
<!--
You just have to add a div with an ID as bellow and include the js to start
using metacar. -->
<div class="canvas" id="canvas"></div>
</div>

<div class="body_container">
<h3 id="trainingProgress"></h3>
<h3 style="float: left" >Current state (Lidar points)</h3><br><br><br>
<div id="realtime_viewer" style="float: left"></div>
<p>
The algorithm is based on the following papers:
<ul style="margin:0;">
<li><b>Deep Deterministic Policy Gradients (DDPG): <a href="https://arxiv.org/abs/1509.02971">paper</a></b> </li>
<li><b>Parameter Space Noise for Exploration</b>: <a href="https://blog.openai.com/better-exploration-with-parameter-noise/">paper</a> </li>
</ul>
<br>
You can use the <b>arrow keys</b> to control the car by yourself.<br><br>

The motion control is based on two continuous values for the throttle and steering angle of the car.

<br><br>The left window gives you an overview of what the autonomous vehicle (in red) sees.<br><br>

You can find the code of this demo <a href="https://github.com/thibo73800/metacar/tree/master/demo/webapp/public/js/ddpg/">here</a> and <a href="https://github.com/thibo73800/metacar/tree/master/demo/webapp/public/js/ddpg-traffic/">here</a>.
</p>
</div>

<br>
<div class="body_container" id="statContainer" style="position:relative"></div>

<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/4.7.1/pixi.min.js"></script>
<script src="/dist/metacar.min.js"></script>

<script type="text/javascript" src="/public/js/utils.js"></script>
<script type="text/javascript" src="/public/js/viewer.js"></script>

<script type="text/javascript" src="/public/js/ddpg/models.js"></script>
<script type="text/javascript" src="/public/js/ddpg/memory.js"></script>
<script type="text/javascript" src="/public/js/ddpg/prioritized_memory.js"></script>
<script type="text/javascript" src="/public/js/ddpg/noise.js"></script>
<script type="text/javascript" src="/public/js/ddpg/ddpg.js"></script>
<script type="text/javascript" src="/public/js/ddpg/ddpg_agent.js"></script>
<script type="text/javascript" src="/public/js/ddpg-traffic/index.js"></script>
</body>
</html>
66 changes: 66 additions & 0 deletions demo/webapp/ddpg.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Metacar: Continous control</title>
<link rel="icon" href="/public/img/icon.png">
<link rel="stylesheet" href="/public/css/general.css">
<link href="https://fonts.googleapis.com/css?family=Tajawal" rel="stylesheet">
</head>
<body>

<header>
<div class="header_container">
<h1><a href="/">Metacar</a></h1>
<a href="https://github.com/thibo73800/metacar"><img src="/public/img/github-logo.png" /></a>
</div>
</header>

<div class="canvas_container">
<!--
You just have to add a div with an ID as bellow and include the js to start
using metacar. -->
<div class="canvas" id="canvas"></div>
</div>

<div class="body_container">
<h3 id="trainingProgress"></h3>
<h3 style="float: left" >Current state (Lidar points)</h3><br><br><br>
<div id="realtime_viewer" style="float: left"></div>
<p>
The algorithm is based on the following papers:
<ul style="margin:0;">
<li><b>Deep Deterministic Policy Gradients (DDPG): <a href="https://arxiv.org/abs/1509.02971">paper</a></b> </li>
<li><b>Parameter Space Noise for Exploration</b>: <a href="https://blog.openai.com/better-exploration-with-parameter-noise/">paper</a> </li>
</ul>
<br>
You can use the <b>arrow keys</b> to control the car by yourself.<br><br>

The motion control is based on two continuous values for the throttle and steering angle of the car.

<br><br>The left window gives you an overview of what the autonomous vehicle (in red) sees.<br><br>

You can find the code of this demo <a href="https://github.com/thibo73800/metacar/tree/master/demo/webapp/public/js/ddpg/">here</a>.
</p>
</div>

<br>
<div class="body_container" id="statContainer" style="position:relative"></div>

<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/4.7.1/pixi.min.js"></script>
<script src="/dist/metacar.min.js"></script>

<script type="text/javascript" src="/public/js/utils.js"></script>
<script type="text/javascript" src="/public/js/viewer.js"></script>

<script type="text/javascript" src="/public/js/ddpg/models.js"></script>
<script type="text/javascript" src="/public/js/ddpg/prioritized_memory.js"></script>
<script type="text/javascript" src="/public/js/ddpg/memory.js"></script>
<script type="text/javascript" src="/public/js/ddpg/noise.js"></script>
<script type="text/javascript" src="/public/js/ddpg/ddpg.js"></script>
<script type="text/javascript" src="/public/js/ddpg/ddpg_agent.js"></script>
<script type="text/javascript" src="/public/js/ddpg/index.js"></script>
</body>
</html>
53 changes: 39 additions & 14 deletions demo/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,45 +37,70 @@ <h3>Check out examples of algorithms created with <b>metacar</b></h3>
<br><br><br>

<div class="level_link_box" style="height: 300px;">
<a href="/level0.html"><img class="floatleft" src="/public/img/level0.png" /></a>
<a href="/qtable.html"><img class="floatleft" src="/public/img/level0.png" /></a>
<h4>
<br><a href="/level0.html">Q-learning with table</a>
<br><a href="/qtable.html">Discrete Actions</a>
</h4>
<p>
Algorithm: <b>Q-learning with table</b> <br><br>
In this example, the goal is to demonstrate a simple working example of a reinforcement learning
algorithm using the metacar environment. You can check out
<a href="/level0.html">the demo</a> or take a look at the <a href="#">medium tutorial</a>.
<a href="/qtable.html">the demo</a> or take a look at the <a href="#">medium tutorial</a>.
</p>
</div>


<div class="level_link_box" style="height: 298px;">
<a href="/level1.html"><img class="floatright" src="/public/img/level1.png" /></a>
<a href="/policy.html"><img class="floatright" src="/public/img/level1.png" /></a>
<h4>
<br><a href="/level1.html">Policy Monte carlo</a>
<br><a href="/policy.html">Discrete Actions in traffic</a>
</h4>
<p>
Here is an axample of a policy gradient algorithm based on Monte Carlo exploration.
The neural network is build using <a href="http://js.tensorflow.org">tensorflow.js</a>. Check out <a href="/level1.html"> the demo</a>.
Algorithm: <b>Policy gradient algorithm based on Monte Carlo exploration (REINFORCE).</b> <br><br>

The neural network is build using <a href="http://js.tensorflow.org">tensorflow.js</a>. Check out <a href="/policy.html"> the demo</a>.
<br><br>
</p>
</div>

<div class="level_link_box" style="height: 312px;">
<a href="/level2.html"><img class="floatleft" src="/public/img/level2.png" /></a>
<div class="level_link_box" style="height: 263px;">
<a href="/ddpg.html"><img width="393px" class="floatleft" src="/public/img/ddpg.png" /></a>
<h4>
<br><a href="/level2.html">Full control</a>
<br><a href="/ddpg.html">Continous Actions</a>
</h4>
<br>
<ul style="margin:0;">
<li><b>Deep Deterministic Policy Gradients (DDPG): <a href="https://arxiv.org/abs/1509.02971">paper</a></b> </li>
<li><b>Parameter Space Noise for Exploration</b>: <a href="https://blog.openai.com/better-exploration-with-parameter-noise/">paper</a> </li>
</ul>

<p>
This level is not solved yet (working on it). However, you can <a href="https://github.com/thibo73800/metacar/blob/master/CONTRIBUTE.md">contribute</a> to the project by solving it and sharing your implementation!<br><br>
<br><br>
The control is based on two continuous values for the throttle and steering angle of the car.
The model is made using <a href="http://js.tensorflow.org">tensorflow.js</a>
</p>
</div>


<div class="level_link_box" style="height: 263px;">
<a href="/ddpg-traffic.html"><img width="366px" class="floatright" src="/public/img/ddpg-traffic.png" /></a>
<h4>
<br><a href="/ddpg-traffic.html">Continous Actions in traffic</a>
</h4>
<br>
<ul style="margin:0;">
<li><b>Deep Deterministic Policy Gradients (DDPG): <a href="https://arxiv.org/abs/1509.02971">paper</a></b> </li>
<li><b>Parameter Space Noise for Exploration</b>: <a href="https://blog.openai.com/better-exploration-with-parameter-noise/">paper</a> </li>
</ul>
<p>
The control is based on two continuous values for the throttle and steering angle of the car.
The model is made using <a href="http://js.tensorflow.org">tensorflow.js</a>
<br><br>
</p>
</div>



<div class="level_link_box" style="height: 261px;">
<a href="/editor.html"><img class="floatright" src="/public/img/editor.png" /></a>
<a href="/editor.html"><img class="floatleft" src="/public/img/editor.png" /></a>
<h4>
<br><a href="/editor.html">Create your own level!</a>
</h4>
Expand Down
47 changes: 0 additions & 47 deletions demo/webapp/level2.html

This file was deleted.

9 changes: 5 additions & 4 deletions demo/webapp/level1.html → demo/webapp/policy.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<title>Metacar: Policy gradient demo</title>
<title>Metacar: Discrete Actions in traffic.</title>
<link rel="icon" href="/public/img/icon.png">
<link rel="stylesheet" href="/public/css/general.css">
<link href="https://fonts.googleapis.com/css?family=Tajawal" rel="stylesheet">
Expand All @@ -25,7 +25,7 @@ <h1><a href="/">Metacar</a></h1>

<div class="body_container">
<h3 id="trainingProgress"></h3>
<h3 style="float: left">Current state (Lidar points)</h3><br><br>
<h3 style="float: left">Current state (Lidar points)</h3><br><br><br>
<div id="realtime_viewer" style="float: left"></div>
<p>
<b>Policy Gradient</b> algorithm based on Monte Carlo exploration. <br>
Expand All @@ -45,9 +45,10 @@ <h3 style="float: left">Current state (Lidar points)</h3><br><br>
<script src="/dist/metacar.min.js"></script>

<script type="text/javascript" src="/public/js/utils.js"></script>
<script type="text/javascript" src="/public/js/policy_agent.js"></script>
<script type="text/javascript" src="/public/js/viewer.js"></script>
<script type="text/javascript" src="/public/js/level1.js"></script>

<script type="text/javascript" src="/public/js/policy_monte_carlo/policy_agent.js"></script>
<script type="text/javascript" src="/public/js/policy_monte_carlo/index.js"></script>

</body>
</html>
Binary file added demo/webapp/public/img/ddpg-traffic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/webapp/public/img/ddpg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/webapp/public/img/level0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions demo/webapp/public/js/ddpg-traffic/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

let levelUrl = metacar.level.level3;

var env = new metacar.env("canvas", levelUrl);

env.setAgentMotion(metacar.motion.ControlMotion, {});
env.setAgentLidar({pts: 7, width: 3, height: 7, pos: -0.5})

// js/DDPG/ddpg.js
var agent = new DDPGAgent(env, {
stateSize: 50,
resetEpisode: true,
desiredActionStddev: 0.4,
initialStddev: 0.4,
actorFirstLayerSize: 128,
actorSecondLayerSize: 64,
criticFirstLayerSSize: 128,
criticFirstLayerASize: 128,
criticSecondLayerSize: 64,
nbEpochs: 1000
});

initMetricsContainer("statContainer", ["Reward", "ActorLoss", "CriticLoss", "EpisodeDuration", "NoiseDistance"]);

let it = 0;
env.loop(() => {
let state = env.getState();
displayState("realtime_viewer", state.lidar, 200, 200);
let reward = env.getLastReward();
const qValue = agent.getQvalue(state.linear, [state.a, state.steering]);
if (it % 10 == 0)
displayScores("realtime_viewer", [qValue, state.a, state.steering], reward, ["Q(a, s)", "Acceleration", "Steering Angle"]);
it += 1;
});

env.load().then(() => {

env.addEvent("train [Background]", () => {
let train = confirm("The training process takes some time and might slow this tab. Do you want to continue? \n You can also load a pre-trained model.");
if (train){
env.render(false);
agent.train(false);
}
});

env.addEvent("Train [Show the training]", () => {
env.steping(false);
agent.train(true);
});

env.addEvent("play", () => {
agent.play();
});

env.addEvent("stop", () => {
agent.stop();
});

env.addEvent("reset_env");

env.addEvent("save", () => {
agent.save("model-ddpg-traffic");
});

env.addEvent("load", () => {
agent.restore("ddpg-traffic", "model-ddpg-traffic-epoch-120");
});
});





Loading

0 comments on commit 678ed4f

Please sign in to comment.