首页 > 解决方案 > TensorFlow saved_model 为不同的输入返回相同的结果

问题描述

我正在尝试使用下面的代码导出保存的模型。它导出了 saved_model.pb,但是对于我给它的任何输入,我都会得到相同的结果。我认为我的输出方式有问题。我对 TensorFlow 很陌生,所以如果这是一个简单的错误,我深表歉意。

with tf.gfile.FastGFile("retrained_graph.pb", 'rb') as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())
    _ = tf.import_graph_def(graph_def, name='')

def export_model(saved_model_dir, final_tensor_name):
  with tf.Session() as sess:
    init = tf.global_variables_initializer()
    sess.run(init)
    with sess.graph.as_default() as graph:
      tf.saved_model.simple_save(
        sess,
        saved_model_dir,
        inputs={'image': tf.placeholder(tf.string)},
        outputs={'prediction': graph.get_tensor_by_name(final_tensor_name + ":0")}
   )

我还在使用以下教程中的 retrain.py:https://github.com/BartyzalRadek/Multi-label-Inception-net所以它可能是那里的东西。

我的代码结构是我将其包含在一个单独的文件中,因此每次我想保存时都不需要重新训练。

标签: tensorflowtensorflow-serving

解决方案


推荐阅读