linyiLYi / snake-ai

An AI agent that beats the classic game "Snake".
Apache License 2.0
1.61k stars 359 forks source link

运行时发现的bug #1

Open ShuaiLi-XY opened 1 year ago

ShuaiLi-XY commented 1 year ago

============================= 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。这是什么意思,萌新菜鸟求教。

Sakura-Shino commented 1 year ago

可参考 #https://github.com/linyiLYi/street-fighter-ai/issues/16

image

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})
aijunzhao commented 1 year ago

可参考 #linyiLYi/street-fighter-ai#16

image

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.

linyiLYi commented 1 year ago

如果改了 board 大小,模型输入部分也要改一下,在 snake_game_custom_wrapper 里面