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

Interactive rendering for SafetyGym #24

Open
joshwa71 opened this issue Mar 5, 2023 · 6 comments
Open

Interactive rendering for SafetyGym #24

joshwa71 opened this issue Mar 5, 2023 · 6 comments

Comments

@joshwa71
Copy link

joshwa71 commented Mar 5, 2023

Hi there,

Thanks for the codebase, an awesome algorithm to play around with. I'm trying to render the env to sanity check the agent and am wondering how this is done. I've tried calling the render function in the from_gym.py script but this is not working. Simply running env.render in the step function also is not working.

Any help appreciated, thanks.

@jobesu14
Copy link

jobesu14 commented Mar 5, 2023

That might help.

#2 (comment)

@joshwa71
Copy link
Author

joshwa71 commented Mar 6, 2023

I'm just trying to render a gym env not pygame, any idea in which file I need to call env.render() in order for this to work?

@jobesu14
Copy link

jobesu14 commented Mar 6, 2023

If I am not mistaken, you can still render the gym env as it is done here and get rid of all the pygame specific code...

The render() function of line 22 should be the one you are interested in (the one from your gym env).

Note: in the linked code, the extra callback to render the env is added to the embodied.run.eval_only script, but you can do the same for the embodied.run.train script.

@joshwa71
Copy link
Author

joshwa71 commented Mar 6, 2023

I have instead added a call to the render() function in the from_gym.py step function, though it seems to only display the first frame and then goes black which is odd as the steps counter continues. Code below:

def step(self, action):
if action['reset'] or self._done:
self._done = False
obs = self._env.reset()

  return self._obs(obs, 0.0, is_first=True)
if self._act_dict:
  action = self._unflatten(action)
else:
  action = action[self._act_key]
self._env.render()
obs, reward, self._done, self._info = self._env.step(action)
return self._obs(
    obs, reward,
    is_last=bool(self._done),
    is_terminal=bool(self._info.get('is_terminal', self._done)))

Edit: I am using SafetyGym which uses Mujoco-py backend.

@danijar
Copy link
Owner

danijar commented Mar 7, 2023

You can move the env out of a subprocess/thread with --envs.parallel none, maybe that fixes rendering in that environment?

In general, you can view videos in TensorBoard if your environment has an image observation key (or you can specify different keys via e.g. --run.log_video_keys top_down_image side_image.

For mujoco specifically, you may want to check/change the env variable MUJOCO_PY, which I set to egl in the FromDM wrapper to allow rendering on headless servers.

@danijar danijar changed the title Rendering runs Interactive rendering for SafetyGym Mar 7, 2023
@vtopiatech
Copy link

vtopiatech commented Jan 25, 2024

Hey @danijar excellent work with DreamerV3! Do you know is there any simple way to "play together" with the AI e.g. in Crafter? Meaning if I press a key, it takes an action in the game (while the AI is playing)

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

4 participants