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

Gymwrapper: support both gym and gymnasium, and support dict_obs and … #547

Merged

Conversation

youliangtan
Copy link
Member

@youliangtan youliangtan commented Nov 4, 2024

As described in: #497 , reopen after v1.5 release

  • Support both gymnasium and gym interfaces. A runtime check will ensure gym>=0.26.0 (which uses terminate and truncate).
  • Support Flatten and Dict Observation. GymWrapper(..., flatten_obs=True), previously only return flatten obs, which is not always desired.
  • Ensure that the .observation_space specifies the correct dtype and shape.

Quick RUn

import robosuite as suite
from robosuite.wrappers.gym_wrapper import GymWrapper
import cv2

if __name__ == '__main__':
    # create environment instance
    env = suite.make(
        env_name="Lift",  # try with other tasks like "Stack" and "Door"
        robots="Panda",   # try with other robots like "Sawyer" and "Jaco"
        has_renderer=True,
        has_offscreen_renderer=True,
        use_camera_obs=True,
    )

    # convert to gym/gymnasium environment
    env = GymWrapper(
        env,
        keys=["robot0_proprio-state", "object-state", "agentview_image"],
        flatten_obs=False, # default is True, we will not flatten the observation
    )
    print(" -> action space:", env.action_space)
    print(" -> observation space:", env.observation_space)
    obs, info = env.reset()

    for i in range(1000):
        # action = np.random.randn(env.robots[0].dof)  # sample random action
        action = env.action_space.sample()
        obs, reward, done, trunc, info = env.step(action)  # take action in the environment
        print(obs.keys(), obs["agentview_image"].shape)

        # Optional camera view viz
        cv2.imshow("Agent View", cv2.cvtColor(obs["agentview_image"], cv2.COLOR_RGB2BGR))
        if cv2.waitKey(1) & 0xFF == ord('q'): break

        env.render()  # render on display

@kevin-thankyou-lin
Copy link
Contributor

Looks good to me:

image

can we flip the cv2 imshow image?

@kevin-thankyou-lin
Copy link
Contributor

Sorry, just realized that script isn't part of the code base. PR looks good

@kevin-thankyou-lin kevin-thankyou-lin merged commit b81bde4 into ARISE-Initiative:master Nov 6, 2024
2 checks passed
@youliangtan youliangtan deleted the enhance-gym-wrapper branch November 6, 2024 08:23
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

Successfully merging this pull request may close these issues.

2 participants