【TensorFlow】Windows10下配置TensorFlow环境

0x00 前言

前言什么的也懒得说了……
总之:
TeamViewer中转+VNC连接来图形化,
SecureCRT两重ssh跳转来改代码,
以及paste.ubuntu.com来复制粘贴,
这样的日子我已经受够了…… 我要在我的windows上配一个!

0x01 官方说明

Installing with Anaconda

The Anaconda installation is community supported, not officially supported.

Take the following steps to install TensorFlow in an Anaconda environment:

Follow the instructions on the Anaconda download site to download and install Anaconda.

Create a conda environment named tensorflow by invoking the following command:
使用如下指令创建一个名为tensorflow的conda环境:

1
C:> conda create -n tensorflow

Activate the conda environment by issuing the following command:
可以用如下指令来激活conda环境:

1
2
C:> activate tensorflow
(tensorflow)C:> # Your prompt should change

Issue the appropriate command to install TensorFlow inside your conda environment. To install the CPU-only version of TensorFlow, enter the following command:

1
(tensorflow)C:> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.1.0-cp35-cp35m-win_amd64.whl 

To install the GPU version of TensorFlow, enter the following command (on a single line):

1
(tensorflow)C:> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-win_amd64.whl 

0x02 尝试

于是我跑去装了个Anaconda
anaconda

装好之后愉快的开始乱敲:

1
2
3
C:> conda create -n tensorflow
C:> activate tensorflow
(tensorflow)C:>

conda环境是需要有的,虽然我开一个环境是因为dalao们都这么开,但是实际上这是很有意义的,比如……你瞎配环境配炸了怎么办呢对不对,另一个方面也是为了不影响你原生系统里的环境,在这个你自己设定的env里就是一个纯净环境,转为某种工程环境配置的,在各种env之间切换,也比较高效和稳定。

1
(tensorflow)C:> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-win_amd64.whl 

哎?为什么用不了呢,于是我注意到了一件事情:

tensorflow_gpu-1.1.0-cp 35 -cp 35 m-win_amd64.whl

原来如此,python版本变成python3.5.x就可以了对吧~
但是,这个conda是python3.6的呀,我总不能去archive里看着连python版本都不标明的仓库里一个一个试哪个是python3.5吧……

这个时候conda环境的好处就来啦~ 我们可以在这个名为tensorflow的环境里使用python3.5,还不影响外面的python3.6~并且装好tensorflow之后和这个python3.5完美适配的在这个环境里用来敲tf代码:

conda

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
C:\Users\Work> activate tensorflow
(tensorflow) C:\Users\Work> conda install python==3.5
Fetching package metadata ...........
Solving package specifications: .

Package plan for installation in environment C:\ProgramData\Anaconda3\envs\tensorflow:

The following NEW packages will be INSTALLED:

msvc_runtime: 1.0.1-vc14_0 [vc14]
pip: 9.0.1-py35_1
python: 3.5.0-4
setuptools: 27.2.0-py35_1
wheel: 0.29.0-py35_0

Proceed ([y]/n)?

哈哈,果不其然,可以装啦可以装啦——

1
2
3
4
5
6
7
8
9
10
(tensorflow) C:\Users\Work>pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.1.0-cp35-cp35m-win_amd64.whl
Collecting tensorflow==1.1.0 from https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.1.0-cp35-cp35m-win_amd64.whl
Downloading https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.1.0-cp35-cp35m-win_amd64.whl (19.4MB)
69% |██████████████████████▏ | 13.4MB 877kB/s eta 0:00:07

......

Installing collected packages: wheel, numpy, six, pyparsing, packaging, appdirs, setuptools, protobuf, werkzeug, tensorflow
Successfully installed appdirs-1.4.3 numpy-1.12.1 packaging-16.8 protobuf-3.3.0 pyparsing-2.2.0 setuptools-35.0.2 six-1.10.0 tensorflow-1.1.0 werkzeug-0.12.1 wheel-0.29.0

顺便再把GPU版本的也装了吧——

1
2
3
4
5
6
7
8
9
(tensorflow) C:\Users\Work>pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-win_amd64.whl
Collecting tensorflow-gpu==1.1.0 from https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-win_amd64.whl
Downloading https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-win_amd64.whl (48.5MB)
4% |█▋ | 2.4MB 1.1MB/s eta 0:00:41

......

Installing collected packages: wheel, numpy, pyparsing, six, packaging, appdirs, setuptools, protobuf, werkzeug, tensorflow-gpu
Successfully installed appdirs-1.4.3 numpy-1.12.1 packaging-16.8 protobuf-3.3.0 pyparsing-2.2.0 setuptools-35.0.2 six-1.10.0 tensorflow-gpu-1.1.0 werkzeug-0.12.1 wheel-0.29.0

##0x03 测试运行

安装完了哎……
真的假的?
跑跑试试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
(tensorflow) C:\Users\Work>python
Python 3.5.0 |Continuum Analytics, Inc.| (default, Dec 1 2015, 11:46:22) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
2017-05-04 13:48:07.019445: 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.
2017-05-04 13:48:07.020593: 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 SSE2 instructions, but these are available on your machine and could speed up CPU computations.
2017-05-04 13:48:07.021313: 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 SSE3 instructions, but these are available on your machine and could speed up CPU computations.
2017-05-04 13:48:07.022356: 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 SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-05-04 13:48:07.024544: 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 SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-05-04 13:48:07.026923: 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 AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-05-04 13:48:07.028016: 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 AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-05-04 13:48:07.028824: 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 FMA instructions, but these are available on your machine and could speed up CPU computations.
>>> sess.run(hello)
b'Hello, TensorFlow!'

虽然不知道蹦出来些什么,不过看上去是装好了的样子,可喜可贺可喜可贺~

0x04 后记

Fold runs under Linux; we have not tested it on other platforms. Python 2.7 and 3.3+ are both supported. We recommend installing using Virtualenv and pip. See here for instructions on installing from sources, if that’s how you roll. If you run into trouble, the TensorFlow main site has a list of common problems with some solutions that might be helpful.

Please note that Fold requires TensorFlow 1.0; it is not compatible with earlier versions due to breaking API changes.

Tensorflow_Fold 就别想了QvQ
容我哭一会儿