在推论服务中使用tf.Session时,它是线程安全的吗? [英] Is it thread-safe when using tf.Session in inference service?

查看:325
本文介绍了在推论服务中使用tf.Session时,它是线程安全的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我们已使用TensorFlow训练和导出模型.就像tensorflow/serving一样,我们可以使用此模型来实现推理服务.

Now we have used TensorFlow to train and export an model. We can implement the inference service with this model just like how tensorflow/serving does.

我对tf.Session对象是否是线程安全的存在疑问.如果是真的,我们可以在启动后初始化该对象,并使用单例对象来处理并发请求.

I have a question about whether the tf.Session object is thread-safe or not. If it's true, we may initialize the object after starting and use the singleton object to process the concurrent requests.

推荐答案

tf.Session对象对于

The tf.Session object is thread-safe for Session.run() calls from multiple threads.

在TensorFlow 0.10图形修改之前不是线程安全的.这个问题在0.10版本中已得到修复,因此您可以通过Session.run()调用将节点同时添加到图中,尽管出于性能原因不建议这样做.相反,建议调用 sess.graph.finalize() 使用来自多个线程的会话,以防止意外的内存泄漏.

Before TensorFlow 0.10 graph modification was not thread-safe. This was fixed in the 0.10 release, so you can add nodes to the graph concurrently with Session.run() calls, although this is not advised for performance reasons; instead, it is recommended to call sess.graph.finalize() before using the session from multiple threads, to prevent accidental memory leaks.

这篇关于在推论服务中使用tf.Session时,它是线程安全的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆