TensorFlow:将输入发送到导出的模型

时间:2018-04-13 12:01:51

标签: python tensorflow

场景:我已导出TF模型,我有.pb文件。该模型是一个简单的分类器,已经在图像上训练。该模型将图像作为输入,并提供图像是否属于具有概率分数的特定类别。

我正在使用python并使用下面的方法加载模型。 graph = load_graph(' model.pb')

但无法找到将图像作为输入发送并检索结果的方法。我应该使用哪些属性来发送输入和接收结果?

1 个答案:

答案 0 :(得分:1)

在tensorflow中有几种方法可以做到这一点。最简单的方法是使用feed_dict。首先需要从模型中找到输入张量,output_tensor,然后使用feed dict提供新输入并获得新输出 例如:

    input_place_holder = model.input_place_holder
    out_put = model.output_tensor
    current_input = your_img_input
    result = model.session.run([out_put], feed_dict={input_place_holder: current_input})

将输入提供给模型的更高级方法是使用tensorflow服务(具有更好的性能等)