Python 3.x 如何在默认会话中运行tensorflow会话?
如何使用默认tensorflow会话的预测作为新tensorflow会话的输入。我有一个检测模型,检测到的对象应该作为输入传递给新模型进行分类,当我尝试这样做时,我得到了资源消耗错误。 示例代码:Python 3.x 如何在默认会话中运行tensorflow会话?,python-3.x,tensorflow,deep-learning,computer-vision,Python 3.x,Tensorflow,Deep Learning,Computer Vision,如何使用默认tensorflow会话的预测作为新tensorflow会话的输入。我有一个检测模型,检测到的对象应该作为输入传递给新模型进行分类,当我尝试这样做时,我得到了资源消耗错误。 示例代码: with detection_graph.as_default(): with tf.Session(graph=detection_graph) as sess: while True: sess.run([boxes, scores, classes
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????"
谢谢使用完成此
之后,会话将关闭,因为它不在范围内,因此是的,它将在循环的每次迭代中创建:
with tf.Session() as sess:
"Classification model"
"Pseudo code????"
我想你会想重新安排这样的事情:
with detection_graph.as_default():
with tf.Session(graph=detection_graph) as sess:
sess2 = tf.Session(graph=detection_graph)
while True:
sess.run([boxes, scores, classes, num_detections] )
""" I want to use the predicted values to another tensorflow session for classification"""
# use sess2 here
"Classification model"
"Pseudo code????"
在尝试了所有不同的方法之后,我使用classinit方法修复了它
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
在图中有两个会话背后的动机是什么?我正在尝试运行两个不同的模型,分类在顶部自定义检测模型。您能粘贴实际的错误消息而不是“获取资源耗尽错误”吗?似乎讨论了拥有多个会话并运行它(尽管结果因线程性质而损坏),所以我不确定错误是否是因为有嵌套会话sessions@IanQuah没有错误。但当我观察日志时,会连续打印tensorflow会话(是因为每次创建新会话并关闭它吗?)。我将嵌套SES作为默认会话,但我仍然面临这个问题。谢谢