Can't load with SB3-v2.3.2 and Imitation-v1.0.0
#1
by
Boshi666
- opened
File "path/to/env/lib/python3.8/site-packages/stable_baselines3/common/base_class.py", line 707, 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"
Using the following code, stable-baselines3=2.3.2, imitation=1.0.0
import numpy as np
import gymnasium as gym
from stable_baselines3.common.evaluation import evaluate_policy
from imitation.algorithms import bc
from imitation.data import rollout
from imitation.data.wrappers import RolloutInfoWrapper
from imitation.policies.serialize import load_policy
from imitation.util.util import make_vec_env
rng = np.random.default_rng(0)
env = make_vec_env(
"seals:seals/CartPole-v0",
rng=rng,
n_envs=1,
post_wrappers=[lambda env, _: RolloutInfoWrapper(env)], # for computing rollouts
)
expert = load_policy(
"ppo-huggingface",
organization="HumanCompatibleAI",
env_name="seals-CartPole-v0",
venv=env,
# observation_space=env.observation_space,
# action_space=env.action_space
)
rollouts = rollout.rollout(
expert,
env,
rollout.make_sample_until(min_timesteps=None, min_episodes=50),
rng=rng,
)
transitions = rollout.flatten_trajectories(rollouts)
bc_trainer = bc.BC(
observation_space=env.observation_space,
action_space=env.action_space,
demonstrations=transitions,
rng=rng,
)
bc_trainer.train(n_epochs=10)
# reward, _ = evaluate_policy(bc_trainer.policy, env, 10)
# print("Reward:", reward)