From d1211037c2a245b61828831011b86724c8502804 Mon Sep 17 00:00:00 2001 From: Evan Shelhamer Date: Thu, 11 May 2017 10:44:46 -0700 Subject: [PATCH] fix play utility - import pyglet window to fix mysterious issue with ui focus (hat tip @jeanharb) - make matplotlib backend take effect by picking before plot import - fix misc. issues with example usage --- gym/utils/play.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/gym/utils/play.py b/gym/utils/play.py index 1aafa622c3f..2b5abc6b747 100644 --- a/gym/utils/play.py +++ b/gym/utils/play.py @@ -3,17 +3,19 @@ import sys import time import matplotlib -import matplotlib.pyplot as plt - -from collections import deque -from pygame.locals import HWSURFACE, DOUBLEBUF, RESIZABLE, VIDEORESIZE -from threading import Thread - try: matplotlib.use('GTK3Agg') + import matplotlib.pyplot as plt except Exception: pass + +import pyglet.window as pw + +from collections import deque +from pygame.locals import HWSURFACE, DOUBLEBUF, RESIZABLE, VIDEORESIZE +from threading import Thread + def display_arr(screen, arr, video_size, transpose): arr_min, arr_max = arr.min(), arr.max() arr = 255.0 * (arr - arr_min) / (arr_max - arr_min) @@ -180,14 +182,10 @@ def callback(self, obs_t, obs_tp1, action, rew, done, info): if __name__ == '__main__': - from rl_algs.common.atari_wrappers import wrap_deepmind - def callback(obs_t, obs_tp1, action, rew, done, info): return [rew, obs_t.mean()] env_plotter = EnvPlotter(callback, 30 * 5, ["reward", "mean intensity"]) env = gym.make("MontezumaRevengeNoFrameskip-v3") - env = wrap_deepmind(env) - - play_env(env, zoom=4, callback=env_plotter.callback, fps=30) + play(env, zoom=4, callback=env_plotter.callback, fps=30)