DanielTheRocketMan
DanielTheRocketMan

Reputation: 3249

How to do this in Tensorflow 2.0?

I am trying for the first time the Tensorflow 2.0. Is this idiomatic?

@tf.function
def add(a,b):
    return a+b

if __name__=="__main__":

    result=add(1.0,2.0)
    print(result)
    print(tf.keras.backend.get_value(result))

However, I get this warning related to the add function:

WARNING:tensorflow:Entity <function add at 0x7ff34781a2f0> could not be transformed and will be executed as-is. Please report this to the AutoGraph team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: 

What does it mean? How can I correct this?

Upvotes: 0

Views: 165

Answers (1)

Shanqing Cai
Shanqing Cai

Reputation: 3876

I didn't get the warning in the latest tf-nightly (2.1.0-dev20200104). But there are two pieces of advice regarding your code,

  1. As @thushv89 pointed out, it is generally a good idea to pass Tensor objects when calling functions decorated by @tf.function. In some cases, passing plain Python data types (like floats and ints) may cause the function to be "recompiled", dramatically slowing down the performance. It doesn't happen in this case. But it's good to be careful in general.

  2. In TF2's eager execution, tf.keras.backend.get_value(result) is a no-op. You can omit that call. result is the Tensor value per se and it holds the concrete values.

Upvotes: 1

Related Questions