Tensorflow 1.11挂在“ sess = tf.Session()”上

时间:2018-10-06 15:11:41

标签: python tensorflow

我从1.10更新到TensorFlow 1.11,无法运行健康检查。以下代码挂在sess = tf.Session()上。

配置:Windows 10 x64,最新的GPU驱动程序,Cuda 9.0,cudnn 7.3,Python 3.6.6。以前,该设置适用于TF 1.10,突然之间一切都停止了。

有人遇到过类似情况吗?

import os
import numpy as np
import tensorflow as tf

def tftest(a, b):
    # Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3
    x_data = np.random.rand(100).astype(np.float32)
    y_data = x_data * a + b

    # Try to find values for W and b that compute y_data = W * x_data + b
    # (We know that W should be 0.1 and b 0.3, but TensorFlow will
    # figure that out for us.)
    W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
    b = tf.Variable(tf.zeros([1]))
    y = W * x_data + b

    # Minimize the mean squared errors.
    loss = tf.reduce_mean(tf.square(y - y_data))
    optimizer = tf.train.GradientDescentOptimizer(0.5)
    train = optimizer.minimize(loss)

    # Before starting, initialize the variables.  We will 'run' this first.
    init = tf.global_variables_initializer()

    # Launch the graph.
    sess = tf.Session()   #<< the script hangs here!
    sess.run(init)

    # Fit the line.
    for step in range(201):
        sess.run(train)
        if step % 20 == 0:
            print(step, sess.run(W), sess.run(b))

if __name__ == "__main__":
    tftest(20, 10)

1 个答案:

答案 0 :(得分:1)

我认为是this bug。该问题仍未解决,似乎与使用MSVC构建的Eigen中的问题有关。

好消息是TensorFlow不会无限期地挂起:必须等待3-4-5分钟,然后代码才能恢复。在TensorFlow首次启动时,这种情况只会发生一次。