http://www.javashuo.com/article/p-mlivmoir-kg.htmlhtml
https://blog.csdn.net/tomato_sir/article/details/79973237html5
https://blog.csdn.net/qq_36556893/article/details/79433298 -->这里面有个连接,支持cuda9.1的tensorflowpython
装GPU版本的tensorflow,搞了1天多,终于搞清前因后果。记录于此但愿让你少走弯路。 网络
个人第一块显卡是 NVIDIA Quadro 2000dom
支持cuda5.0.1 ,驱动过低,tensorflow gpu版本须要至少cuda8.0。 你用驱动精灵升级你的显卡驱动。ide
后来发现,不须要用驱动精灵先升级显卡驱动的。你就直接装cuda,所有安装,别少选,他里面有驱动,会帮你升级。但问题是,老显卡你不知道最高支持多少,好比显卡最高支持cuda8.0,你装个cuda9.0,那不行的。测试
因此,若是你是第一次装,你仍是老老实实先用驱动精灵升级显卡驱动,这样你就知道显卡最高支持多少的cuda了。优化
我以前不知道上面的规律,因此我看到5.0.1后,觉得这显卡不能用,换了一个更高级的显卡,用驱动精灵装完驱动后发现显卡是cuda9.2,后来发现后续装cudnn 支持不了9.2(why?你看这篇文章的第5点,列表中cuda9.2没有支持win7的包),后来从新装cuda9.0 后,这里的驱动也降到了9.0. 网站
上面的经验也折腾了很久。。ui
下图是我第一块显卡,后来被证明这块显卡装好最新驱动后支持cuda8.0. 下面的记录都是我用第二块显卡的过程。这个图的主要目的是让你知道哪里去找显卡的cuda版本。你运行里面直接搜索'nvidia控制面板就行'
图一
1.为了要cpu和gpu都支持,须要新建一个新的虚拟环境
(后来我把虚拟环境删除了,不要cpu版本的了,直接gpu版本,下面2.3 两步能够省略)
conda create --name tensorflow-gpu python=3.6
红色字为新环境名字,随意~
2.切换到新的环境
activate tensorflow-gpu
3.查看当前环境, 能够看到已经切换了。 * 好就是当前的环境
conda info --envs
4.安装cuda
先装 VS2013 (VS2015 VS2017 均可以行,vs2012是否能够,请网友试验成功后告诉我哈,我装cuda时,里面显示能够装vs2012的扩展,因此我认为都是能够的)
装完vs,装cuda
CUDA下载地址:https://developer.nvidia.com/cuda-downloads
个人cuda在这里:https://developer.nvidia.com/cuda-90-download-archive?target_os=Windows&target_arch=x86_64&target_version=7&target_type=exelocal
5. 装cudnn
务必到下面网站看下,支持的cuda版本,和操做系统的版本。我是win7,cuda9.0 用的是红框的。
https://developer.nvidia.com/rdp/cudnn-archive (这网站要注册,并且网站比较慢,须要FQ,好麻烦的~~)
按照其余帖子,把cudnn直接复制到相应目录。
打开你下载路径能够看到cuda文件夹下有三个子文件,分别为bin、include和lib
将如下三个路径添加到环境变量中(不知道环境变量在哪的朋友自行百度~)
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\lib\x64;
(舒适提示:记得路径之间加分号 ;)
6. 安装 tensorflow-gpu 1.5.0
若是第一次使用anaconda,pip可能比较老了,能够升级一下pip先:
python -m pip install --upgrade pip
安装以前记得先把cpu版本的tensorflow卸载,还有tensorboard也卸载。
pip uninstall tensorflow
pip uninstall tensorboard (这步大概不须要,你本身看看吧)
pip install tensorflow-gpu==1.5.0 指定一个版本, 老版本不支持 cuda9.0 只支持cuda8.0,新的版本听说有bug,反正用1.5.0听说不出问题。
备用,若是你pip安装出错或者网络慢,能够先下载whl文件:
tensorflow 的 whl文件下载
https://pypi.org/project/tensorflow-gpu/1.5.0/#files
7.测试下
我作测试时,全部都装好后运行下面两句,import没问题,可是tf.__version__显示没有这个模块。
通过反复重装也没用,最后,我把anaconda更新了一下。就行了【轻描淡写的一句话,实际上我折腾了大半天。。。。最后不行了才想到去更新anaconda】
import tensorflow as tf tf.__version__
测试是否能用gpu,应该返回true
tf.test.is_gpu_available( cuda_only=False, min_cuda_compute_capability=None )
8. 更新anaconda
如下两个方法都OK。大概须要半小时左右(看网速多快了)。我用第一个方法的。
方法1:
方法2:
conda install -c anaconda html5lib
用了方法一后,我对比了一下,发现里面的包并无更新:
上面2种方法仍是有点区别的,第二种方法会更新全部的库,第一种方法并无更新别的库,只是更新了conda
相似于下面,这句话的意思是更新conda,这个指令的做用是更新conda 的package库
第一种方法相似于:conda update conda
第2种方法相似于:conda update --all
conda的文档
https://conda.io/docs/user-guide/getting-started.html
9. 通过上面第8步更新后,再回到第六步,安装tensorflow-gpu 就能够安装成功了。
一段demo
#写在第一段单元格 import tensorflow as tf hello = tf.constant('Hello, TensorFlow!') sess = tf.Session() print(sess.run(hello)) a = tf.constant(10) b = tf.constant(32) print(sess.run(a + b)) #写在第二个cell import tensorflow as tf import numpy import matplotlib.pyplot as plt rng = numpy.random learning_rate = 0.01 training_epochs = 1000 display_step = 50 #数据集x train_X = numpy.asarray([3.3,4.4,5.5,7.997,5.654,.71,6.93,4.168,9.779,6.182,7.59,2.167, 7.042,10.791,5.313,9.27,3.1]) #数据集y train_Y = numpy.asarray([1.7,2.76,3.366,2.596,2.53,1.221,1.694,1.573,3.465,1.65,2.09, 2.827,3.19,2.904,2.42,2.94,1.3]) n_samples = train_X.shape[0] X = tf.placeholder("float") Y = tf.placeholder("float") W = tf.Variable(rng.randn(), name="weight") b = tf.Variable(rng.randn(), name="bias") pred = tf.add(tf.multiply(X, W), b) cost = tf.reduce_sum(tf.pow(pred-Y, 2))/(2*n_samples) optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost) init = tf.initialize_all_variables() with tf.Session() as sess: sess.run(init) # 训练数据 for epoch in range(training_epochs): for (x, y) in zip(train_X, train_Y): sess.run(optimizer, feed_dict={X: x, Y: y}) print("优化完成!") training_cost = sess.run(cost, feed_dict={X: train_X, Y: train_Y}) print("Training cost=", training_cost, "W=", sess.run(W), "b=", sess.run(b), '\n') #可视化显示 plt.plot(train_X, train_Y, 'ro', label='Original data') plt.plot(train_X, sess.run(W) * train_X + sess.run(b), label='Fitted line') plt.legend() plt.show()
运行后显示:
10 虽然能运行上面的,可是发现导入tensorflow时会报错
是由于numpy版本和h5py的不兼容,升级 pip install --upgrade h5py==2.8.0rc1
参考:
https://blog.csdn.net/u014561933/article/details/80156091