健身房:无法设置观察空间

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

我正在尝试在 gym-duckietown 的 Gym 环境中训练强化学习代理。我一直在使用他们的 github 存储库中的模板实现时遇到问题。 该模板的代码:

import gym
from gym import spaces
import numpy as np
from PIL import Image


class ResizeWrapper(gym.ObservationWrapper):
    def __init__(self, env=None, shape=(64, 64, 3)):
        super(ResizeWrapper, self).__init__(env)
        self.observation_space.shape = shape
        self.observation_space = spaces.Box(
            self.observation_space.low[0, 0, 0],
            self.observation_space.high[0, 0, 0],
            shape,
            dtype=self.observation_space.dtype,
        )
        self.shape = shape

    def observation(self, observation):

        return np.array(Image.fromarray(observation).resize(self.shape[0:2]))

错误指向

self.observation_space.shape = shape
AttributeError: can't set attribute

在 VSCode 中将鼠标悬停在它上面显示 shape 返回一个不可变属性,但显然模板代码仍然试图将它设置为不同的值。我没有发现其他人遇到这个问题。

python reinforcement-learning openai-gym
© www.soinside.com 2019 - 2024. All rights reserved.