【问题标题】:tensorflow image retraining with servingtensorflow 图像再训练与服务
【发布时间】:2017-06-19 00:25:41
【问题描述】:

我正在尝试使用 tensorflow 服务来提供重新训练的初始图。对于再培训,我使用的是example。但是我需要对此图表进行更改以使其与serving export code 一起使用。

由于在 tensorflow 服务中,您将收到序列化的图像作为输入,图形输入应以此开头:

serialized_tf_example = tf.placeholder(tf.string, name='tf_example')
feature_configs = {
    'image/encoded': tf.FixedLenFeature(shape=[], dtype=tf.string),
}
tf_example = tf.parse_example(serialized_tf_example, feature_configs)
jpegs = tf_example['image/encoded']
images = tf.map_fn(preprocess_image, jpegs, dtype=tf.float32)

此图像张量应输入到重新训练的初始图。但是我不知道是否可以在 tensorflow 中将一个图附加到另一个图上,就像您可以使用 placeholder_with_input 轻松附加一样(这已在重新训练代码中完成)。

graph, bottleneck_tensor, jpeg_data_tensor, resized_image_tensor = (
  create_inception_graph())

理想情况下,在图像再训练代码中,我会收到一个占位符张量 jpeg_input_data。我需要将张量 images 附加到这个占位符张量 jpeg_data_tensor 并使用导出器将其导出为单个图,以便可以使用 tensorflow 服务对其进行服务。但是我没有任何 tensorflow 指令可以做到这一点。除了这个方法还有其他的选择吗?

【问题讨论】:

    标签: tensorflow tensorflow-serving


    【解决方案1】:

    一种方法是:

    model_path = 'trained/export.pb' 
    with tf.Graph().as_default():
        with tf.Session() as sess:       
            with gfile.FastGFile(model_path, 'rb') as f:
                graph_def = tf.GraphDef()
                graph_def.ParseFromString(f.read())
                # Your prepending ops here
                images_placeholder = tf.placeholder(tf.string, name='tf_example')
                ...
                images = tf.map_fn(preprocess_image, jpegs, dtype=tf.float32)
                tf.import_graph_def(graph_def, name='inception', input_map={'ResizeBilinear:0': images})
    

    特别注意input_map 参数。 ResizeBilinear:0 可能不是您需要的操作的正确名称 - 您可以通过以下方式列出操作:

    [n.name for n in tf.get_default_graph().as_graph_def().node]  
    

    我意识到这不是一个完整的答案,也许不是最有效的,但希望它可以帮助您入门。只是提醒一下,还有this blogpost

    【讨论】:

      【解决方案2】:

      因此,既然您已经重新训练了模型,我假设该模型是 Protobuf,但您可以将其加载到 Python 对象中,并使用处理批处理或原子操作。

      据我所知,对于您的图形问题,当您加载 tf.Graph() 对象时,您只能使用该对象而不能与其他图形一起使用......也就是说,如果您有另一个图形是现有 Inception-V3 图形的扩展,那么您可以轻松地将其添加到自定义图形的计算图形中。

      【讨论】:

        猜你喜欢
        • 2018-05-22
        • 2017-04-06
        • 2017-05-16
        • 2017-08-21
        • 1970-01-01
        • 1970-01-01
        • 2017-12-16
        • 2018-03-10
        • 2019-06-08
        相关资源
        最近更新 更多