代码改变世界

安装WIN7/WIN10上的 CPU版本的TensorFlow

2017-11-23 16:39  撞破南墙  阅读(1058)  评论(0编辑  收藏  举报

随手记

ancaconda Anaconda2-5.0.1-Windows-x86_64
(python3.5 ancaconda python-3.5.2-amd64 安装TensorFlow的时候自动依赖安装)
charmpython IDE

1 安装 ancaconda
访问Anaconda的下载页面,下载Python 3..6,选择64位版本。


2 配置国内的源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

  


3 继续在 Anaconda Prompt 窗口输入:
conda create -n tensorflow python=3.5

【】

在这最近找到一个新的方法,更简单

[3.7的版本]

conda create -n tensorflow python=3.7

activate tensorflow   输入 激活环境

 

一、安装tensorflow-gpu=2.2.0使用清华源安装,代码如下:

pip install tensorflow-gpu==2.2.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

这样下载速度飞起!

二、什么去官网下载cuda版本配置路径,感觉都不靠谱,我实验了,一个命令搞定,我的是1080Ti显卡,先通过GeForce Experience把驱动更新到最新,我的cuda信息如下:
在这里插入图片描述
我cuda的是11.0,这不重要,一般需要cuda是10.1或者以上就可以了。
然后一句代码安装:

conda install cudatoolkit=10.1 cudnn=7.6.5

注意:不要改上面的版本,不然安装成功了,使用时报错,这里就是个坑,我试过很多,这两个版本才是对应的,不管tensorflow-gpu=2.0/2.1/2.2,都适用
安装好后测试下,测试代码;

 

import tensorflow as tf


print('GPU', tf.test.is_gpu_available())

a = tf.constant(2.0)
b = tf.constant(4.0)
print(a + b)

 

安装 ffmpeg

 conda install ffmpeg -c conda-forge

#### 


4 安装CPU版本的tensorflow

 

 pip install --ignore-installed --upgrade https://mirrors.tuna.tsinghua.edu.cn/tensorflow/windows/cpu/tensorflow-1.2.1-cp35-cp35m-win_amd64.whl

 


你也可以打开 https://mirrors.tuna.tsinghua.edu.cn/tensorflow/ 选择合适的 whl 文件地址进行安装;或者打开https://mirrors.tuna.tsinghua.edu.cn/help/tensorflow/ 可视化选择 whl 版本。

 

GPU

【主要参考这篇 http://blog.csdn.net/jin739738709/article/details/73525482】

安装

 pip install --ignore-installed --upgrade https://mirrors.tuna.tsinghua.edu.cn/tensorflow/windows/gpu/tensorflow_gpu-1.2.1-cp35-cp35m-win_amd64.whl

 

### 更新版本 PYTHON 3.7 +  tensorflow-2.0

 pip install --ignore-installed --upgrade https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/54/5f/e1b2d83b808f978f51b7ce109315154da3a3d4151aa59686002681f2e109/tensorflow-2.0.0-cp37-cp37m-win_amd64.whl

 

下载对应的 

1. 下载CUDA8.0并安装

 

CUDA Toolkit 8.0 - Feb 2017

https://developer.nvidia.com/cuda-80-ga2-download-archive

[官网:https://developer.nvidia.com/rdp/cudnn-download]

 

 

2.   cuDNN v7.0.5 

 Download cuDNN v7.0.5 (Dec 5, 2017), for CUDA 8.0

https://developer.nvidia.com/rdp/cudnn-download

[官网:https://developer.nvidia.com/cuda-downloads]

 

打开你下载路径可以看到cuda文件夹下有三个子文件,分别为bin、include和lib

 设置到环境变量比如:

E:\cudnn-8.0-windows7-x64-v7\cuda\bin;E:\cudnn-8.0-windows7-x64-v7\cuda\include;E:\cudnn-8.0-windows7-x64-v7\cuda\lib\x64;

 

WIN10下的版本对应是

CUDA Toolkit 8.0 - Feb 2017    配 cudnn-8.0-windows10-x64-v5.1 ,设定好环境变量后需要重启。


5. activate tensorflow
激活 TensorFlow 虚拟环境,当不使用 TensorFlow 时,使用 deactivate tensorflow 关闭。


6. 测试
进入到 Anaconda 安装目录下 /envs /tensorflow 文件夹,继续在 Anaconda Prompt 窗口输入输入:
python.exe
回车后,复制复制如下内容拷贝到Anaconda Prompt,自动输出:
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
>>> sess.run(hello)
>>> a = tf.constant(10)
>>> b= tf.constant(32)
>>> sess.run(a+b)
>>>
输出:
...
b'Hello, TensorFlow!'
...
42

表示 TensorFlow 已经安装成功。
7.配置 charmpython
启动的时候指定python路径即可,比如我这边是这个路径。“进入到 Anaconda 安装目录下 /envs /tensorflow 文件夹”

 

其他

1.  W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations.

因为预编译的问题,可百度看到。

 

补【升级版本】

 出错处理

参考这里代码确认是否哪些DLL没有设定对

 https://www.cnblogs.com/facingwaller/p/8614164.html

 

 


1. 使用 upgrade

  • CPU:pip3 install –upgrade tensorflow
  • GPU:pip3 install –upgrade tensorflow-gpu

2. 指定升级的版本(1.2.0)

  • CPU: pip install --ignore-installed --upgrade https://mirrors.tuna.tsinghua.edu.cn/tensorflow/windows/cpu/tensorflow-1.2.1-cp35-cp35m-win_amd64.whl
  • GPU:pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.2.0-cp35-cp35m-win_amd64.whl

由上所示,python 的版本需要为 3.5。

 

---

补充 安装jieba

执行Anaconda2.exe

输入

activate tensorflow

pip install jieba

 

安装插件

activate tensorflow_gpu_121

pip install gensim

pip install sklearn

pip install matplotlib

pip install pandas