Skip to main content
 首页 » 编程设计

python之Tensorflow 1.11 卡在 "sess = tf.Session()"

2024年12月31日28cloudgamer

我从 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) 

请您参考如下方法:

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

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