如何组合多个训练模型的Tensorflow API

时间:2017-10-06 18:12:03

标签: python graph tensorflow models object-detection

我想知道如何在tensorflow API中组合多个模型,例如,我想结合预先训练的COCO模型的输出以及训练的OXFORD Pet数据。有没有办法将它们组合起来并尝试在张量流的同一会话中得到两个结果?

当我尝试在会话中获取两个模型的图表时,我在这里失败了:

detection_graph = tf.Graph()
with detection_graph.as_default():
  od_graph_def = tf.GraphDef()
  with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
    serialized_graph = fid.read()
    od_graph_def.ParseFromString(serialized_graph)
    tf.import_graph_def(od_graph_def, name='')
label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True)
category_index = label_map_util.create_category_index(categories)

detection_graph_PET = tf.Graph()
with detection_graph_PET.as_default():
  od_graph_def_PET = tf.GraphDef()
  with tf.gfile.GFile(PATH_TO_CKPT_PET, 'rb') as fid:
    serialized_graph_PET = fid.read()
    od_graph_def_PET.ParseFromString(serialized_graph_PET)
    tf.import_graph_def(od_graph_def_PET, name='')
label_map_PET = label_map_util.load_labelmap(PATH_TO_LABELS_PET)
categories_PET = label_map_util.convert_label_map_to_categories(label_map_PET, max_num_classes=NUM_CLASSES_PET, use_display_name=True)
category_index_PET = label_map_util.create_category_index(categories_PET)
return detection_graph, category_index, detection_graph_PET, category_index_PET

它会在终端中抛出一些异常,如下所示:

  

od_graph_def_PET.ParseFromString(serialized_graph_PET)    google.protobuf.message.DecodeError:解析消息时出错

它们在单独运行时工作正常。

是否有合适的方法来组合模型?

0 个答案:

没有答案