2017-02-02 218 views
0

我想服务使用tensorflow服务的再培训开始图。对于再培训,我使用这个example。不过,我需要对此图进行更改才能使其与serving export code配合使用。tensorflow图像重新训练

自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) 

此图像张应输入到重新训练开始图表。但是我不知道是否有可能在张量流中添加一个图到另一个图,就像你可以使用placeholder_with_input(已经在再训练代码中完成)轻松追加图一样。

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

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

回答

2

一种方法是:

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很可能不是你所需要的正确的操作名称 - 你可以列出OPS:

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

我知道这不是一个完整的答案,也许不是最有效的,但希望它可以让你开始。只是单挑,也有this blogpost

0

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

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