hill-a / stable-baselines

A fork of OpenAI Baselines, implementations of reinforcement learning algorithms
http://stable-baselines.readthedocs.io/
MIT License
4.16k stars 725 forks source link

ValueError: Tried to convert 'input' to a tensor and failed. Error: None values not supported.[DQN] #1001

Closed dx2919717227 closed 4 years ago

dx2919717227 commented 4 years ago

tensorflow version: tensorflow-gpu-1.13.2

test.py

import gym
from stable_baselines.deepq.policies import DQNPolicy
from stable_baselines.deepq import DQN

env = gym.make('CartPole-v1')

model = DQN(DQNPolicy, env, verbose=1)
model.learn(total_timesteps=10000)
obs = env.reset()
for i in range(1000):
    action, _states = model.predict(obs)
    obs, rewards, dones, info = env.step(action)
    env.render()

env.close()

Traceback:

Traceback (most recent call last):
  File "/home/onion/.local/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 511, in _apply_op_helper
    preferred_dtype=default_dtype)
  File "/home/onion/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1175, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/home/onion/.local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 304, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "/home/onion/.local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 245, in constant
    allow_broadcast=True)
  File "/home/onion/.local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 283, in _constant_impl
    allow_broadcast=allow_broadcast))
  File "/home/onion/.local/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 454, in make_tensor_proto
    raise ValueError("None values not supported.")
ValueError: None values not supported.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/onion/.local/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 525, in _apply_op_helper
    values, as_ref=input_arg.is_ref).dtype.name
  File "/home/onion/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1175, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/home/onion/.local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 304, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "/home/onion/.local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 245, in constant
    allow_broadcast=True)
  File "/home/onion/.local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 283, in _constant_impl
    allow_broadcast=allow_broadcast))
  File "/home/onion/.local/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 454, in make_tensor_proto
    raise ValueError("None values not supported.")
ValueError: None values not supported.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "test2.py", line 12, in <module>
    model = DQN(DQNPolicy, env, verbose=1)
  File "/usr/local/lib/python3.6/dist-packages/stable_baselines/deepq/dqn.py", line 103, in __init__
    self.setup_model()
  File "/usr/local/lib/python3.6/dist-packages/stable_baselines/deepq/dqn.py", line 141, in setup_model
    double_q=self.double_q
  File "/usr/local/lib/python3.6/dist-packages/stable_baselines/deepq/build_graph.py", line 370, in build_train
    act_f, obs_phs = build_act(q_func, ob_space, ac_space, stochastic_ph, update_eps_ph, sess)
  File "/usr/local/lib/python3.6/dist-packages/stable_baselines/deepq/build_graph.py", line 143, in build_act
    deterministic_actions = tf.argmax(policy.q_values, axis=1)
  File "/home/onion/.local/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "/home/onion/.local/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 86, in argmax
    return argmax_v2(input, axis, output_type, name)
  File "/home/onion/.local/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 115, in argmax_v2
    return gen_math_ops.arg_max(input, axis, name=name, output_type=output_type)
  File "/home/onion/.local/lib/python3.6/site-packages/tensorflow/python/ops/gen_math_ops.py", line 879, in arg_max
    name=name)
  File "/home/onion/.local/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 529, in _apply_op_helper
    (input_name, err))
ValueError: Tried to convert 'input' to a tensor and failed. Error: None values not supported.

How can i fix this error?

Miffyli commented 4 years ago

As in examples, you need to provide stable_baselines.deepq.policies.MlpPolicy, not stable_baselines.deepq.policies.DQNPolicy as a policy to the DQN creation code.

dx2919717227 commented 4 years ago

oh tks