如何使用Tensorflow导出用于图像分类的简单保存模型图?

问题描述 投票:1回答:1

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

任何帮助表示赞赏!谢谢!

python tensorflow tensorflow-serving
1个回答
0
投票

如果您使用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})
© www.soinside.com 2019 - 2024. All rights reserved.