Example #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)
Example #2
0
    def train(self):

        # 将定义好的网络作为参数传入框架的API中,构成一个完成智能体,用于接下来的强化学习训练。
        agent =self.create_agent()
        cpkt = tf.io.gfile.listdir("model_dir")
        if cpkt==self.file_path:
            agent.model.load_weights(self.file_path)
        # 使用general框架的trainer来创建一个训练模拟器,在模拟器中进行训练。
        sim = gr.Trainer(self.dummy_env, agent)
        sim.train(max_steps=self.train_steps, visualize=True, plot=self.plot_rewards)
        agent.save(filename=self.file_path,overwrite=True,save_format='h5')
Example #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')
Example #4
0
    def train(self):

        # 将定义好的网络作为参数传入框架的API中,构成一个完成智能体,用于接下来的强化学习训练。
        agent = self.create_agent()
        cpkt = tf.io.gfile.listdir("model_dir")
        if cpkt == self.file_path:
            agent.model.load_weights(self.file_path)

        # 使用general框架的trainer来创建一个训练模拟器,在模拟器中进行训练。
        sim = gr.Trainer(self.dummy_env, agent)
        sim.train(max_steps=self.train_steps,
                  visualize=True,
                  plot=self.plot_rewards)
        agent.save(filename=self.file_path, overwrite=True, save_format='h5')
        cf = configparser.ConfigParser(allow_no_value=True)
        cf.add_section('ints')
        cf.add_section('strings')
        cf.set('ints', 'dense_num', "%s" % self.dense_num)
        cf.set('ints', 'cell_num', "%s" % self.cell_num)
        cf.set('ints', 'action_space', "%s" % self.action_space)
        cf.set('strings', 'activation', "%s" % self.activation)
        cf.set('strings', 'algorithm_type', "%s" % self.algorithm_type)
        with open(self.config_path, 'w') as f:
            cf.write(f)
Example #5
0
 def run_model(self):
     agent = self.create_agent()
     agent.model.load_weights(filepath=self.file_path)
     sim = gr.Trainer(self.dummy_env, agent)
     sim.test(max_steps=self.run_steps, plot=self.plot_rewards)
Example #6
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)