This commit is contained in:
wassname
2018-12-01 21:21:12 +08:00
parent a7df66c034
commit c1e2467324
3 changed files with 39 additions and 6 deletions
+9 -3
View File
@@ -80,8 +80,14 @@ class DDPGAgent {
/*
Save the network
*/
this.ddpg.critic.model.save('downloads://critic-' + name);
this.ddpg.actor.model.save('downloads://actor-'+ name);
if (typeof window === "undefined") {
this.ddpg.actor.model.save('file://./outputs/actor-' + name);
this.ddpg.actor.model.save('file://./outputs/actor-' + name);
} else {
this.ddpg.critic.model.save('downloads://critic-' + name);
this.ddpg.actor.model.save('downloads://actor-'+ name);
}
}
async restore(folder, name){
@@ -229,7 +235,7 @@ class DDPGAgent {
this._optimize();
}
if (this.config.saveDuringTraining && this.epoch % this.config.saveInterval == 0 && this.epoch != 0){
this.save("model-ddpg-traffic-epoch-"+this.epoch);
this.save("model-ddpg-walker-epoch-"+this.epoch);
}
setMetric("Reward", mean(this.rewardsList));
setMetric("EpisodeDuration", mean(this.stepList));
+5
View File
@@ -1,2 +1,7 @@
const tf = require('@tensorflow/tfjs')
// Load the binding (note you may have to press enter in the terminal for some reason)
require('@tensorflow/tfjs-node-gpu');
require('@tensorflow/tfjs-node'); // seem to need this as well for save?
module.exports = { tf }
+25 -3
View File
@@ -7,24 +7,46 @@ const {
} = require('./js/walker')
var world = new b2.World(new b2.Vec2(0, -10))
var gravity = new b2.Vec2(0, -10)
var world = new b2.World(gravity)
floor = createFloor(world, config.max_floor_tiles);
var env = new Walker(world, floor, config)
const nbActions = env.joints.length + 4
const stateSize = env.bodies.length * 10 + env.joints.length * 3
var agent = new DDPGAgent(env, {
stateSize,
nbActions,
resetEpisode: true,
desiredActionStddev: 0.4,
batchSize: 128,
actorLr: 0.0001,
criticLr: 0.001,
memorySize: 30000,
gamma: 0.99,
desiredActionStddev: 0.1,
initialStddev: 0.4,
actorFirstLayerSize: 128,
actorSecondLayerSize: 64,
criticFirstLayerSSize: 128,
criticFirstLayerASize: 128,
criticSecondLayerSize: 64,
nbEpochs: 1000
nbEpochs: 1000,
nbEpochsCycle: 10,
nbTrainSteps: 100,
maxStep: 800,
saveDuringTraining: true,
saveInterval: 20,
tau: 0.008,
adoptionCoefficient: 1.01,
});
agent.train(true);
agent.save("model-ddpg-traffic");