我注意到session.run之后的代码有时会在session.run完成之前执行,这很可能是因为tensorflow session.run正在其他线程上执行。有没有一种方法可以检测session.run何时完成,因此我可以控制何时执行其余代码?
我的设置如下:
with detection_graph.as_default():
with tf.Session(graph=detection_graph) as sess:
# do stuff...
(boxes, scores, classes, num) = sess.run(
[detection_boxes, detection_scores, detection_classes, num_detections],
feed_dict={image_tensor: image_np_expanded})
# code here will sometimes run before sess.run has finished
此外,不确定是否相关,但是我正在从实例限制为1的python BackgroundScheduler运行此代码。而且,有时,看似随机的,tensorflow冻结在以下消息中:
I tensorflow/core/common_runtime/process_util.cc:115] Creating new thread pool with default inter op setting: 2. Tune using inter_op_parallelism_threads for best performance.