question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 issue

There 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 Pythonbool 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:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:16

github_iconTop GitHub Comments

16reactions
elnazsn1988commented, Jun 1, 2020

Why has the change not been added to the package to make it compatible with tf>2.0?

11reactions
yingshaoxocommented, Mar 18, 2020

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 of from tensorflow import keras.

Read more comments on GitHub >

github_iconTop Results From Across the Web

using a `tf.Tensor` as a Python `bool` is not allowed in Graph ...
As the error message explain, you try to use a tf.Tensor as a Python bool . This happens generally where condition are expected...
Read more >
len is not well defined for symbolic tensors ... - Bountysource
len is not well defined for symbolic tensors *AND* using a `tf.Tensor` as a Python `bool` is not allowed in Graph execution.
Read more >
tf.constant | TensorFlow v2.11.0
Creates a constant tensor from a tensor-like object. ... This function is not fundamentally different from tf.convert_to_tensor .
Read more >
Training Mask R-CNN with TensorFlow 2.0 and Keras
Tensor ` as a Python `bool` is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function. Copy. According...
Read more >
tensorflow.python.framework.ops 源代码
OperatorNotAllowedInGraphError ( "{} is not allowed in Graph execution. ... def __len__(self): raise TypeError("len is not well defined for symbolic Tensors.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found