Win10通过Anaconda安装GPU版tensorflow

安装:

主要参考这个网址,但是他之中的Cudnn无法安装,原因复杂:
https://zhuanlan.zhihu.com/p/37086409

Cudnn的安装参考这个网址,之后返回主要参考的网址:
https://blog.csdn.net/angzhangzhang123/article/details/79637346

下载tensorflow的时候,也就是命令行下输入这个命令时:
pip install --ignore-installed --upgrade tensorflow_gpu==1.2.0
它会很慢,或者是卡住了,点击鼠标右键或是一个ctral+c推进它结束或是继续。
这个安装tensorflow的步骤是一个难点,它会从网上下载资源,而且网络不好,时常中断,你只能不断地重复输入这个命令,
或是更换一个更好的网络。要坚持下去。

 

测试:

先打开Anaconda Prompt:

Win10通过Anaconda安装GPU版tensorflow

然后输入:activate tensorflow  **tensoflow环境。再输入:python   进入python编程环境

Win10通过Anaconda安装GPU版tensorflow

 

测试tensorflow是否是在用GPU,如果是,结果会有GPU:0的输出,把下面这些代码粘贴进Anaconda Prompt

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

Win10通过Anaconda安装GPU版tensorflow

然后打开Anconda Navigatior

Win10通过Anaconda安装GPU版tensorflow

进入tensorflow环境:

Win10通过Anaconda安装GPU版tensorflow

安装spyder,我这里已经安装了,它显示的是launch。

Win10通过Anaconda安装GPU版tensorflow

然后你就可以用spyder这个IDE使用tensorflow框架了。

当你安装了无数次tensorflow后却不尽人愿,那你就卸载了Anaconda重新来吧。

 

附录:

1.查看已经安装的CUDA版本
cmd下输入:nvcc -V

 

2.
#查看tensorflow版本
import tensorflow as tf
tf.__version__
#查询tensorflow安装路径为:
tf.__path__

 


3.怎么卸载tensorflow
卸载命令时‘pip uninstall tensorflow’。但要先确定我们所在的是哪个环境,
如果所在基础python3.6环境,使用这个命令是没有用处的,倒是你输入‘pip u
ninstall python’可以把基础python3.6环境卸载掉。怎样卸载tensorflow呢?
我们需要先**有tensorflow的环境,命令为‘activate tensorflow’,然后再
输入命令‘pip uninstall tensorflow’就可以了,卸载python2.7环境也是同理,输入‘pip uninstall python27’。? ? ? ? ? 
--------------------- 
作者:aiguiru 
来源:CSDN 
原文:https://blog.csdn.net/ifisher999/article/details/81085805 
版权声明:本文为博主原创文章,转载请附上博文链接!

 

4.查看anaconda的所有环境:
命令行下:
conda info --envs

 

5.

#看tensorflow安装在CPU还是GPU上
import os
from tensorflow.python.client import device_lib
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "99"
if __name__ == "__main__":
    print(device_lib.list_local_devices())

#看tensorflow安装在CPU还是GPU上
import tensorflow as tf
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)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) 
print (sess.run(c))
sess.close()

 

6.怎么用pip卸载应用
先命令行下:pip list来查看安装了什么包
https://jingyan.baidu.com/article/ea24bc39d8497eda62b3313a.html
pip uninstall 要卸载的包名
比如:pip uninstall tensorflow

加上一个参数-y,启动安静模式,即不提示是否卸载。
pip uninstall tensorflow -y

******完结撒花******