Farama-Foundation / ViZDoom

Reinforcement Learning environments based on the 1993 game Doom :godmode:
https://vizdoom.farama.org/
1.75k stars 404 forks source link

ValueError: setting an array element with a sequence. in learning_stable_baselines.py #516

Closed zfwang615 closed 1 year ago

zfwang615 commented 2 years ago

I'm trying to use examples/python/learning_stable_baselines.py. This example has some questions. By the way, learning_pytorch.py works well.

MY ENV INFO:

First, the env is using 'screen' instead 'rgb' now.

class ObservationWrapper(gym.ObservationWrapper):
...
...
    def __init__(self, env, shape=IMAGE_SHAPE):
        super().__init__(env)
        self.image_shape = shape
        self.image_shape_reverse = shape[::-1]

        # Create new observation space with the new shape
        num_channels = env.observation_space["screen"].shape[-1] # use 'screen' instead 'rgb'
        new_shape = (shape[0], shape[1], num_channels)
        self.observation_space = gym.spaces.Box(0, 255, shape=new_shape, dtype=np.uint8)

    def observation(self, observation):
        observation = cv2.resize(observation["screen"], self.image_shape_reverse) # use 'screen' instead 'rgb'
        return observation

After that, I got followed error:

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

in SB3 dummy_vec_env.py, the error occurredself.buf_obs[key][env_idx]=obs

Could you give me some advice? Thanks in advance for any help.

Miffyli commented 2 years ago

Hey! Sounds like something has gone off with the changes for Gym support. Make sure you are using the newest code when trying things out (clone from the github), but beyond that I do not have bandwidth to debug what could have gone wrong :(.

jkterry1 commented 1 year ago

Hey, stable baselines 3 doesn't support current versions of gym/gymnasium, but has publicly promised to soon. You can either use their beta fork with support for newer versions, wait for them to update, use an older version of this package with an older version of gym, or try cleanrl or another library instead of sb3