snake-ai
snake-ai copied to clipboard
运行时发现的bug
============================= test session starts ============================= platform win32 -- Python 3.9.12, pytest-7.1.1, pluggy-1.0.0 -- D:\anaconda\python.exe cachedir: .pytest_cache rootdir: E:\python_project\snake-ai-other\main plugins: anyio-3.5.0 collecting ... test_cnn.py:None (test_cnn.py) test_cnn.py:25: in <module> model = MaskablePPO.load(MODEL_PATH) D:\anaconda\lib\site-packages\stable_baselines3\common\base_class.py:687: in load raise KeyError("The observation_space and action_space were not given, can't verify new environments") E KeyError: "The observation_space and action_space were not given, can't verify new environments" collected 0 items / 1 error
报错点:D:\anaconda\lib\site-packages\stable_baselines3\common\base_class.py:687
断点调试发现 observation_space were not given。这是什么意思,萌新菜鸟求教。
可参考 #https://github.com/linyiLYi/street-fighter-ai/issues/16
keys = ['high', 'low', 'bounded_above', 'bounded_below']
setattr(env.observation_space, '_shape', (3,84,84))
for k in keys:
new_attr = getattr(env.observation_space, k).reshape(3,84,84)
setattr(env.observation_space, k, new_attr)
# Load the trained model
model = MaskablePPO.load(MODEL_PATH,env=env,custom_objects={'observation_space': env.observation_space, 'action_space': env.action_space})
可参考 #linyiLYi/street-fighter-ai#16
keys = ['high', 'low', 'bounded_above', 'bounded_below'] setattr(env.observation_space, '_shape', (3,84,84)) for k in keys: new_attr = getattr(env.observation_space, k).reshape(3,84,84) setattr(env.observation_space, k, new_attr) # Load the trained model model = MaskablePPO.load(MODEL_PATH,env=env,custom_objects={'observation_space': env.observation_space, 'action_space': env.action_space})
知道怎么改board大小吗,12*12感觉有点小,改成24,就报错了,也是这个ValueError: Error: Unexpected observation shape (72, 72, 3) for Box environment, please use (3, 84, 84) or (n_env, 3, 84, 84) for the observation shape.
如果改了 board 大小,模型输入部分也要改一下,在 snake_game_custom_wrapper 里面