【问题标题】:How do I export a simple saved model graph for image classification with Tensorflow?如何使用 Tensorflow 导出简单保存的模型图以进行图像分类?
【发布时间】:2019-04-14 09:15:36
【问题描述】:

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

如果您使用 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})

【讨论】:

    猜你喜欢
    • 2018-04-07
    • 1970-01-01
    • 2017-08-13
    • 1970-01-01
    • 2018-07-23
    • 1970-01-01
    • 2021-05-08
    • 2016-04-19
    • 2018-03-07
    相关资源
    最近更新 更多