小编Sta*_*taz的帖子

我可以在一个python进程中使用自己的Tensorflow会话运行两个Thread吗?

我在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 …
Run Code Online (Sandbox Code Playgroud)

multithreading python-3.x tensorflow

6
推荐指数
0
解决办法
902
查看次数

标签 统计

multithreading ×1

python-3.x ×1

tensorflow ×1