【发布时间】:2020-01-08 03:16:09
【问题描述】:
在检查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 的返回元组中填充元组与字典背后的逻辑是什么?
【问题讨论】:
标签: python tensorflow2.0 tensorflow-serving