Esempio n. 1
0
    def write_tboard(self, data):
        with lock:
            loss, train_step, writer, summary_ops, summary_vars, num_agents = data
            # Tensorboard
            episode_b_rewards = []
            for j in range(self.num_env):
                if self.args.env_type == "mpe":
                    episode_b_rewards.append(
                        np.mean(self.ep_rewards[j][self.print_step:]))
                else:
                    episode_b_rewards.append(
                        np.mean(self.ep_success[j][self.print_step:]))
            episode_b_rewards = np.mean(np.array(episode_b_rewards))
            num_steps = train_step * self.num_env

            # Add to tensorboard only when actor agent is updated
            if loss[0][1] is not None:
                fd = {}
                for i, key in enumerate(summary_vars):
                    if i == 0:
                        fd[key] = episode_b_rewards
                    else:
                        agnt_idx = int((i - 1) / 5)
                        if agnt_idx == num_agents: agnt_idx -= 1
                        if loss[agnt_idx] is not None:
                            fd[key] = loss[agnt_idx][int((i - 1) % 5)]

                summary_str = U.get_session().run(summary_ops, feed_dict=fd)
                writer.add_summary(summary_str, num_steps)
                writer.flush()
Esempio n. 2
0
 def create_tensorboard(self):
     """ Setup tensorboard """
     if not (self.args.benchmark or self.args.display):
         self.writer = tf.compat.v1.summary.FileWriter(
             self.tboard_dir,
             U.get_session().graph)
         self.writer.flush()
         self.summary_ops, self.summary_vars = build_summaries(
             self.num_agents, self.args)