Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to load OpenGL: Found 0 GPUs for rendering. Using device 0. #665

Closed
hbonnavaud opened this issue Dec 29, 2021 · 18 comments
Closed

Failed to load OpenGL: Found 0 GPUs for rendering. Using device 0. #665

hbonnavaud opened this issue Dec 29, 2021 · 18 comments

Comments

@hbonnavaud
Copy link

Describe the bug
Unable to generage rgb array of environment state / image using environment.render (mode="rgb_array").

To Reproduce
Run the following code:

import mujoco_py
import gym
from gym.envs.mujoco.half_cheetah_v3 import HalfCheetahEnv
import numpy as np
from mujoco_py import GlfwContext

GlfwContext(offscreen=True)  # Trying to initialize an OpenGL context

env = HalfCheetahEnv()
test = env.reset()
mode_human = False  # Work well in human mode, don't work in "rgb_array" mode
image = env.render(mode="human" if mode_human else "rgb_array")
print("image is: ")
print(image)

Expected behavior
An image is returned and stored inside image variable, as a numpy.ndarray of pixels values.

Error Messages

Creating offscreen glfw
Found 0 GPUs for rendering. Using device 0.
Device id outside of range of available devices.
Traceback (most recent call last):
  File "mujoco_test.py", line 11, in <module>
    image = env.render(mode="human" if mode_human else "rgb_array")
  File "/home/disc/h.bonnavaud/.local/lib/python3.8/site-packages/gym/envs/mujoco/mujoco_env.py", line 157, in render
    self._get_viewer(mode).render(width, height, camera_id=camera_id)
  File "/home/disc/h.bonnavaud/.local/lib/python3.8/site-packages/gym/envs/mujoco/mujoco_env.py", line 186, in _get_viewer
    self.viewer = mujoco_py.MjRenderContextOffscreen(self.sim, -1)
  File "mujoco_py/mjrendercontext.pyx", line 46, in mujoco_py.cymj.MjRenderContext.__init__
  File "mujoco_py/mjrendercontext.pyx", line 114, in mujoco_py.cymj.MjRenderContext._setup_opengl_context
  File "mujoco_py/opengl_context.pyx", line 130, in mujoco_py.cymj.OffscreenOpenGLContext.__init__
RuntimeError: Failed to initialize OpenGL

Desktop (please complete the following information):

  • OS: ubuntu 20.04
  • Python Version 3.8.10
  • Mujoco Version 2.1
  • mujoco-py version 2.0.2.13

Environment

  • output of: echo $LD_LIBRARY_PATH -> /home/disc/h.bonnavaud/.mujoco/mujoco210/bin:/usr/lib/nvidia

  • output of: echo $HOME -> /home/disc/h.bonnavaud

  • output of: echo $USER -> h.bonnavaud

  • output of: echo $LD_PRELOAD -> /usr/lib/x86_64-linux-gnu/libGLEW.so

  • output of: glxinfo | grep "OpenGL version" -> OpenGL version string: 4.6 (Compatibility Profile) Mesa 21.0.3

Additional context
I found many hints about this problem but nothing about an error like "Found 0 GPUs for rendering. Using device 0.". Reading this line, the problem looks obvious since indice 0 of an empty list is out of range, but I have no idea how to solve it. Do not hesitate to redirect me if I'm at the wrong place, or if you know any helpful other issues reports. Thanks a lot.

@tudorjnu
Copy link

I found out that if I comment the loading of the library, it works to render an image. I am really not sure what is wrong with it, maybe someone with more experience can help us here.
#export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libGLEW.so

@kaixindelele
Copy link

Thank you! In other issues, I wrote the export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libGLEW.so into ~/.bashrc, and then I couldn't get an rgb_array for env.render('rgb_array') directly, I must first env.render(), then get an img from env.render ("rgb_array").

@tudorjnu
Copy link

Yes, that is exactly the behaviour I am experiencing. I can render images only with the commented lines but then I cannot render the environment and vice versa. It would be amazing if both worked at the same time without altering the ~/.bashrc file.

@kaixindelele
Copy link

What's very annoying is, different Ubuntu versions also affect the render of mujoco (version 2.0 and below). I list some common permutations here:
Conflict between render and image of robosuite

Of course, you may need to Google translate~

@nikhilweee
Copy link

nikhilweee commented Feb 24, 2022

There have been multiple issues which relate to the same error (#598, #187, #390) but unfortunately none of them worked for me. What worked was to change this line in <site_packages>/gym/envs/mujoco/mujoco_env.py to:

self.viewer = mujoco_py.MjRenderContextOffscreen(self.sim, None, -1)

You can find the location of <site_packages> in your system by using pip show gym.

@hbonnavaud
Copy link
Author

Ty @nikhilweee, maybe this correction should be included inside the mujoco.py code, and shouldn't be something the user should change?

@tudorjnu
Copy link

@nikhilweee, you just made my life so much easier! Thank you for your answer!

@tudorjnu
Copy link

@nikhilweee, are you able to render without starting the terminal or id with the graphics card? For me it throws the error of libGL error: failed to load driver: iris.

@nikhilweee
Copy link

nikhilweee commented Feb 24, 2022

Ty @nikhilweee, maybe this correction should be included inside the mujoco.py code, and shouldn't be something the user should change?

@hbonnavaud It definitely shouldn't be something that the user needs to change, so maybe a PR would help? Another way maybe is to create a wrapper which fixes this?

@nikhilweee, are you able to render without starting the terminal or id with the graphics card? For me it throws the error of libGL error: failed to load driver: iris.

@tudorjnu I usually render offscreen using xvfb-run -a, but if it's a driver issue that suggests you have a missing file?

@pjhae
Copy link

pjhae commented Jun 19, 2022

There have been multiple issues which relate to the same error (#598, #187, #390) but unfortunately none of them worked for me. What worked was to change this line in <site_packages>/gym/envs/mujoco/mujoco_env.py to:

self.viewer = mujoco_py.MjRenderContextOffscreen(self.sim, None, -1)

You can find the location of <site_packages> in your system by using pip show gym.

Thankyou!!! you make my life very easier :)
감사합니다

@herene
Copy link

herene commented Feb 22, 2023

I use this method, but there are two Creating window glfw in my program, and one is stuck because it doesn't get any output display information. Do you know why? Thank you very much for your answer!!

@kaixindelele
Copy link

I use this method, but there are two Creating window glfw in my program, and one is stuck because it doesn't get any output display information. Do you know why? Thank you very much for your answer!!

没太懂你的问题,建议报错贴详细信息,另外可以先参考一下我的这个教程:https://github.com/kaixindelele/Mujoco-Issues#robosuite%E7%9A%84render%E5%92%8Cimage%E5%86%B2%E7%AA%81%E9%97%AE%E9%A2%98

@herene
Copy link

herene commented Feb 22, 2023

没太懂你的问题,建议报错贴详细信息,另外可以先参考一下我的这个教程:https://github.com/kaixindelele/Mujoco-Issues#robosuite%E7%9A%84render%E5%92%8Cimage%E5%86%B2%E7%AA%81%E9%97%AE%E9%A2%98

我看到了一个同学可以同时拿到渲染场景和图片(https://blog.csdn.net/zhangkefang45/article/details/107313009?spm=1001.2014.3001.5502),所以就想尝试一下,但是我这样做之后画面一闪而过,且提示我Failed to initialize OpenGL,
我尝试按照上述说法更改MjRenderContextOffscreen,得到了下面这样的结果
image

@kaixindelele
Copy link

没太懂你的问题,建议报错贴详细信息,另外可以先参考一下我的这个教程:https://github.com/kaixindelele/Mujoco-Issues#robosuite%E7%9A%84render%E5%92%8Cimage%E5%86%B2%E7%AA%81%E9%97%AE%E9%A2%98

我看到了一个同学可以同时拿到渲染场景和图片(https://blog.csdn.net/zhangkefang45/article/details/107313009?spm=1001.2014.3001.5502),所以就想尝试一下,但是我这样做之后画面一闪而过,且提示我Failed to initialize OpenGL, 我尝试按照上述说法更改MjRenderContextOffscreen,得到了下面这样的结果 image

你看我的帖子了么?这个很大程度上是因为你的Ubuntu版本是16.04,而你参考的博客的版本可能是18以上。至于为什么,我还不太清楚。如果说错了,可以先贴出来看看~

@herene
Copy link

herene commented Feb 23, 2023

没太懂你的问题,建议报错贴详细信息,另外可以先参考一下我的这个教程:https://github.com/kaixindelele/Mujoco-Issues#robosuite%E7%9A%84render%E5%92%8Cimage%E5%86%B2%E7%AA%81%E9%97%AE%E9%A2%98

我看到了一个同学可以同时拿到渲染场景和图片(https://blog.csdn.net/zhangkefang45/article/details/107313009?spm=1001.2014.3001.5502),所以就想尝试一下,但是我这样做之后画面一闪而过,且提示我Failed to initialize OpenGL, 我尝试按照上述说法更改MjRenderContextOffscreen,得到了下面这样的结果 image

你看我的帖子了么?这个很大程度上是因为你的Ubuntu版本是16.04,而你参考的博客的版本可能是18以上。至于为什么,我还不太清楚。如果说错了,可以先贴出来看看~

我的ubuntu系统是20.04的,我也没搞清楚为什么在会出现两个viewer,我并没有更改过底层的rende函数,现在采取的方案就是不使用gym,只在mujoco中渲染得到我自己设定的camera的rgb和depth。

@sainavaneet
Copy link

没太懂你的问题,建议报错贴详细信息,另外可以先参考一下我的这个教程:https://github.com/kaixindelele/Mujoco-Issues#robosuite%E7%9A%84render%E5%92%8Cimage%E5%86%B2%E7%AA%81%E9%97%AE%E9%A2%98

I saw a classmate who could get both the rendered scene and the image (https://blog.csdn.net/zhangkefang45/article/details/107313009?spm=1001.2014.3001.5502), so I wanted to try it, but when I did so, the screen flashed and I was prompted to Failed To initialize OpenGL, I tried changing the MjRenderContextOffscreen as described above and got something like this image

你看我的帖子了么?这个很大程度上是因为你的Ubuntu版本是16.04,而你参考的博客的版本可能是18以上。至于为什么,我还不太清楚。如果说错了,可以先贴出来看看~

我的ubuntu系统是20.04的,我也没搞清楚为什么在会出现两个viewer,我并没有更改过底层的rende函数,现在采取的方案就是不使用gym,只在mujoco中渲染得到我自己设定的camera的rgb和depth。

i am also getting the mujoco_py viewer but i dont required it did you solve this problem ??

@pjhae
Copy link

pjhae commented Apr 29, 2024

If you are running rendering and an RGB display for training simultaneously, it is normal for two windows to open, and seeing a black screen is typical.

If you have attempted training, it should be working properly even if the screen is black.
To check if the values are being outputted correctly, you can use matplotlib to visualize them.

One tip would be not to render twice; instead, concatenate the RGB vectors and create a program that automatically saves the video, which is much more efficient.

Have a nice day :)

@sainavaneet
Copy link

If you are running rendering and an RGB display for training simultaneously, it is normal for two windows to open, and seeing a black screen is typical.

If you have attempted training, it should be working properly even if the screen is black. To check if the values are being outputted correctly, you can use matplotlib to visualize them.

One tip would be not to render twice; instead, concatenate the RGB vectors and create a program that automatically saves the video, which is much more efficient.

Have a nice day :)

thank you got it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants