0

“AttributeError:‘dict’对象没有‘flatten’属性”。

运行以下代码时出现此错误:

import math
from gym import Env
from gym.spaces import Discrete, Box, Dict, Tuple, MultiBinary, MultiDiscrete

from stable_baselines3 import PPO
screen_width = 900

class GameEnv(Env):
    def __init__(self):
        self.action_space = Discrete(5)

        observation_positions = Box(low=0, high=screen_width, shape=(2,))

        self.observation_space = Dict({'observation_positions': observation_positions})

        self.state = self.observation_space.sample()

    def step(self, action):
        self.state = self.observation_space.sample()

    def render(self):
        pass

    def reset(self):
        return self.state


env = GameEnv()

model = PPO('MlpPolicy', env, verbose=1,)
model.learn(total_timesteps=1000)

我必须改变什么?

4

1 回答 1

1

使用观察空间时,您可能必须使用MultiInputPolicy而不是MlpPolicy作为类的第一个参数:PPODict

model = PPO('MultiInputPolicy', env, verbose=1,)
于 2021-08-19T09:59:38.460 回答