structured_input_signature在检查tf.ConcreteFunction.
在谷歌文档https://www.tensorflow.org/guide/concrete_function#using_a_concrete_function中返回一个元组。例如
@tf.function
def power(a,b):
print('Tracing "power"\n')
return a**b
float_power = power.get_concrete_function(
a = tf.TensorSpec(shape=[], dtype=tf.float32),
b = tf.TensorSpec(shape=[], dtype=tf.float32))
print(float_power.structured_input_signature)
print(float_power.structured_outputs)
Run Code Online (Sandbox Code Playgroud)
印刷
Tracing "power"
((TensorSpec(shape=(), dtype=tf.float32, name='a'), TensorSpec(shape=(), dtype=tf.float32, name='b')), {})
Tensor("Identity:0", shape=(), dtype=float32)
Run Code Online (Sandbox Code Playgroud)
然而,当模块被保存和加载时,输出略有不同:
float_power_mod = tf.Module()
float_power_mod.float_power = float_power
tf.saved_model.save(float_power_mod, './float_power_mod')
mod_4 = tf.saved_model.load('./float_power_mod')
float_power_func = mod_4.signatures['serving_default']
print(float_power_func.structured_input_signature)
Run Code Online (Sandbox Code Playgroud)
印刷
((),
{'a': TensorSpec(shape=(), dtype=tf.float32, name='a'),
'b': TensorSpec(shape=(), dtype=tf.float32, name='b')})
Run Code Online (Sandbox Code Playgroud)
在 Structured_input_signature 的返回元组中填充元组与字典背后的逻辑是什么?