First of all, excellent work, just what I have been looking for!
Love it that I can experiment and have well documented code.
I work mainly in Google Colab, mainly because I got tired of pip install and it removes the hassle of infrastructure.
See you published very nice Colabs, many thanks.
I figured out a way with wrappers to have Gym create video's that is also working in Colab (with virtual monitor) , nice to have a graph explaining the score is increasing but also want to see games with my own eyes. Unfortunately that does not work anymore with Stable baselines (at least I did not yet spot it).
Any ideas how to solve this for a Colab environments with Stable-baselines?
Below example how it works for e in a standard gym environment:
`
@title Set-up the virtual display environment
!apt-get update
!apt-get install python-opengl -y
!apt install xvfb -y
!pip install pyvirtualdisplay
!pip install piglet
!apt-get install ffmpeg
@title Start the virtual monitor
from pyvirtualdisplay import Display
display = Display(visible=0, size=(1400, 900))
display.start()
@title play a random game and create video
env = gym.make("PongNoFrameskip-v4")
monitor_dir ='/content/test5'
#Setup a wrapper to be able to record a video of the game
record_video = True
should_record = lambda i: record_video
env = wrappers.Monitor(env, monitor_dir, video_callable=should_record, force=True)
#Play a game
state = env.reset()
done = False
while not done:
action = env.action_space.sample() #random action, replace by the prediction of the model
state, reward, done, _ = env.step(action)
record_video = False
env.close()
download videos
from google.colab import files
import glob
os.chdir(monitor_dir) # change directory to get the files
!pwd #show file path
!ls # show directory content
for file in glob.glob(".mp4"):
print(file)
files.download(file)
os.chdir('..') #backout the video directory
`
Wrapping the whole stable-baseline env does not work.
Tried also something like:
`
monitor_dir ='/content/test7'
env_show = gym.make('LunarLander-v2')
record_video = True
should_record = lambda i: record_video
env_show = wrappers.Monitor(env_show, monitor_dir, video_callable=should_record, force=True)
obs = env_show.reset()
dones = False
while not dones:
action, _states = model.predict(obs)
obs, rewards, dones, info = env_show.step(action)
env_show.render()
record_video = False
env_show.close()
`
Which works for Lunar Lander but not for an Atari game: Error: Unexpected observation shape (210, 160, 3) for Box environment, please use (84, 84, 4) or (n_env, 84, 84, 4) for the observation shape.
Any pragmatic elegant solution or small enhancement for Colab users?
Thank you