UNABEL加载PPO模型

发布于 2025-02-08 10:35:09 字数 1940 浏览 3 评论 0原文

您好,我已经从stabel_baselines3上培训了一个PPO模型3,我保存了它,

model.save("model")

但是当我尝试加载它时,我会收到以下错误:

m = PPO.load("model", env=env)
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_25649/121834194.py in <module>
      2 env = e.MinitaurBulletEnv(render=False)
      3 env.reset()
----> 4 m2 = PPO.load("model", env=env)
      5 for episode in range(1, 6):
      6     obs = env.reset()

~/anaconda3/lib/python3.8/site-packages/stable_baselines3/common/base_class.py in load(cls, path, env, device, custom_objects, **kwargs)
    668             env = cls._wrap_env(env, data["verbose"])
    669             # Check if given env is valid
--> 670             check_for_correct_spaces(env, data["observation_space"], data["action_space"])
    671         else:
    672             # Use stored env, if one exists. If not, continue as is (can be used for predict)

~/anaconda3/lib/python3.8/site-packages/stable_baselines3/common/utils.py in check_for_correct_spaces(env, observation_space, action_space)
    217     :param action_space: Action space to check against
    218     """
--> 219     if observation_space != env.observation_space:
    220         raise ValueError(f"Observation spaces do not match: {observation_space} != {env.observation_space}")
    221     if action_space != env.action_space:

~/anaconda3/lib/python3.8/site-packages/gym/spaces/box.py in __eq__(self, other)
    138 
    139     def __eq__(self, other):
--> 140         return isinstance(other, Box) and (self.shape == other.shape) and np.allclose(self.low, other.low) and np.allclose(self.high, other.high)

AttributeError: 'Box' object has no attribute 'shape'

知道env是Pybullet的盒子Env,

import pybullet_envs.bullet.minitaur_gym_env as e
import gym

env = e.MinitaurBulletEnv(render=False)
env.reset()

其他信息是该模型完美地加载了合作

hello I've trained a PPO model from stabel_baselines3 on collab I saved it

model.save("model")

but when I tried loading it I got the following error:

m = PPO.load("model", env=env)
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_25649/121834194.py in <module>
      2 env = e.MinitaurBulletEnv(render=False)
      3 env.reset()
----> 4 m2 = PPO.load("model", env=env)
      5 for episode in range(1, 6):
      6     obs = env.reset()

~/anaconda3/lib/python3.8/site-packages/stable_baselines3/common/base_class.py in load(cls, path, env, device, custom_objects, **kwargs)
    668             env = cls._wrap_env(env, data["verbose"])
    669             # Check if given env is valid
--> 670             check_for_correct_spaces(env, data["observation_space"], data["action_space"])
    671         else:
    672             # Use stored env, if one exists. If not, continue as is (can be used for predict)

~/anaconda3/lib/python3.8/site-packages/stable_baselines3/common/utils.py in check_for_correct_spaces(env, observation_space, action_space)
    217     :param action_space: Action space to check against
    218     """
--> 219     if observation_space != env.observation_space:
    220         raise ValueError(f"Observation spaces do not match: {observation_space} != {env.observation_space}")
    221     if action_space != env.action_space:

~/anaconda3/lib/python3.8/site-packages/gym/spaces/box.py in __eq__(self, other)
    138 
    139     def __eq__(self, other):
--> 140         return isinstance(other, Box) and (self.shape == other.shape) and np.allclose(self.low, other.low) and np.allclose(self.high, other.high)

AttributeError: 'Box' object has no attribute 'shape'

knowing that the env is a box env from pybullet

import pybullet_envs.bullet.minitaur_gym_env as e
import gym

env = e.MinitaurBulletEnv(render=False)
env.reset()

additional info is that the model loaded perfectly in collab

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁人与我共长歌 2025-02-15 10:35:09

从您的问题来看,我无法分辨您是否在Google Colab上工作,但是如果您是,我认为加载时绝对应该包括保存模型的整个路径。也许您也需要这样做,即使不是在Colab中。

我的意思是,当您加载模型时,您的代码线可能看起来像这样:

m = PPO.load("./model.zip/", env=env)

我希望这会有所帮助!

From your question, I can't tell if you are or aren't working on Google Colab, but if you are, I think you should definitely include the whole path to the saved model when you load it. Maybe you need to do this even if not in Colab.

What I mean is that your line of code should probably look something like this when you're loading the model:

m = PPO.load("./model.zip/", env=env)

I hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文