Skip to content

Commit e2a7ab0

Browse files
kiersten-stokesSvetlana Karslioglu
and
Svetlana Karslioglu
authored
Clear plot at beginning of loop so that non-empty image renders (#2401)
Co-authored-by: Svetlana Karslioglu <[email protected]>
1 parent aa400c3 commit e2a7ab0

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Diff for: intermediate_source/mario_rl_tutorial.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -711,17 +711,18 @@ def record(self, episode, epsilon, step):
711711
f"{datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S'):>20}\n"
712712
)
713713

714-
for metric in ["ep_rewards", "ep_lengths", "ep_avg_losses", "ep_avg_qs"]:
715-
plt.plot(getattr(self, f"moving_avg_{metric}"))
716-
plt.savefig(getattr(self, f"{metric}_plot"))
714+
for metric in ["ep_lengths", "ep_avg_losses", "ep_avg_qs", "ep_rewards"]:
717715
plt.clf()
716+
plt.plot(getattr(self, f"moving_avg_{metric}"), label=f"moving_avg_{metric}")
717+
plt.legend()
718+
plt.savefig(getattr(self, f"{metric}_plot"))
718719

719720

720721
######################################################################
721722
# Let’s play!
722723
# """""""""""""""
723724
#
724-
# In this example we run the training loop for 10 episodes, but for Mario to truly learn the ways of
725+
# In this example we run the training loop for 40 episodes, but for Mario to truly learn the ways of
725726
# his world, we suggest running the loop for at least 40,000 episodes!
726727
#
727728
use_cuda = torch.cuda.is_available()
@@ -735,7 +736,7 @@ def record(self, episode, epsilon, step):
735736

736737
logger = MetricLogger(save_dir)
737738

738-
episodes = 10
739+
episodes = 40
739740
for e in range(episodes):
740741

741742
state = env.reset()

0 commit comments

Comments
 (0)