自定义环境中的 OpenAI Gym RLLib AssertionError

问题描述 投票:0回答:1

我有一个自定义环境:

class PlacementEnv(gym.Env)

    def __init__(self, sb, bb):
        self.reward = None
        self.smallBoxes = sb
        self.bigBoxes = bb

        # Define the observation space

        i = 1
        space_to_observe = {}

        for smallbox in self.smallBoxes:
            highx = smallbox.pointMax_X
            highy = smallbox.pointMax_Y
            space_single_smallbox = {
                'points_smallbox' + str(i): gym.spaces.Box(low=np.array([0, 0]), high=np.array([highx, highy]),
                                                            shape=(2,), dtype=int),
                'bbID_smallbox' + str(i): gym.spaces.Discrete(len(self.bigBoxes))}
            space_to_observe = space_to_observe | space_single_smallbox
            i = i+1

        dict_space = gym.spaces.Dict(space_to_observe)
        self.observation_space = dict_space

        # Define action space
        self.action_space = spaces.Tuple((
            spaces.Discrete(len(self.bigBoxes)),
            spaces.Box(low=0, high=3000, shape=(2,), dtype=int), 
            spaces.Discrete(8))
        ))

    def reset(self):
        i = 0
        space_to_observe = {}

        for smallbox in self.smallBoxes:
            smallbox.bb_id = None
            smallbox.insertion_point = (0, 0)
            smallbox.rotation_angle = 0
            highx = smallbox.pointMax_X
            highy = smallbox.pointMax_Y
            space_single_smallbox = {
                'points_smallbox' + str(i): gym.spaces.Box(low=np.array([0, 0]), high=np.array([highx, highy]),
                                                            shape=(2,), dtype=int),
                'bbID_smallbox' + str(i): gym.spaces.Discrete(len(self.bigBoxes))}
            space_to_observe = space_to_observe | space_single_smallbox
            i = i+1
        dict_space = gym.spaces.Dict(space_to_observe)
        self.observation_space = dict_space
        return self.observation_space

当我运行代码时,出现以下错误:

AssertionError: ERROR: `elem` (Box(0, 2, (2,), int16)) must be np.array, float or int!

我不明白为什么会出现这个错误。我看不到任何明确的提示。

信息:对于每个人来说,这段代码似乎都很熟悉。这是我昨天的帖子,我现在已经删除了,因为我取得了一些进展(我认为:-))

我是 Python 和 OpenAI Gym 的初学者。这是我的第一个项目。

感谢任何有帮助的回复。 编辑:抱歉,每次我想以“嗨”或“大家好”开头时,我发布问题时都会被截断。不想不客气! :) 我在网上搜索没有成功

numpy openai-gym rllib
1个回答
0
投票

问题是

reset
应该从环境返回初始观察——而不是观察空间本身。所以你应该根据你的问题返回一个有效的观察结果,或者你可以做像
return self.observation_space.sample()

这样的事情
© www.soinside.com 2019 - 2024. All rights reserved.