代码之家  ›  专栏  ›  技术社区  ›  desert_ranger

StableBaselines3-NotImplementedError:不支持观察空间

  •  0
  • desert_ranger  · 技术社区  · 2 年前

    我试着跑 cleanrl Pendulum-v1 环境我做到了 here 和更改默认值 env-id parser.add_argument("--env-id", type=str, default="Pendulum-v1",help="the id of the environment")

    然而,我不断地得到错误- NotImplementedError: Box([-1. -1. -8.], [1. 1. 8.], (3,), <class 'numpy.float32'>) observation space is not supported

    因此,我将此错误调试到从导入的ReplayBuffer SB3 。这是 problem function -

    def get_obs_shape(
        observation_space: spaces.Space,
    ) -> Union[Tuple[int, ...], Dict[str, Tuple[int, ...]]]:
        """
        Get the shape of the observation (useful for the buffers).
    
        :param observation_space:
        :return:
        """
        if isinstance(observation_space, spaces.Box):
            return observation_space.shape
        elif isinstance(observation_space, spaces.Discrete):
            # Observation is an int
            return (1,)
        elif isinstance(observation_space, spaces.MultiDiscrete):
            # Number of discrete features
            return (int(len(observation_space.nvec)),)
        elif isinstance(observation_space, spaces.MultiBinary):
            # Number of binary features
            return observation_space.shape
        elif isinstance(observation_space, spaces.Dict):
            return {key: get_obs_shape(subspace) for (key, subspace) in observation_space.spaces.items()}  # type: ignore[misc]
    
        else:
            raise NotImplementedError(f"{observation_space} observation space is not supported")
    

    我试着打印 observation_space 形状,这就是我得到的-

    Box([-1. -1. -8.], [1. 1. 8.], (3,), float32) 。你知道SB3为什么不接受我的观察形状吗?

    0 回复  |  直到 2 年前