Esempio n. 1
0
def test():
    #初始化神经网络模型
    model = create_model()
    #将定义好的网络作为参数传入general框架的API中,构建一个含有DQN神经网络的智能体。
    agent = gr.DQN(model, actions=dummy_env.action_space.n, nsteps=2)
    #将之前训练的模型参数导入的新初始化的神经网络中
    agent.model.load_weights("model_dir/dqn.h5")
    #将智能体和gym环境放入训练器中开始测试模型的效果
    tra = gr.Trainer(create_env, agent)
    tra.test(max_steps=1000)
Esempio n. 2
0
    def create_agent(self):
        model = self.create_model()
        if self.algorithm_type=='dqn':
            agent = gr.DQN(model, actions=2, nsteps=2)
        elif self.algorithm_type=='ddpg':
            agent = gr.DDPG(model, actions=self.dummy_env.action_space.n, nsteps=2)

        elif self.algorithm_type=='ppo':
            agent = gr.PPO(model, actions=self.dummy_env.action_space.n, nsteps=2)

        return agent
Esempio n. 3
0
def train():
    #初始化神经网络模型
    model = create_model()
    #将定义好的网络作为参数传入general框架的API中,构成一个完成DQN 智能体,用于接下来的强化学习训练。
    agent = gr.DQN(model, actions=dummy_env.action_space.n, nsteps=2)
    cpkt = tf.io.gfile.listdir("model_dir")
    if cpkt:
        agent.model.load_weights("model_dir/dqn.h5")
    #将智能体和gym环境放入训练器中开始训练深度神经网络模型
    tra = gr.Trainer(dummy_env, agent)
    tra.train(max_steps=3000, visualize=True, plot=plot_rewards)
    agent.save(filename='model_dir/dqn.h5', overwrite=True, save_format='h5')
Esempio n. 4
0
 def run_model(self):
     model = self.create_model()
     agent = gr.DQN(model, actions=self.dummy_env.action_space.n, nsteps=2)
     agent.model.load_weights(filepath=self.file_path)
     sim = gr.Trainer(self.dummy_env, agent)
     sim.test(max_steps=self.run_steps)