我有些困难理解在检查
根据谷歌文档https://www.tensorflow.org/guide/concrete_function#using_a_concrete_function,会返回一个元组。例如:
打印
然而,当模块被保存并加载时, 的输出略有不同:
tf.ConcreteFunction
时,structured_input_signature
的返回类型。根据谷歌文档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)
打印
Tracing "power"
((TensorSpec(shape=(), dtype=tf.float32, name='a'), TensorSpec(shape=(), dtype=tf.float32, name='b')), {})
Tensor("Identity:0", shape=(), dtype=float32)
然而,当模块被保存并加载时, 的输出略有不同:
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)
打印
((),
{'a': TensorSpec(shape=(), dtype=tf.float32, name='a'),
'b': TensorSpec(shape=(), dtype=tf.float32, name='b')})
在structured_input_signature的返回元组中,为什么要选择填充元组或字典?这背后的逻辑是什么?