(self)
| 97 | # wandb.log(num_zombies, step=self.model.num_timesteps) |
| 98 | |
| 99 | def _on_rollout_end(self): |
| 100 | wandb.log({'time/rollout': self.model.t_rollout}, step=self.model.num_timesteps) |
| 101 | |
| 102 | # save rollout statistics |
| 103 | avg_ep_stat = self.get_avg_ep_stat(self.model.ep_stat_buffer, prefix='rollout/') |
| 104 | wandb.log(avg_ep_stat, step=self.model.num_timesteps) |
| 105 | |
| 106 | # action, mu, sigma histogram |
| 107 | action_statistics = np.array(self.model.action_statistics) |
| 108 | mu_statistics = np.array(self.model.mu_statistics) |
| 109 | sigma_statistics = np.array(self.model.sigma_statistics) |
| 110 | n_action = action_statistics.shape[-1] |
| 111 | action_statistics = action_statistics.reshape(-1, n_action) |
| 112 | mu_statistics = mu_statistics.reshape(-1, n_action) |
| 113 | sigma_statistics = sigma_statistics.reshape(-1, n_action) |
| 114 | |
| 115 | for i in range(n_action): |
| 116 | # path_str = (self._save_dir/f'action{i}.csv').as_posix() |
| 117 | # np.savetxt(path_str, action_statistics[:, i], delimiter=',') |
| 118 | # wandb.save(path_str) |
| 119 | wandb.log({f'action[{i}]': wandb.Histogram(action_statistics[:, i])}, step=self.model.num_timesteps) |
| 120 | wandb.log({f'alpha[{i}]': wandb.Histogram(mu_statistics[:, i])}, step=self.model.num_timesteps) |
| 121 | wandb.log({f'beta[{i}]': wandb.Histogram(sigma_statistics[:, i])}, step=self.model.num_timesteps) |
| 122 | |
| 123 | # render buffer |
| 124 | if (self.model.num_timesteps - self._last_time_buffer) >= self._buffer_step: |
| 125 | self._last_time_buffer = self.model.num_timesteps |
| 126 | buffer_video_path = (self._video_path / f'buffer_{self.model.num_timesteps}.mp4').as_posix() |
| 127 | |
| 128 | list_buffer_im = self.model.buffer.render() |
| 129 | encoder = ImageEncoder(buffer_video_path, list_buffer_im[0].shape, 30, 30) |
| 130 | for im in list_buffer_im: |
| 131 | encoder.capture_frame(im) |
| 132 | encoder.close() |
| 133 | encoder = None |
| 134 | |
| 135 | wandb.log({f'buffer/{self.model.num_timesteps}': wandb.Video(buffer_video_path)}, |
| 136 | step=self.model.num_timesteps) |
| 137 | |
| 138 | @staticmethod |
| 139 | def evaluate_policy(env, policy, video_path, min_eval_steps=3000): |
nothing calls this directly
no test coverage detected