len is not well defined for symbolic tensors *AND* using a `tf.Tensor` as a Python `bool` is not allowed in Graph execution
See original GitHub issueThere is an error in the error-handling of the ddpg.py and dqn.py agents in keras-rl/rl/agents while using Tensorflow 2.0, Keras 2.3.1, Keras-rl 0.4.2 dqn.py line 108 ddpg.py line 29, 31 It comes about by calling len(model.output)
Error:
Traceback (most recent call last):
File "foo.py", line x, in <module>
agent = DDPGAgent(...)
**File "foo\ddpg.py", line 29, in __init__
if hasattr(actor.output, '__len__') and len(actor.output) > 1:**
File "foo\ops.py", line 741, in __len__
"shape information.".format(self.name))
TypeError: len is not well defined for symbolic Tensors. (dense_5/BiasAdd:0) Please call `x.shape` rather than `len(x)` for shape information.
Possible solution:
What I’ve been using as a fix is summing the shape of the tensor:
sum(x is not None for x in model.output.shape)
Implementation example:
if hasattr(model.output, '__len__') and sum(x is not None for x in model.output.shape) > 1:
There is then another error in ddpg.py at line 130:
if i == self.critic_action_input:
Error:
tensorflow.python.framework.errors_impl.OperatorNotAllowedInGraphError: using a
tf.Tensoras a Python
bool is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.
Including
import tensorflow as tf
tf.compat.v1.enable_eager_execution()
Does not seem to help, I have also tried creating a session and using tf.equal(i, self.critic_action_input).eval(session=sess) but I’m having issues, as of now I’ve tried
import tensorflow as tf
with tf.compat.v1.Session(graph=self.critic_action_input.graph) as sess:
for i in self.critic.
if tf.equal(i, self.critic_action_input).eval(session=sess): #if i == self.critic_action_input:
combined_inputs.append([])
else:
combined_inputs.append(i)
critic_inputs.append(i)
But I cannot get it to work
Thank you
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:16
Top GitHub Comments
Why has the change not been added to the package to make it compatible with tf>2.0?
I think all of you may have mistaken what this library was capable of doing. It’s a Keras module!
It can only work by using
import keras
instead offrom tensorflow import keras
.