美文网首页
Tensorflow-GPU 1.8.0 安装过程中的报错

Tensorflow-GPU 1.8.0 安装过程中的报错

作者: 捡个七 | 来源:发表于2018-12-01 15:56 被阅读0次
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())

运行结果:


2. ImportError: DLL load failed: 找不到指定的程序。

可能是 protobuf 安装的版本过高,根据[1]检查了一下自己的版本,发现是 3.6.1 版本的,而 tensorflow-gpu 1.8.0 版本对应的是 3.6.0 版本。后来直接输入 pip install protobuf==3.6.0 降级处理。降级之后就不报错了。

参考

[1]. tensorflow出现 ImportError: DLL load failed: 找不到指定的程序

相关文章

网友评论

      本文标题:Tensorflow-GPU 1.8.0 安装过程中的报错

      本文链接:https://www.haomeiwen.com/subject/cqhrcqtx.html