Sta*_*taz 6 multithreading python-3.x tensorflow
我在nvidia docker中使用tensorflow 1.1.
我目前正在尝试运行两个不同的卷积神经网络,在两个单独的线程中运行推理,在python进程中访问相同的gpu.
首先,我正在加载两个不同的模型:
型号1:
with self.sess.as_default():
saver = tf.train.import_meta_graph('saved_models/cnn_model112.ckpt.meta')
saver.restore(self.sess, 'saved_models/cnn_model112.ckpt')
self.graph = self.sess.graph
with self.graph.as_default():
self.sess.run(tf.global_variables_initializer())
Run Code Online (Sandbox Code Playgroud)
型号2:
with tf.gfile.GFile(frozen_graph_filename, "rb") as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
with tf.Graph().as_default() as g1:
tf.import_graph_def(
graph_def,
input_map=None,
return_elements=None,
name=prefix,
op_dict=None,
producer_op_list=None
)
self.sess = tf.Session(graph=self.graph)
Run Code Online (Sandbox Code Playgroud)
这两个会话位于不同的对象中.每个对象都会旋转一个线程来对其关联的模型进行推理,并以此函数为目标:
def run(self, stop_event, streams, parent_videos, output, netType):
if self.sess:
with self.sess.as_default():
while not stop_event.is_set():
ret, frame = stream.readSingleFrame()
if ret and frame is not None:
self.sess.run(self.predict, feed_dict={ self.input: [frame]})
Run Code Online (Sandbox Code Playgroud)
这会导致以下错误:
2017-07-13 09:28:17.346614: E tensorflow/stream_executor/cuda/cuda_event.cc:49] Error polling for event status: failed to query event: CUDA_ERROR_ILLEGAL_ADDRESS
2017-07-13 09:28:17.346866: F tensorflow/core/common_runtime/gpu/gpu_event_mgr.cc:203] Unexpected Event status: 1
Run Code Online (Sandbox Code Playgroud)
根据我的阅读,我认为多个线程可能使用相同的会话,因为session.run()调用是线程安全的.我还读过,我可以将这些图组合在一起,以便在同一个会话中运行.但是我真的希望他们同时运行.
我认为这两个会话试图同时访问相同的GPU内存空间,但我认为tensorflow会为gpu上的两个图分配足够的空间.
在我的问题之上,为什么在单独的进程中在同一GPU上运行并发推断工作,而不是在单独的线程中?
| 归档时间: |
|
| 查看次数: |
902 次 |
| 最近记录: |