from rl.agents.dqn import DQNAgent from rl.memory import SequentialMemory # define model and memory model = ... memory = SequentialMemory(limit=10000, window_length=1) # create DQNAgent dqn_agent = DQNAgent(model=model, memory=memory, nb_actions=10, nb_steps_warmup=1000) # --- training of the agent --- # save the trained weights dqn_agent.save_weights('dqn_weights.h5', overwrite=True)
from rl.agents.dqn import DQNAgent from rl.memory import SequentialMemory # define model and memory model = ... memory = SequentialMemory(limit=10000, window_length=1) # create DQNAgent and load pre-trained weights dqn_agent = DQNAgent(model=model, memory=memory, nb_actions=10, nb_steps_warmup=1000) dqn_agent.load_weights('dqn_weights.h5', by_name=True)In this example, a DQNAgent is created similarly to the previous example. However, before any training is done, the pre-trained weights are loaded using the load_weights method. The 'by_name=True' parameter specifies that only the matching layers in the model should have their weights loaded. If 'by_name=False', the loaded weights would be expected to match the entire model.