Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新人,执行到“python test.py”这一步时,报如下错误,请问有好的解决办法吗? #50

Open
meici2023 opened this issue Apr 26, 2023 · 5 comments

Comments

@meici2023
Copy link

image

@tppig
Copy link

tppig commented May 3, 2023

我也碰到了这个问题。最神奇的是我一开始能跑的,后来不知怎么的突然不能跑了。

重新装一下环境后又可以运行了。可以试一下重新建一个conda环境。

@IAAI-star
Copy link

image

我也是遇到了相似的问题,请问您的目前解决了么?
我问了chatGPT,说是代码与模型不符,让我检查模型啥的,不懂,以下是报错的代码:
(StreetFighterAI) C:\Users\jiaxin\StreetFighterAI\street-fighter-ai-master\main>python test.py
Wrapping the env with a Monitor wrapper
Wrapping the env in a DummyVecEnv.
Wrapping the env in a VecTransposeImage.
Traceback (most recent call last):
File "test.py", line 53, in
model = PPO.load(os.path.join(MODEL_DIR, MODEL_NAME), env=env)
File "C:\Users\jiaxin.conda\envs\StreetFighterAI\lib\site-packages\stable_baselines3\common\base_class.py", line 641, in load
model.set_parameters(params, exact_match=True, device=device)
File "C:\Users\jiaxin.conda\envs\StreetFighterAI\lib\site-packages\stable_baselines3\common\base_class.py", line 574, in set_parameters
attr.load_state_dict(params[name], strict=exact_match)
File "C:\Users\jiaxin.conda\envs\StreetFighterAI\lib\site-packages\torch\nn\modules\module.py", line 2041, in load_state_dict
raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for ActorCriticCnnPolicy:
Unexpected key(s) in state_dict: "pi_features_extractor.cnn.0.weight", "pi_features_extractor.cnn.0.bias", "pi_features_extractor.cnn.2.weight", "pi_features_extractor.cnn.2.bias", "pi_features_extractor.cnn.4.weight", "pi_features_extractor.cnn.4.bias", "pi_features_extractor.linear.0.weight", "pi_features_extractor.linear.0.bias", "vf_features_extractor.cnn.0.weight", "vf_features_extractor.cnn.0.bias", "vf_features_extractor.cnn.2.weight", "vf_features_extractor.cnn.2.bias", "vf_features_extractor.cnn.4.weight", "vf_features_extractor.cnn.4.bias", "vf_features_extractor.linear.0.weight", "vf_features_extractor.linear.0.bias".

@XrbStudying
Copy link

我也遇到了相同的问题,重新建了虚拟环境还是不行,请问有什么解决方案吗?

/home/xrb280/anaconda3/envs/StreetFighterAI2/lib/python3.8/site-packages/stable_baselines3/common/save_util.py:166: UserWarning: Could not deserialize object observation_space. Consider using custom_objects argument to replace this object.
Exception: __randomstate_ctor() takes from 0 to 1 positional arguments but 2 were given
warnings.warn(
Traceback (most recent call last):
File "test.py", line 55, in
model = PPO.load(os.path.join(MODEL_DIR, MODEL_NAME), env=env)
File "/home/xrb280/anaconda3/envs/StreetFighterAI2/lib/python3.8/site-packages/stable_baselines3/common/base_class.py", line 678, in load
raise KeyError("The observation_space and action_space were not given, can't verify new environments")
KeyError: "The observation_space and action_space were not given, can't verify new environments"

@761046683
Copy link

我也是我也是,这个问题咋办呀,解决了滴滴我一下

@JizhiXiang
Copy link

如果KeyError: "The observation_space and action_space were not given, can't verify new environments"报错的话,
将test.py的52~53行换成如下即可解决:

# 参考https://github.com/linyiLYi/street-fighter-ai/issues/16#issuecomment-1515463967
# if not RANDOM_ACTION:
#     # 如果是你自己训练的模型    
#     model = PPO.load(os.path.join(MODEL_DIR, MODEL_NAME), env=env)
if not RANDOM_ACTION:
    # 如果你使用的是linyiLYi提供的模型
    keys = ['high', 'low', 'bounded_above', 'bounded_below']
    setattr(env.observation_space, '_shape', (3,100,128))
    for k in keys:
        new_attr = getattr(env.observation_space, k).reshape(3,100,128)
        setattr(env.observation_space, k, new_attr)
    model = PPO.load(os.path.join(MODEL_DIR, MODEL_NAME), env=env,
                custom_objects = {'observation_space': env.observation_space, 'action_space': env.action_space})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants