openai / gym

A toolkit for developing and comparing reinforcement learning algorithms.
https://www.gymlibrary.dev
Other
34.52k stars 8.59k forks source link

tflearn and gym.render() cannot work together,invalid literal for int() with base 10: 'None' #403

Closed taochenshh closed 7 years ago

taochenshh commented 7 years ago

I just used the following code. And the code ran fine when import tflearn was commented. If I have both import tflearn and env.render(), error occurred.

import tflearn
import tensorflow as tf
import gym
with tf.Session() as sess:
    env = gym.make('Pendulum-v0')
    env.seed(1234)
    env.reset()
    env.render()

The error is like this:

I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcurand.so locally
I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:925] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
I tensorflow/core/common_runtime/gpu/gpu_device.cc:951] Found device 0 with properties: 
name: GeForce GTX 980
major: 5 minor: 2 memoryClockRate (GHz) 1.253
pciBusID 0000:01:00.0
Total memory: 3.93GiB
Free memory: 3.31GiB
W tensorflow/stream_executor/cuda/cuda_driver.cc:572] creating context when one is currently active; existing: 0x36e0a20
I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:925] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
I tensorflow/core/common_runtime/gpu/gpu_device.cc:951] Found device 1 with properties: 
name: GeForce GTX 980
major: 5 minor: 2 memoryClockRate (GHz) 1.253
pciBusID 0000:07:00.0
Total memory: 3.94GiB
Free memory: 3.87GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:972] DMA: 0 1 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] 0:   Y Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] 1:   Y Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:1041] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 980, pci bus id: 0000:01:00.0)
I tensorflow/core/common_runtime/gpu/gpu_device.cc:1041] Creating TensorFlow device (/gpu:1) -> (device: 1, name: GeForce GTX 980, pci bus id: 0000:07:00.0)
[2016-11-17 10:40:25,058] Making new env: Pendulum-v0
Traceback (most recent call last):
  File "test.py", line 14, in <module>
    env.render()
  File "/home/chentao/software/gym/gym/core.py", line 192, in render
    return self._render(mode=mode, close=close)
  File "/home/chentao/software/gym/gym/envs/classic_control/pendulum.py", line 66, in _render
    from gym.envs.classic_control import rendering
  File "/home/chentao/software/gym/gym/envs/classic_control/rendering.py", line 23, in <module>
    from pyglet.gl import *
  File "/home/chentao/software/anaconda2/envs/tensorflow/lib/python2.7/site-packages/pyglet/gl/__init__.py", line 236, in <module>
    import pyglet.window
  File "/home/chentao/software/anaconda2/envs/tensorflow/lib/python2.7/site-packages/pyglet/window/__init__.py", line 1817, in <module>
    gl._create_shadow_window()
  File "/home/chentao/software/anaconda2/envs/tensorflow/lib/python2.7/site-packages/pyglet/gl/__init__.py", line 205, in _create_shadow_window
    _shadow_window = Window(width=1, height=1, visible=False)
  File "/home/chentao/software/anaconda2/envs/tensorflow/lib/python2.7/site-packages/pyglet/window/xlib/__init__.py", line 163, in __init__
    super(XlibWindow, self).__init__(*args, **kwargs)
  File "/home/chentao/software/anaconda2/envs/tensorflow/lib/python2.7/site-packages/pyglet/window/__init__.py", line 505, in __init__
    config = screen.get_best_config(template_config)
  File "/home/chentao/software/anaconda2/envs/tensorflow/lib/python2.7/site-packages/pyglet/canvas/base.py", line 161, in get_best_config
    configs = self.get_matching_configs(template)
  File "/home/chentao/software/anaconda2/envs/tensorflow/lib/python2.7/site-packages/pyglet/canvas/xlib.py", line 179, in get_matching_configs
    configs = template.match(canvas)
  File "/home/chentao/software/anaconda2/envs/tensorflow/lib/python2.7/site-packages/pyglet/gl/xlib.py", line 29, in match
    have_13 = info.have_version(1, 3)
  File "/home/chentao/software/anaconda2/envs/tensorflow/lib/python2.7/site-packages/pyglet/gl/glx_info.py", line 89, in have_version
    client = [int(i) for i in client_version.split('.')]
ValueError: invalid literal for int() with base 10: 'None'
tlbtlbtlb commented 7 years ago

This is most likely because OpenGL is unable to create a window because tensorflow has grabbed the GPU. You didn't mention what OS, OpenGL or X server you're using, but on Linux you can usually work around this by setting the environment variable LIBGL_ALWAYS_SOFTWARE=1.

yaroslavvb commented 7 years ago

You can also prevent TensorFlow from grabbing GPU by doing "export CUDA_VISIBLE_DEVICES="

taochenshh commented 7 years ago

@tlbtlbtlb Thanks, do you mean I enter export LIBGL_ALWAYS_SOFTWARE=1 in the terminal? I tried this and it did not work. BTW, I used ubuntu 14.04. And when I ran glxinfo | grep 'version', I got:

server glx version string: 1.4
client glx version string: 1.4
GLX version: 1.4
OpenGL core profile version string: 4.3.0 NVIDIA 367.57
OpenGL core profile shading language version string: 4.30 NVIDIA via Cg compiler
OpenGL version string: 4.5.0 NVIDIA 367.57
OpenGL shading language version string: 4.50 NVIDIA

Do I need to install any software to make LIBGL_ALWAYS_SOFTWARE=1 work?

taochenshh commented 7 years ago

@yaroslavvb Thanks, but what if I wanna use tensorflow with GPU while using gym simultaneously? Actually, if I only import tensorflor, no error occurred. Error only occurred when I import tflearn before calling env.render(). And no error occurred either if I import tflearn after env.render()

tlbtlbtlb commented 7 years ago

It may also fix it to import pyglet before tensorflow, which is cleaner than trying to call env.render first.

watts4speed commented 6 years ago

Is there a better fix for this problem. I'm seeing it on Linux Ubuntu 16.04. I'm up to date with the latest patches etc, and I tried all of the above and more and it's still crashing similiar to the OP. Any help is appreciated. I get the stack trace:

/usr/bin/python3.6 /home/pmerrill/pycharm/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 42703 --file /home/pmerrill/dev/openai/baselines/baselines/ddpg/main.py pydev debugger: process 11603 is connecting

Connected to pydev debugger (build 172.4343.24) Traceback (most recent call last): File "/home/pmerrill/pycharm/helpers/pydev/pydevd.py", line 1599, in globals = debugger.run(setup['file'], None, None, is_module) File "/home/pmerrill/pycharm/helpers/pydev/pydevd.py", line 1026, in run pydev_imports.execfile(file, globals, locals) # execute the script File "/home/pmerrill/pycharm/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "/home/pmerrill/dev/openai/baselines/baselines/ddpg/main.py", line 5, in env.render() File "/usr/local/lib/python3.6/dist-packages/gym/core.py", line 150, in render return self._render(mode=mode, close=close) File "/usr/local/lib/python3.6/dist-packages/gym/core.py", line 286, in _render return self.env.render(mode, close) File "/usr/local/lib/python3.6/dist-packages/gym/core.py", line 150, in render return self._render(mode=mode, close=close) File "/usr/local/lib/python3.6/dist-packages/gym/envs/box2d/lunar_lander.py", line 322, in _render from gym.envs.classic_control import rendering File "/usr/local/lib/python3.6/dist-packages/gym/envs/classic_control/rendering.py", line 23, in from pyglet.gl import File "/usr/local/lib/python3.6/dist-packages/pyglet/gl/init.py", line 239, in import pyglet.window File "/usr/local/lib/python3.6/dist-packages/pyglet/window/init.py", line 1884, in gl._create_shadow_window() File "/usr/local/lib/python3.6/dist-packages/pyglet/gl/init.py", line 208, in _create_shadow_window _shadow_window = Window(width=1, height=1, visible=False) File "/usr/local/lib/python3.6/dist-packages/pyglet/window/xlib/init.py", line 166, in init super(XlibWindow, self).init(args, **kwargs) File "/usr/local/lib/python3.6/dist-packages/pyglet/window/init.py", line 512, in init config = screen.get_best_config(template_config) File "/usr/local/lib/python3.6/dist-packages/pyglet/canvas/base.py", line 159, in get_best_config configs = self.get_matching_configs(template) File "/usr/local/lib/python3.6/dist-packages/pyglet/canvas/xlib.py", line 182, in get_matching_configs configs = template.match(canvas) File "/usr/local/lib/python3.6/dist-packages/pyglet/gl/xlib.py", line 31, in match have_13 = info.have_version(1, 3) File "/usr/local/lib/python3.6/dist-packages/pyglet/gl/glx_info.py", line 87, in have_version client_version = self.get_client_version().split()[0] IndexError: list index out of range

Process finished with exit code 1

watts4speed commented 6 years ago

Ok I figured it out. I need to install gym using python3. I had followed the docs which for me installed for python2.7 on the command line. In my IDE(pycharm) I was using python3 When I installed gym with pip3 then things were set up correctly and the crash went away. Hope this helps others.