微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

KeyError:在尝试使用 OpenAI stable-baselines3 和 Gym 进行多智能体强化学习时的“观察”

如何解决KeyError:在尝试使用 OpenAI stable-baselines3 和 Gym 进行多智能体强化学习时的“观察”

我正在尝试使用饥饿鹅健身房 here 来训练 PPO:

from kaggle_environments import make
from stable_baselines3 import PPO

directions = {0:'EAST',1:'norTH',2:'WEST',3:'SOUTH'}
loaded_model = PPO.load('logs\\dqn2ppo_nonvec\\model')

def agent_ppo(obs,config):
    a = directions[loaded_model.predict(obs)[0]]
    return a 
    
env = make('hungry_geese',debug=True)
env.run([agent_ppo,'agent_bfs.py'])
env.render(mode="ipython")

但我的游戏只玩了一步。使用调试运行后,我得到了以下跟踪:

Traceback (most recent call last):
  File "c:\users\crrma\.virtualenvs\hungry_geese-ept5y6nv\lib\site-packages\kaggle_environments\agent.py",line 151,in act
    action = self.agent(*args)
  File "<ipython-input-29-faad97d317d6>",line 5,in agent_ppo
    a = directions[loaded_model.predict(obs)[0]]
  File "c:\users\crrma\.virtualenvs\hungry_geese-ept5y6nv\lib\site-packages\stable_baselines3\common\base_class.py",line 497,in predict
    return self.policy.predict(observation,state,mask,deterministic)
  File "c:\users\crrma\.virtualenvs\hungry_geese-ept5y6nv\lib\site-packages\stable_baselines3\common\policies.py",line 262,in predict
    observation = ObsDictWrapper.convert_dict(observation)
  File "c:\users\crrma\.virtualenvs\hungry_geese-ept5y6nv\lib\site-packages\stable_baselines3\common\vec_env\obs_dict_wrapper.py",line 68,in convert_dict
    return np.concatenate([observatio I was trying to use hungry-geese gym [here](https://www.kaggle.com/victordelafuente/dqn-goose-with-stable-baselines3-pytorch#) to train PPO. But my game was getting played for only one step. After running with debug ON I got following trace:

Traceback (most recent call last):
  File "c:\users\crrma\.virtualenvs\hungry_geese-ept5y6nv\lib\site-packages\kaggle_environments\agent.py",in convert_dict
    return np.concatenate([observation_dict[observation_key],observation_dict[goal_key]],axis=-1)
KeyError: 'observation'

所以我在 vscode 中调试了更多。从下面的屏幕截图中可以看出,observationdesired_goal 键都没有出现在 observation_dict 中。

image

这也是我调试上述调用的方式:

image

我是否错误地使用了 API 导致这种情况发生(我是 API 的新手)? (或者这可能是一个错误,我觉得不太可能。)

Colab notebookmodel

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。