python-3.xgoogle-colaboratoryopenai-gymstable-baselinespybullet

unabel to load a ppo model


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


Solution

  • 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!