我现在有以下代码,但它不起作用。我试图接受一个图像输入,分类器将输出一些标签。培训正在输出图表,但我需要保存的模型用于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})