Stable-baselines: [question] AttributeError: 'NoneType' object has no attribute 'reset'

Created on 27 Aug 2020  Â·  6Comments  Â·  Source: hill-a/stable-baselines

import gym
from stable_baselines import DQN,PPO2
from stable_baselines.common.evaluation import evaluate_policy

env=gym.make('LunarLander-v2')

model=DQN('MlpPolicy',env,learning_rate=1e-3,prioritized_replay=True,verbose=1)
model.learn(total_timesteps=int(2e5))
model.save('dqn_lunar')
del model

model=DQN.load('dqn_lunar')
mean_reward,std_reward=evaluate_policy(model,model.get_env(),n_eval_episodes=10)
obs=env.reset()
for i in range(1000):
    action,_state=model.predict(obs)
    obs,rewards,dones,info=env.step(action)
    env.render()

Describe the bug
Traceback (most recent call last):
File "", line 1, in
File "C:\Program Files\JetBrains\PyCharm 2020.2\plugins\python\helpers\pydev_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm 2020.2\plugins\python\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"n", file, 'exec'), glob, loc)
File "C:/Users/born_/PycharmProjects/test_sb/main.py", line 41, in
mean_reward,std_reward=evaluate_policy(model,model.get_env(),n_eval_episodes=10)
File "C:\Users\born_\anaconda3\envs\workEnv\lib\site-packages\stable_baselines\common\evaluation.py", line 49, in evaluate_policy
obs = env.reset()
AttributeError: 'NoneType' object has no attribute 'reset'

System Info

  • anaconda3
  • NVIDIA RTX 2080
  • Python 3.6
  • tensorflow-gpu==1.15.0
  • cuda 10.0, cudnn 7.6.5
question

All 6 comments

Hello,
let me give you a hint: when you load the model as you do, there is normally a warning that will explain you why it does not work ;)

Loading a model without an environment, this model cannot be trained until it has a valid environment.
It should be this sentence?

I have tried model.get_env() command, but it returns a None. Why?

Model does not contain an environment, you need to provide one yourself. See docs on load.

Loading a model without an environment, this model cannot be trained until it has a valid environment.
It should be this sentence?

yes

I have tried model.get_env() command, but it returns a None. Why?

As mentioned by the warning and by @Miffyli the model is without an environment (not saved).

OK,thank you! I have succeed with your help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sahilgupta2105 picture sahilgupta2105  Â·  3Comments

maystroh picture maystroh  Â·  3Comments

Unimax picture Unimax  Â·  3Comments

maystroh picture maystroh  Â·  3Comments

stefanbschneider picture stefanbschneider  Â·  3Comments