Example #1
0
RESTORE_PATH = None

if RESTORE_PATH is None:
    raise UserWarning(
        'Please change the variable `RESTORE_PATH` to where you would like to load the model from. If you haven\'t trained a model, try \'example-save\''
    )

# Create environment
game_wrapper = GameWrapper(ENV_NAME, MAX_NOOP_STEPS)
print("The environment has the following {} actions: {}".format(
    game_wrapper.env.action_space.n,
    game_wrapper.env.unwrapped.get_action_meanings()))

# Create agent
MAIN_DQN = build_q_network(game_wrapper.env.action_space.n,
                           LEARNING_RATE,
                           input_shape=INPUT_SHAPE)
TARGET_DQN = build_q_network(game_wrapper.env.action_space.n,
                             input_shape=INPUT_SHAPE)

replay_buffer = ReplayBuffer(size=MEM_SIZE, input_shape=INPUT_SHAPE)
agent = Agent(MAIN_DQN,
              TARGET_DQN,
              replay_buffer,
              game_wrapper.env.action_space.n,
              input_shape=INPUT_SHAPE,
              batch_size=BATCH_SIZE)

print('Loading model...')
agent.load(RESTORE_PATH)
print('Loaded')
Example #2
0
 action_codes = []
 inv_action_codes = []
 saved_experts = find_saved_experts(env_names)
 print(saved_experts)
 experts = []
 replay_buffers = []
 for i in range(num_envs):
     game_actions = game_wrappers[i].env.unwrapped.get_action_meanings()
     action_code = [all_actions.index(action) for action in game_actions]
     action_codes.append(action_code)
     inv_action_code = [
         game_actions.index(action) for action in all_actions
         if action in game_actions
     ]
     inv_action_codes.append(inv_action_code)
     MAIN_DQN = build_q_network(len(game_actions), input_shape=INPUT_SHAPE)
     TARGET_DQN = build_q_network(len(game_actions),
                                  input_shape=INPUT_SHAPE)
     replay_buffer = ReplayBuffer(size=MEM_SIZE,
                                  input_shape=INPUT_SHAPE,
                                  use_per=USE_PER)
     expert = Agent(MAIN_DQN,
                    TARGET_DQN,
                    replay_buffer,
                    len(game_actions),
                    input_shape=INPUT_SHAPE,
                    batch_size=BATCH_SIZE,
                    use_per=USE_PER)
     expert.load(saved_experts[i], False)
     experts.append(expert)
     replay_buffers.append(replay_buffer)