5
class Foo(object):
    def __init__(self):
        self.shape = [None, 4]

    @tf.function(input_signature=[tf.TensorSpec(shape=self.shape)])
    def add_constant(self, a):
        print('Building graph')
        return a + 5

Any way to make this possible? Currently, I just decorate add_constant inside Foo class __init__ as:

self.add_constant = tf.function(func=self.add_constant, input_signature=[tf.TensorSpec(shape=self.shape)]).

However, this makes the code less readable comparable to function decorator.

quamrana
  • 37,849
  • 12
  • 53
  • 71
Chi Zhang
  • 51
  • 2
  • This may be relevant: https://stackoverflow.com/questions/11731136/python-class-method-decorator-with-self-arguments – quamrana Oct 05 '19 at 11:28

0 Answers0