Beispiel #1
0
model.add(Activation('relu'))
model.add(Dense(24))
model.add(Activation('relu'))
model.add(Dense(nb_actions))
model.add(Activation('linear'))
print(model.summary())

# serialize model to JSON
model_save = model.to_json()
with open("save/NNmodel2.json", "w") as json_file:
    json_file.write(model_save)

print("Saved model to disk!")

memory = SequentialMemory(limit=100000, window_length=1)
policy1 = BoltzmannQPolicy()
policy2 = EpsGreedyQPolicy()

callback6 = FileLogger(filepath='save/history6_{}'.format(timenow), interval=1)

dqn3 = DQNAgent(model=model,
                nb_actions=nb_actions,
                memory=memory,
                batch_size=640,
                nb_steps_warmup=20000,
                target_model_update=1e-2,
                policy=policy2)
dqn3.compile(Adam(lr=1e-3), metrics=['mae'])
history3 = dqn3.fit(env,
                    nb_epsteps=2500,
                    visualize=False,
Beispiel #2
0
model.add(Activation('linear'))
print(model.summary())

# serialize model to JSON
model_save = model.to_json()
with open("save/NNmodel1.json", "w") as json_file:
    json_file.write(model_save)

print("Saved model to disk!")

# Finally, we configure and compile our agent. You can use every built-in Keras optimizer and
# even the metrics!
memory = SequentialMemory(limit=10000, window_length=1)
#policy1 = BoltzmannQPolicy()
policy1 = EpsDisGreedyQPolicy(eps=0.0001, eps_decay=0.999)
policy2 = BoltzmannQPolicy()

callback12 = FileLogger(filepath='save/history12_{}'.format(timenow),
                        interval=1)

dqn8 = DQNAgent(model=model,
                nb_actions=nb_actions,
                memory=memory,
                gamma=0.99,
                nb_steps_warmup=2000,
                target_model_update=1,
                policy=policy1)
dqn8.compile(Adam(lr=1e-3), metrics=['mae'])
history8 = dqn8.fit(env,
                    nb_epsteps=3000,
                    visualize=False,
Beispiel #3
0
timenow = datetime.now().strftime('%Y-%m-%d %H:%M:%S')

#import gym_gazebo

# load json and create model
json_file = open('save/NNmodel1.json', 'r')
loaded_model1 = json_file.read()
json_file.close()
model = model_from_json(loaded_model1)
print("Loaded model from disk!")

ENV_NAME = 'GazeboCircuit2TurtlebotLidar-v1'
env = gym.make(ENV_NAME)
nb_actions = env.action_space.n
memory = SequentialMemory(limit=10000, window_length=1)
policy = BoltzmannQPolicy()
#dqn1 = DQNAgent(model=model, nb_actions=nb_actions, memory=memory, nb_steps_warmup=2000,
#               target_model_update=1e-2, policy=policy)
dqn2 = DQNAgent(model=model,
                nb_actions=nb_actions,
                memory=memory,
                nb_steps_warmup=2000,
                target_model_update=1e-2)
#dqn3 = DQNAgent(model=model, nb_actions=nb_actions, memory=memory, nb_steps_warmup=1000,
#               target_model_update=1e-2, policy=policy, enable_double_dqn=False)
#dqn4 = DQNAgent(model=model, nb_actions=nb_actions, memory=memory, nb_steps_warmup=1000,
#               target_model_update=1e-2, enable_double_dqn=False)

#dqn1.compile(Adam, metrics=['mae'])
dqn2.compile(Adam, metrics=['mae'])
#dqn3.compile(SGD, metrics=['mae'])