我现在有以下代码,但它不起作用。我正在尝试输入一张图像,分类器将输出一些标签。训练正在使用输出图形,但我需要保存的模型进行 GCP 上传。
inputs = tf.placeholder(tf.image)
outputs = tf.placeholder(tf.string)
tf.saved_model.simple_save(sess,
export_dir,
inputs={"x": inputs},
outputs={"z": outputs})
任何帮助不胜感激!谢谢!
如果您使用 tf.keras
训练模型:
import tensorflow as tf
# The export path contains the name and the version of the model
tf.keras.backend.set_learning_phase(0) # Ignore dropout at inference
model = tf.keras.models.load_model('./model.h5')
export_path = './1'
# Fetch the Keras session and save the model
# The signature definition is defined by the input and output tensors
# And stored with the default serving key
with tf.keras.backend.get_session() as sess:
tf.saved_model.simple_save(
sess,
export_path,
inputs={'input_image': model.input},
outputs={t.name:t for t in model.outputs})