Search code examples
pythonfunctiontensorflowpython-decoratorspython-class

Using @ sign in Tensorflow functions


I have seen that in Tensorflow tutorials, they usually put an "@" sign before writing the "tf.functionenter link description here"

Why there is a need to do that? What happens if we do not put the "@" sign? In other words, where and when we should put an "@" sign when writing a function?

Thanks in advance


Solution

  • I'm not sure if your question is regarding just the @ sign or the @tf.fuction decorator.

    It seems that you are asking about the @ sign. The @tf.function is just a Syntactic sugar.

    You could do

    @tf.function
    def myFunc()
    

    or

    x = tf.function(myFunc())