TensorFlow 2.x 的SavedModel 文件包含一个完整的 TensorFlow 模型——不仅包含权重值,还包含模型的构架和计算。它不需要原始模型构建代码就可以运行,因此,非常有利于模型的共享和部署
使用 tf.saved_model.load
将 SavedModel 重新加载到 Python 中
可以用TensorFlow自带的 SavedModel 命令行界面 (CLI) 查看SavedModel模型,例如
saved_model_cli show --dir /tmp/saved_model_dir --all

tf.saved_model.load()的返回值是:
Returns:
A trackable object with a signatures
attribute mapping from signature
keys to functions. If the SavedModel was exported by tf.saved_model.save
,
it also points to trackable objects, functions, debug info which it has been
saved.
使用范例
Signatures associated with the SavedModel are available as functions:
imported = tf.saved_model.load(path)
f = imported.signatures["serving_default"]
print(f(x=tf.constant([[1.]])))
心得:开源软件的API帮助信息写的很糟糕,必须直接看源码
网友评论