如何在默认会话中运行tensorflow会话?

时间:2019-01-14 10:47:10

标签: python-3.x tensorflow deep-learning computer-vision

如何使用默认张量流会话的预测作为新张量流会话的输入。我有一个检测模型,当我尝试执行检测到资源耗尽错误时,应将检测到的对象作为输入传递给新模型进行分类。 示例代码:

with detection_graph.as_default():
    with tf.Session(graph=detection_graph) as sess:
        while True:
            sess.run([boxes, scores, classes, num_detections] )

            """ I want to use the predicted values to another tensorflow session for classification"""
           i.e
           with tf.Session() as sess:
               "Classification model"
               "Pseudo code????"

谢谢

1 个答案:

答案 0 :(得分:0)

尝试了所有不同的方法后,我可以使用类 init 方法对其进行修复。

def __init__(self):
    """Tensorflow detector
    """
    self.detection_graph = tf.Graph()
    with self.detection_graph.as_default():
        od_graph_def = tf.GraphDef()
        with tf.gfile.GFile(frozen_inference.pb, 'rb') as fid:
            serialized_graph = fid.read()
            od_graph_def.ParseFromString(serialized_graph)
            tf.import_graph_def(od_graph_def, name='')


    with self.detection_graph.as_default():
        config = tf.ConfigProto()
        # config.gpu_options.allow_growth = True
        self.detection_sess = tf.Session(graph=self.detection_graph, config=config)
        self.windowNotSet = True