def load(self, name): self.model.load_weights(name) def save(self, name): self.model.save_weights(name) if __name__ == "__main__": env = gym.make('CartPole-v1') state_size = env.observation_space.shape[0] # print(state_size) # 4 =: left , right , balance , slide or drop the pole action_size = env.action_space.n # print(action_size) # 2 agent = DQNAgent(state_size, action_size) smodel = agent._build_model() smodel.summary() # agent.load("cartpole-dqn.h5") done = False batch_size = 32 for e in range(EPISODES): # reset state in the beginning of each game state = env.reset() state = np.reshape(state, [1, state_size]) # turn the state into a one dimensional matrix which is a vector # time represents each frame of the game # Our goal is to keep the pole upright as long as possible until score of 500 # the more time the more score for time in range(700): env.render() # Decide action