Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
927 views
in Technique[技术] by (71.8m points)

reinforcement learning - OpenAI gym render() in Google Colab

I am trying to use a Reinforcement Learning tutorial using OpenAI gym in a Google Colab environment. I am using the strategy of creating a virtual display and then using matplotlib to display the environment that is being rendered.

This works nicely when I use the "CartPole-v0" or the 'LunarLander-v2' environment but is giving an error when I use "Taxi-v3" environment.

Notebook cells are as follows:

# install required system dependencies
!apt-get install -y xvfb x11-utils > /dev/null
!pip install gym[box2d] pyvirtualdisplay  PyOpenGL PyOpenGL-accelerate > /dev/null

import pyvirtualdisplay
_display = pyvirtualdisplay.Display(visible=False,size=(1400, 900))  # use False with Xvfb                 
_ = _display.start()
!echo $DISPLAY

import gym
import matplotlib.pyplot as plt
import numpy as np
from IPython import display

env = gym.make("Taxi-v3").env
#env = gym.make("CartPole-v0").env
#env = gym.make('LunarLander-v2')

env.reset()
fig, ax = plt.subplots(figsize=(20, 10))
ax.axis('off')
img = ax.imshow(env.render(mode='rgb_array'))
#img.set_data(env.render(mode='rgb_array')) 
display.display(plt.gcf())
display.clear_output(wait=True)

the error is as follows :

Exception in callback BaseAsyncIOLoop._handle_events(18, 1)
handle: <Handle BaseAsyncIOLoop._handle_events(18, 1)>
Traceback (most recent call last):
  File "/usr/lib/python3.6/asyncio/events.py", line 145, in _run
    self._callback(*self._args)
  -------- ------- ---- etc etc
  File "/usr/local/lib/python3.6/dist-packages/ipykernel/iostream.py", line 339, in flush
    if self.pub_thread.thread.is_alive():
AttributeError: 'NoneType' object has no attribute 'thread'

As noted earlier, the error happens ONLY when I use the Taxi-v3 environment. I have two questions

  1. what changes should I do make the Taxi-v3 environment work within Colab?
  2. what could be the difference between the Taxi environment and the two other environments? What could be reason for this error?

Any guidance or suggestion would be welcome.

question from:https://stackoverflow.com/questions/65912117/openai-gym-render-in-google-colab

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Taxi-v3 is an environment that generates text output! So pushing it into matplotlib is causing the error! This code works!

env = gym.make("Taxi-v3").env
env.reset()
env.render()

and generates

+---------+
|R: | : :G|
| : | : : |
| : : : : |
| | : | : |
|Y| : |B: |
+---------+

in colour!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...