I've been trying to make a "dynamic" function signature with TensorFlow using @tf.function(input_signature=[...]). More specifically, I need to find a way for one of the arguments to be either tf.TensorSpec(shape=[None, None], dtype=tf.float32) or None
I am currently trying the following:
@tf.function(input_signature=[tf.TensorSpec(shape=[None], dtype=tf.string), tf.TensorSpec(shape=[None, None], dtype=tf.float32)])
def generate_one_step(self, inputs, states=None):
...
but as the second parameter could also in some cases be None I get the following error:
ValueError: When input_signature is provided, all inputs to the Python function must be convertible to tensors:
inputs: (
tf.Tensor([b'Test '], shape=(1,), dtype=string),
None)
input_signature: (
TensorSpec(shape=(None,), dtype=tf.string, name=None),
TensorSpec(shape=(None, None), dtype=tf.float32, name=None)).
I realize there may also be an error regarding the shape of the first input but I am unsure how to make a "variable" shape as well