Tutorial 4 - Render the Best Model (KeyError: 'policy')

Hello Everybody,

When I run the “render the best model” cell in tutorial 4, I got the following error;

/Users/utkupolat/miniconda3/envs/cr37/lib/python3.7/site-packages/stable_baselines/init.py:33: UserWarning: stable-baselines is in maintenance mode, please use Stable-Baselines3 (SB3) for an up-to-date version. You can find a migration guide in SB3 documentation.
“stable-baselines is in maintenance mode, please use Stable-Baselines3 (SB3) for an up-to-date version. You can find a migration guide in SB3 documentation.”
[INFO] commonroad_rl.gym_commonroad.commonroad_env - Testing on commonroad_rl/tutorials/data/highD/pickles/problem_test with 16 scenarios
Testing a maximum of -1 scenarios
Traceback (most recent call last):
File “/Users/utkupolat/miniconda3/envs/cr37/lib/python3.7/runpy.py”, line 193, in _run_module_as_main
main”, mod_spec)
File “/Users/utkupolat/miniconda3/envs/cr37/lib/python3.7/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “/Users/utkupolat/Downloads/commonroad-rl/commonroad_rl/evaluate_model.py”, line 351, in
main()
File “/Users/utkupolat/Downloads/commonroad-rl/commonroad_rl/evaluate_model.py”, line 170, in main
model, env = load_model_and_vecnormalize(args.model_path, args.algo, normalize, env)
File “/Users/utkupolat/Downloads/commonroad-rl/commonroad_rl/utils_run/utils.py”, line 151, in load_model_and_vecnormalize
model = ALGOS[algo].load(model_path)
File “/Users/utkupolat/miniconda3/envs/cr37/lib/python3.7/site-packages/stable_baselines/common/base_class.py”, line 943, in load
model = cls(policy=data[“policy”], env=None, _init_setup_model=False) # pytype: disable=not-instantiable
KeyError: 'policy’

Any suggestion Please!!

Hi, could you share the model file here? It seems like policy is not stored in the model zip folder somehow.

Hi, thank you for your answer. I fixed it by changing some codes in the utils.py folder.
(/commonroad-rl/commonroad_rl/utils_run/utils.py)

“from stable_baselines3 import PPO” => import it
““ppo”: PPO” => add it to ALGOS

After these modifications, I changed algo ppo2 to algo ppo in all cells.

!python -m commonroad_rl.evaluate_model
–algo ppo \ #algo pp2 => algo ppo
–model_path commonroad_rl/tutorials/logs
–test_path commonroad_rl/tutorials/data/highD/pickles
–viz_path commonroad_rl/tutorials/imgs

It seems working now, and give the outputs of images.
Thanks!