From 237a56d5cb58d010e66389add876418895af830a Mon Sep 17 00:00:00 2001 From: Kiersten Stokes Date: Thu, 1 Jun 2023 13:46:03 -0500 Subject: [PATCH] Clear plot at beginning of loop so that non-empty image renders --- intermediate_source/mario_rl_tutorial.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/intermediate_source/mario_rl_tutorial.py b/intermediate_source/mario_rl_tutorial.py index ff653d54c11..8d02f3daf34 100755 --- a/intermediate_source/mario_rl_tutorial.py +++ b/intermediate_source/mario_rl_tutorial.py @@ -711,17 +711,18 @@ def record(self, episode, epsilon, step): f"{datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S'):>20}\n" ) - for metric in ["ep_rewards", "ep_lengths", "ep_avg_losses", "ep_avg_qs"]: - plt.plot(getattr(self, f"moving_avg_{metric}")) - plt.savefig(getattr(self, f"{metric}_plot")) + for metric in ["ep_lengths", "ep_avg_losses", "ep_avg_qs", "ep_rewards"]: plt.clf() + plt.plot(getattr(self, f"moving_avg_{metric}"), label=f"moving_avg_{metric}") + plt.legend() + plt.savefig(getattr(self, f"{metric}_plot")) ###################################################################### # Let’s play! # """"""""""""""" # -# In this example we run the training loop for 10 episodes, but for Mario to truly learn the ways of +# In this example we run the training loop for 40 episodes, but for Mario to truly learn the ways of # his world, we suggest running the loop for at least 40,000 episodes! # use_cuda = torch.cuda.is_available() @@ -735,7 +736,7 @@ def record(self, episode, epsilon, step): logger = MetricLogger(save_dir) -episodes = 10 +episodes = 40 for e in range(episodes): state = env.reset()