-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
Rendering a single frame and 'human' with MuJoCo #2989
Comments
Would you be able to provide an example script to test with? |
No problem! Let's take import gym
env = gym.make('Humanoid-v4')
obs = env.reset()
for _ in range(1000):
action = env.action_space.sample()
obs, reward, done, info = env.step(action)
env.render() Now, let's assume that in the scene, there is a camera in the scene that should give the observation space for the agent. A problem will raise from this as I cannot get the single RGB array from the scene while still being able to watch the scene through MuJoCo's renderer. A partial solution is to show the scene by showing the images, such as: import gym
import cv2
env = gym.make('Humanoid-v4', render_mode="single_rgb_array")
obs = env.reset()
for _ in range(1000):
action = env.action_space.sample()
obs, reward, done, info = env.step(action)
image = env.render()
cv2.imshow("image", image)
cv2.waitKey(1) Is there any solution in which both are working? Regarding the other issue. To replicate. just set the import gym
import cv2
env = gym.make('Humanoid-v4', render_mode="single_rgb_array",
width=600, height=600)
obs = env.reset()
for _ in range(1000):
action = env.action_space.sample()
obs, reward, done, info = env.step(action)
image = env.render()
cv2.imshow("image", image)
cv2.waitKey(1) , which throws the following error:
The latter seems to be an issue more related to |
@tudorjnu If I understood correctly, you want to use For your case, I suggest to initialize the env with In this way, using the Wrapper you will see the human rendering, and when you need you can call gather an RGB frame from the original env. |
Yup, that is exactly what I was trying to do. It seems that when I wrap the environment it renders a black screen only. |
You are right, this snippet is not working properly; @rodrigodelazcano @Markus28 do you have any idea why? import gym
from gym.wrappers import HumanRendering
env = HumanRendering(gym.make('Humanoid-v4', render_mode="single_rgb_array"))
env.reset()
for _ in range(100):
env.step(env.action_space.sample())
env.close() |
Yes, we are investigating it. It looks like something weird is happening in MuJoCo rendering. Opening a blank PyGame window (completely independently of what we do with the environment) will cause MuJoCo to render only black frames. Check out this snippet: import numpy as np
import gym
import pygame
env = gym.make("Ant-v4", render_mode="single_rgb_array")
env.reset()
env.render()
########## Comment out to compare #############
pygame.init()
pygame.display.init()
window = pygame.display.set_mode((259, 342))
########## Comment out to compare #############
for _ in range(500):
_, _, done, _ = env.step(env.action_space.sample())
print(np.max(env.render()))
if done:
env.reset() We tried using osmesa instead of glfw but that didn't fix the problem. I guess this problem might be difficult to debug. |
Ohh, that's a bummer. I will use the standard In terms of the rendering, would it be possible in the case of MuJoCo, that the renderer from the wrapper would also be MuJoCo's renderer? This is because it offers some extra functionality such as showing contact forces, increasing the speed and so on. |
Nope I don’t think that will be possible. The new render API essentially forces us to choose one render mode during initialization, so we can’t really access human and rgb_array rendering of mujoco environments at the same time. The original idea behind the HumanRendering wrapper wasn’t actually to circumvent this, but to add human rendering to environments that don’t implement it natively, using their rgb_array renders. |
Ohh I see. So the image-based environments would lose their native rendering capabilities. I would leave the issue open for the other two problems, the wrapper not rendering and the size >500 making the environment crash for now. |
Hi! For "So the image-based environments would lose their native rendering capabilities." I guess you just use this for visualization and debug purpose, thus the performance is not critical. |
gym/gym/envs/mujoco/mujoco_env.py Lines 376 to 412 in 6e2e921
gym/gym/envs/mujoco/mujoco_env.py Lines 429 to 448 in 6e2e921
That is - offscreen viewer( gym/gym/envs/mujoco/mujoco_env.py Lines 77 to 83 in 6e2e921
|
Would you want to make a PR to solve the issue |
Yes I can make a PR, but I'am not sure that is the root cause. I am trying to reproduce the problem locally, then I will make a PR. |
Bad news: it seems that this is not the root cause. |
I guess this problem might be related to some global state of GL... (i.e. makecurrent) |
@YouJiacheng @tudorjnu Is this issue solved? If not, what is the remaining issue? |
@pseudo-rnd-thoughts Can confirm that now rendering works with different image sizes. Furthermore, wrapping the "rgb_arrray" environment in To clarify, the remaining issue is the one mentioned by @YouJiacheng one comment above, in which the renderer produces only black frames. |
Thanks @tudorjnu, @rodrigodelazcano (when you have time), could you see if this is an issue with our implementation or mujoco. |
Hello,
I have a problem with the new renderer when combined with MuJoCo.
I am creating a new environment that uses an image-based observation which works well with
render_mode="single_rgb_array"
. However, I would like to be able to visualise the model with MuJoCo's interactive renderer which currently doesn't seem possible.Any current workarounds or ideas on how this can be accomplished? Thank you!
Additionally, a possible bug. When rendering with a greater image size than 500, I get the following error:
The text was updated successfully, but these errors were encountered: