Farama-Foundation / Gymnasium

An API standard for single-agent reinforcement learning environments, with popular reference environments and related utilities (formerly Gym)
https://gymnasium.farama.org
MIT License
6.25k stars 720 forks source link

[Question] Collect multiple images from different cameras #1050

Open zichunxx opened 1 month ago

zichunxx commented 1 month ago

Question

Hi!

Is it possible to require multiple images from different cameras using Gymnasium API?

The list of camera names cannot be passed during registration and only one camera string is feasible.

Is there any elegant way to realize this feature?

Thanks.

zichunxx commented 1 month ago

I made a wrapper to collect images from different cameras:

class ImageCollection(gym.Wrapper, gym.utils.RecordConstructorArgs):
    def __init__(self, env: gym.Env, camera_names: list):
        gym.utils.RecordConstructorArgs.__init__(self, camera_names=camera_names)
        gym.Wrapper.__init__(self, env)

        assert env.render_mode == "rgb_array"
        self.unwrapped_model = env.model
        self.unwrapped_mujoco_renderer = env.mujoco_renderer
        self.camera_names = camera_names

    def render(self):
        frames = []
        for camera_name in self.camera_names:
            frames.append(self.unwrapped_mujoco_renderer.render(render_mode=self.render_mode, camera_name=camera_name))
        return frames

I am not sure if the above is the best way to realize this. Please feel free to offer some suggestions.

pseudo-rnd-thoughts commented 1 month ago

This solution looks like the best available currently

zichunxx commented 1 month ago

Thanks for your time to check the above code snippet.

Kallinteris-Andreas commented 1 month ago

The proper solution for MuJoCo Gymnasium would be to support multiple MujocoRendering objects in MujocoEnv, one for each camera, that will enable different configurations such as using "rgb_array" and "depth_array" cameras at the same time and multiple "human" render windows at the same time.

zichunxx commented 1 month ago

The proper solution for MuJoCo Gymnasium would be to support multiple MujocoRendering objects in MujocoEnv, one for each camera, that will enable different configurations such as using "rgb_array" and "depth_array" cameras at the same time and multiple "human" render windows at the same time.

That would be great if this is implemented.

pseudo-rnd-thoughts commented 1 month ago

@Kallinteris-Andreas The render api doesn't seem built to support as by default so would recommend that until this is a common feature wanted by many users, I wouldn't implement it within the codebase.