我有一个类似这样的代码:
def processImage(filename):
with detection_graph.as_default():
with tf.Session(graph=detection_graph) as sess:
# Definite input and output Tensors for detection_graph
image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
# Each box represents a part of the image where a particular object was detected.
detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
# Each score represent how level of confidence for each of the objects.
# Score is shown on the result image, together with the class label.
detection_scores = detection_graph.get_tensor_by_name('detection_scores:0')
detection_classes = detection_graph.get_tensor_by_name('detection_classes:0')
num_detections = detection_graph.get_tensor_by_name('num_detections:0')
#Do Other Stuff Here with "sess" variable like:
sess.run([abc, xyz, stuff])
def main():
with concurrent.futures.ProcessPoolExecutor(max_workers=2) as executor:
#{executor.map(processImage, filesToProcess): filesToProcess for filesToProcess in filesToProcess}
{executor.submit(processImage, filesToProcess): filesToProcess for filesToProcess in filesToProcess}
if __name__ == '__main__':
main()
但是我只想调用这个代码一次
with detection_graph.as_default():
with tf.Session(graph=detection_graph) as sess:
# Definite input and output Tensors for detection_graph
image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
# Each box represents a part of the image where a particular object was detected.
detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
# Each score represent how level of confidence for each of the objects.
# Score is shown on the result image, together with the class label.
detection_scores = detection_graph.get_tensor_by_name('detection_scores:0')
detection_classes = detection_graph.get_tensor_by_name('detection_classes:0')
num_detections = detection_graph.get_tensor_by_name('num_detections:0')
但是我需要sess
内的processImage
变量。有没有办法,我如何修改这段代码,所以我只调用with detection_graph.as_default(): and with tf.Session(graph=detection_graph) as sess:
部分一次
假设检测图和会话对象是可拾取的(即,可以序列化以发送到不同的进程)和可安全分发的(即,不同副本上的操作是有意义和安全的),您可以这样做
相关问题 更多 >
编程相关推荐