TensorFlow时碰到的问题(GPU)

来源:互联网 发布:网络品牌注册到期 编辑:程序博客网 时间:2024/05/23 15:06
测试环境:GTX965M,python3.6.x(GPU安装TensorFlow),win10
下面列出了我安装TensorFlow时碰到的问题


1.在安装时候易出现decode错误是由于
解决方法:
打开 c:\program files\python36\lib\site-packages\pip\compat\__init__.py 约75行 
return s.decode('utf_8') 改为return s.decode('cp936')
原因: 
编码问题,虽然py3统一用utf-8了。但win下的终端显示用的还是gbk编码。
不同版本可能报错地方可能不一样。


2.ImportError: Could not find 'cudart64_80.dll'. TensorFlow requires that this DLL be installed in a directory that is nam
ed in your %PATH% environment variable. Download and install CUDA 8.0 from this URL: https://developer.nvidia.com/cuda-t
oolkit
原因CUDA最新版是9.0下载时下载了9.0版本
解决办法:下载8.0版本(默认传统安装)
http://blog.csdn.net/akon_wang_hkbu/article/details/78478513


3.在导入TensorFlow时报错找不到dll文件则是在环境变量没配置好
解决办法:在win10中的高级系统设置中修改系统变量
网上有两种说法一个是加在Path变量上还有CUDA_PATH上(我两个都加上了)
如果你安装是默认的话应该是以下三个路径:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64


4.cudnn64_6.dll问题
关于导入TensorFlow找不到cudnn64_6.dll,其实下载的的是cudnn64_7.dll(可能是比较新),用管理员权限修改过来就行了。
目录是在:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin


5.cuDnn库下载
https://developer.nvidia.com/cudnn
下载这个安装包需要注册并且填一堆问卷,下下来以后把相关包不用安装,直接拷到cuda路径对应的C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0文件夹下面就行(不是替换)


附上:
Anaconda安装坑稍微少一些,据说如果会配置会比直接上手快得多
参考:http://blog.csdn.net/sb19931201/article/details/53648615
还有看了下网上教程可能会linux/mac的用命令行配置速度更快
win10坑不少。


官方测试(测试前先导入TensorFlow......)
The TensorFlow implement 
ation translates the graph definition into executable operations distributed across available compute resources, such as the CPU or one of your computer’s GPU cards. In general you do not have to specify CPUs or GPUs explicitly. TensorFlow uses your first GPU, if you have one, for as many operations as possible.


#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)
输出:


Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: Tesla K40c, pci bus
id: 0000:05:00.0
b: /job:localhost/replica:0/task:0/gpu:0
a: /job:localhost/replica:0/task:0/gpu:0
MatMul: /job:localhost/replica:0/task:0/gpu:0
[[ 22.  28.]
 [ 49.  64.]]


通过上述官方测试算是成功了,可能屏幕会黑一下(显卡性能问题)。
 [ 49.  64.]]
附上一些GitHub的源码测试:
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples
原创粉丝点击