Commit 46cb51da authored by Avisek Naug's avatar Avisek Naug 🎨
Browse files

fixed relearn loop

parent db69e205
......@@ -304,7 +304,8 @@ def control_loop(source: str, store: str, save: str, valid: str, agent: DDPGAgen
def learn_control(source: str, save_to: str, relearn_window: int, duration: int,
signal_stop: Event, signal_reload: Event, lock_policy: Lock):
signal_stop: Event, signal_reload: Event, lock_policy: Lock,
lstm, re_agent):
"""
Run reinforcement learning on accumulated experience and save new control
policy.
......@@ -336,21 +337,23 @@ def learn_control(source: str, save_to: str, relearn_window: int, duration: int,
return
# retrain on the same model
log.info('RELEARN: Loading existing LSTM model of energy consumption.')
lstm = load_model('weights.best.hdf5')
log.info('RELEARN: Loading current best weights for LSTM model of energy consumption.')
lstm.load_weights('weights.best.hdf5')
log.info('RELEARN: Re-training LSTM model of energy consumption.')
retrain(lstm, relearndf, epochs=25)
log.info('RELEARN: LSTM energy model training finished.')
# loading the best weights relearned right now
lstm.load_weights('weights.best.hdf5')
# create new model of environment
env = Env(datapath='relearn.pkl', modelpath = 'weights.best.hdf5')
re_env = Env(lstm, datapath='relearn.pkl')
os.remove('relearn.pkl')
# Do not reinitialize the agent, instead use a COPY of the existing agent file
agent = get_agent(env)
agent.load_weights('agent_weights.h5f')
re_agent.load_weights('agent_weights.h5f')
log.info('RELEARN: Training new control agent.')
train_agent(agent=agent, env=env, steps=duration, dest=save_to)
train_agent(agent=re_agent, env=re_env, steps=duration, dest=save_to)
log.info('RELEARN: Control policy adapted.')
signal_reload.set()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment