【问题标题】:Tensorflow freezes when trying to create a session in docker container尝试在 docker 容器中创建会话时,Tensorflow 冻结
【发布时间】:2019-01-06 07:32:57
【问题描述】:

我正在尝试使用 CNN 为演示部署一个网站。 为了达到这个目的,我构建了一个带有依赖项的 docker 镜像(在我的例子中是 tensorflow、keras 和任何其他杂项)。

我设法构建了 docker 映像。但是,当我对一些示例图像进行测试时,它失败了。我发现问题是 tensorflow 无法创建会话。我仍然可以导入 tensorflow 和其他包。甚至我也可以使用 tensorflow 代码运行构建计算图的代码

(Ex,  
a=tf.constant(7)
b=tf.constant(10)
c = tf.add(a,b)
).

但每当我尝试创建 tensorflow 会话时它就会冻结 (Ex, sess = tf.Session()). 下面是构建docker镜像的代码。

def CNN_forward_example(self,image):

    a=tf.constant(7)
    b=tf.constant(10)
    c = tf.add(a,b)
    sess = tf.Session()
    print("I hope to see this message------------------------",c)

预期的结果是看到消息“printed by print("我希望看到这个消息----------",c) ”。

【问题讨论】:

  • 主机上的操作系统是什么?请分享您的 Dockerfile。

标签: python docker tensorflow


【解决方案1】:

我在使用 Docker 时遇到了类似的问题。找不到博文的链接,但基本上建议为 GRAPH 设置一个全局变量。

GRAPH = tf.Graph()
# and then where you need it
with GRAPH.as_default():
    sess = tf.Session()

这是关于如何使用图表和会话的guide。这是与 Docker 一起服务的 TF 上的 guide。

【讨论】:

    猜你喜欢
    • 2017-08-21
    • 1970-01-01
    • 2016-06-14
    • 2020-02-26
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    相关资源
    最近更新 更多