如何更新openai.gym.spaces.Dict状态?



AttributeError: 'dict' object没有'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)

我需要改变什么?

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

model = PPO('MultiInputPolicy', env, verbose=1,)

相关内容

  • 没有找到相关文章

最新更新