Giter Site home page Giter Site logo

Comments (8)

joschu avatar joschu commented on May 20, 2024 8

Should work to do plt.imshow(env.render(mode='rgb_array')) inside of your notebook cell

from gym.

patrickmineault avatar patrickmineault commented on May 20, 2024 2

Here's one approach:

http://nbviewer.jupyter.org/github/patrickmineault/xcorr-notebooks/blob/master/Render%20OpenAI%20gym%20as%20GIF.ipynb

from gym.

mpacer avatar mpacer commented on May 20, 2024 1

Note import matplotlib.pyplot plt.imshow(env.render(mode='rgb_array')) does not work in either notebook 5.0.0 or 5.1.0. I honestly don't think it would have worked in earlier editions, but some stuff with mimetypes have changed so I don't know if that's affecting it.

But should this have ever worked?:

from matplotlib import pyplot as plt
# plt.ion()
%matplotlib inline
import gym
env = gym.make('CartPole-v0')
env.reset()
for _ in range(1000):
   plt.imshow(env.render(mode='rgb_array'))    
   env.step(env.action_space.sample()) # take a random action

from gym.

andrewschreiber avatar andrewschreiber commented on May 20, 2024 1

Wrote up a solution on StackOverflow:

https://stackoverflow.com/questions/40195740/how-to-run-openai-gym-render-over-a-server/45179251#45179251

from gym.

jonasschneider avatar jonasschneider commented on May 20, 2024

That sounds very exciting. I don't think we necessarily need pyglet support; the rgb_array rendering mode might be interesting here -- it just returns the raw image, which we usually use for video encoding. As a first idea, you might want to try using env.render(mode='rgb_array'), and then render the resulting np.ndarray using e.g. matplotlib inside of IPython.

We're definitely open to merging something that makes this even easier, though!

from gym.

gdb avatar gdb commented on May 20, 2024

(Going to close for now; let us know if we can help with anything!)

from gym.

mpacer avatar mpacer commented on May 20, 2024

I can vouch for the solution by @patrickmineault as working, but I'm thinking this should be possible by using the IPython display mech for handling general mimetypes so long as the right spot can be hooked into directly.

from gym.

dsblank avatar dsblank commented on May 20, 2024

I avoided the matplotlib issues by simply doing:

import PIL
PIL.Image.fromarray(env.render(mode='rgb_array')).resize((320, 420))

There may still be an issue on servers without DISPLAYS, but that seems like a separate issue.

from gym.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.