1. AttributeError: module 'tensorflow' has no attribute 'constant'
安装完 tensorflow-gpu
后,运行下方测试代码,会报AttributeError: module 'tensorflow' has no attribute 'constant'
,但是也没有找到与 tensorflow
同名的文件,这时候,果断卸载重装最好。卸载完重装后,再运行测试代码就不报错了。
import tensorflow as tf
# Creates a graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print(sess.run(c))
也可以用下方的代码,测试 GPU 是否可用:
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
运行结果:
![](https://img.haomeiwen.com/i2759738/be488049407cc00d.png)
2. ImportError: DLL load failed: 找不到指定的程序。
可能是 protobuf
安装的版本过高,根据[1]检查了一下自己的版本,发现是 3.6.1
版本的,而 tensorflow-gpu 1.8.0
版本对应的是 3.6.0
版本。后来直接输入 pip install protobuf==3.6.0
降级处理。降级之后就不报错了。
网友评论