How to install TensorFlow on Windows?

2020-02-02 06:07发布

I am starting to work with TensorFlow library for deep learning, https://www.tensorflow.org/.

I found a explicit guide to work on it on linux and Mac but I did not find how to work with it under Windows. I try over the net, but the information are lacking.

I use Visual Studio 2015 for my projects, and I am trying to compile the library with Visual studio Compiler VC14.

How to install it and to use it under Windows?

Can I use Bazel for Windows for production use?

11条回答
Evening l夕情丶
2楼-- · 2020-02-02 06:36

Follow this link to install Tensorflow on Windows and you can also use it in Visual Studio

查看更多
再贱就再见
3楼-- · 2020-02-02 06:37

You can't at the moment. The problem is that tensorflow uses the bazel build another Google internal tool that has been exposed as an open source project and it has only support for mac and unix. Until bazel is ported to windows or another build system is added to tensorflow there is a little chance to run tensorflow natively on windows.

That said you can install virtualbox and then install docker-machine and run a linux container with tensorflow inside it.

查看更多
来,给爷笑一个
4楼-- · 2020-02-02 06:39

As of writing this answer, I wasn't able to get tensorflow to install properly with python version 3.5.2. Reverting to python 3.5.0 did the trick.

Then I was able to install with

C:> pip install tensorflow

查看更多
欢心
5楼-- · 2020-02-02 06:47

Installing TensorFlow

TensorFlow currently supports only Python 3.5 64-bit. Both CPU and GPU are supported. Here are some installation instructions assuming you do not have Python 3.5 64-bit:

  1. Download and install Microsoft Visual C++ 2015 Redistributable Update 3: https://www.microsoft.com/en-us/download/details.aspx?id=53587 (required by Python 3.5 and TensorFlow)
  2. Download and install Python 3.5 64-bit: https://www.python.org/ftp/python/3.5.2/python-3.5.2-amd64.exe
  3. Install pip as follows: download https://bootstrap.pypa.io/get-pip.py, then run python get-pip.py
  4. Install TensorFlow with either pip install tensorflow (CPU version) or pip install tensorflow-gpu (GPU version --> requires CUDA to be installed).

Testing TensorFlow

You can now run something like following to test whether TensorFlow is working fine:

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

TensorFlow comes with a few models, which are located in C:\Python35\Lib\site-packages\tensorflow\models\ (assuming you installed python in C:\Python35). For example, you can run in the console:

python -m tensorflow.models.image.mnist.convolutional

or

python C:\Python35\Lib\site-packages\tensorflow\models\image\mnist\convolutional.py

Limitations of TensorFlow on Windows

Initial support for building TensorFlow on Microsoft Windows was added on 2016-10-05 in commit 2098b9abcf20d2c9694055bbfd6997bc00b73578:

This PR contains an initial version of support for building TensorFlow (CPU only) on Windows using CMake. It includes documentation for building with CMake on Windows, platform-specific code for implementing core functions on Windows, and CMake rules for building the C++ example trainer program and a PIP package (Python 3.5 only). The CMake rules support building TensorFlow with Visual Studio 2015.

Windows support is a work in progress, and we welcome your feedback and contributions.

For full details of the features currently supported and instructions for how to build TensorFlow on Windows, please see the file tensorflow/contrib/cmake/README.md.

The Microsoft Windows support was introduced in TensorFlow in version 0.12 RC0 (release notes):

TensorFlow now builds and runs on Microsoft Windows (tested on Windows 10, Windows 7, and Windows Server 2016). Supported languages include Python (via a pip package) and C++. CUDA 8.0 and cuDNN 5.1 are supported for GPU acceleration. Known limitations include: It is not currently possible to load a custom op library. The GCS and HDFS file systems are not currently supported. The following ops are not currently implemented: DepthwiseConv2dNative, DepthwiseConv2dNativeBackpropFilter, DepthwiseConv2dNativeBackpropInput, Dequantize, Digamma, Erf, Erfc, Igamma, Igammac, Lgamma, Polygamma, QuantizeAndDequantize, QuantizedAvgPool, QuantizedBatchNomWithGlobalNormalization, QuantizedBiasAdd, QuantizedConcat, QuantizedConv2D, QuantizedMatmul, QuantizedMaxPool, QuantizeDownAndShrinkRange, QuantizedRelu, QuantizedRelu6, QuantizedReshape, QuantizeV2, RequantizationRange, and Requantize.

查看更多
欢心
6楼-- · 2020-02-02 06:48

I can confirm that it works in the Windows Subsystem for Linux! And it is also very straightforward.

In the Ubuntu Bash on Windows 10, first update the package index:

apt-get update

Then install pip for Python 2:

sudo apt-get install python-pip python-dev

Install tensorflow:

sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

The package is now installed an you can run the CNN sample on the MNIST set:

cd /usr/local/lib/python2.7/dist-packages/tensorflow/models/image/mnist

python convolutional.py

I just tested the CPU package for now.

I blogged about it: http://blog.mosthege.net/2016/05/11/running-tensorflow-with-native-linux-binaries-in-the-windows-subsystem-for-linux/

cheers

~michael

查看更多
登录 后发表回答