colabgymrender icon indicating copy to clipboard operation
colabgymrender copied to clipboard

Render OpenAI Gym environments in Google Colaboratory

Gym Rendering for Colab

PyPI download month PyPI - Status PyPI GitHub Open In Colab

Installation

apt-get install -y xvfb python-opengl ffmpeg > /dev/null 2>&1
pip install colabgymrender

Common Issues

Problem:

RuntimeError: imageio.ffmpeg.download() has been deprecated. Use 'pip install imageio-ffmpeg' instead.'

Solution: Install earlier version of imageio, then restart runtime.

pip install imageio==2.4.1

Usage

import gym
from colabgymrender.recorder import Recorder

env = gym.make("Breakout-v0")
directory = './video'
env = Recorder(env, directory)

observation = env.reset()
terminal = False
while not terminal:
  action = env.action_space.sample()
  observation, reward, terminal, info = env.step(action)

env.play()

Demo

Watch it on YouTube

https://user-images.githubusercontent.com/18452581/116127430-d2afb300-a695-11eb-991a-99d13c015006.mp4

https://user-images.githubusercontent.com/18452581/116128757-48684e80-a697-11eb-9fbd-a716476b7c90.mp4

https://user-images.githubusercontent.com/18452581/116128782-4ef6c600-a697-11eb-80d2-fbf22ff7cf6f.mp4

https://user-images.githubusercontent.com/18452581/116128789-50c08980-a697-11eb-8ed3-6b4f645c3e1f.mp4