Install Tensorflow(GPU support) with Anaconda on Windows 10
This guide is an enhanced version of the official installation instruction. It includes more details and explanations. You can find the original version here.
About TensorFlow
TensorFlow™ is an open source software library for numerical computation using data flow graphs. Nodes in the graph represent mathematical operations, while the graph edges represent the multidimensional data arrays (tensors) communicated between them. The flexible architecture allows you to deploy computation to one or more CPUs or GPUs in a desktop, server, or mobile device with a single API. TensorFlow was originally developed by researchers and engineers working on the Google Brain Team within Google’s Machine Intelligence research organization for the purposes of conducting machine learning and deep neural networks research, but the system is general enough to be applicable in a wide variety of other domains as well.
Determine which Tensorflow to install
There are two version of TensorFlow:
- TensorFlow with CPU support only. If you only want to play around with TensorFlow or your system does not have a NVIDIA GPU, I recommend you install this version. Note that this version of TensorFlow is much easier to install.
- TensorFlow with GPU support. If your system has a valid NVIDIA GPU and you want to build some real neural networks or deep networks which definitely need massive computation, I recommend you install this version. TensorFlow programs typically run much faster on a GPU than on a CPU. Here is an article about benchmark CPU and GPU performance.
In following parts of this guide, I will explain how to install TensorFlow with GPU support.
Requirements to run TensorFlow with GPU support
Attention!!! You must download and install the specified versions. This is very important. For example, the cuDNN version must match exactly: TensorFlow will not load if it cannot find cuDNN64_6.dll
.
Check the CUDA Compute Capability of your GPU card.
It should be 3.0 or higher. See NVIDIA documentation for a list of supported GPU cards. If your GPU card capability is lower than 3.0 or you can’t find your GPU card in the list, you can just install the only CPU supported version or spend some dollars to buy a powerful NVIDIA GPU card. BTW, I’m using the GTX1080Ti.
CUDA Toolkit 8.0
what is CUDA?
CUDA is a parallel computing platform and programming model that makes using a GPU for general purpose computing simple and elegant. The developer still programs in the familiar C, C++, Fortran, or an ever expanding list of supported languages, and incorporates extensions of these languages in the form of a few basic keywords. Check this out!
How to install it?
Note that the version should be 8.0, not the newest version of CUDA Toolkit which is already 9.0 now and TensorFlow still does not support the newest version.
We can just google “cuda toolkit 8.0”, then click the first one. Here is the link.
Then we set the right options. I recommend you to use the local installer in case we may need to install it again in the future.
Create a new folder inside C:\Program Files, name it “NIVIDIA CUDA Computing Toolkit”. That is where we are going to put our CUDA toolkit in.
After we successfully install it, we will have this file structure.
We come the most important part. Ensure that you append the relevant Cuda pathnames to the %PATH%
environment variable as described in the NVIDIA documentation. Open your Control panel, select System and Security, click System. Then enter Advanced system settings.
Inside the Environment Variables, we choose Edit Path, then add two new variables.
- C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin
- C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\libnvvp
Install NVIDIA drivers associated with CUDA Toolkit 8.0
Since I have used NIVIDIA GPU for a very long time, I already have its driver installed in my computer. If you are new users, you can find and download drivers here. You can manually setup search options or let it automatically search the right driver.
Download cuDNN v6.1
Note that you should download cuDNN v6.1 not the newest version which is already cuDNN 7.0 nowadays.
Here is the link to download cuDNN. Click the “Download” button which is very easy to be found at the middle of this webpage. For this part, you may need to create a new account to join the NVIDIA developer program. It will not charge you any money. Just relax and get enrolled. After you done this, you will be able to see the download options. Remeber that we need to choose cuDNN v6.0 Library for CUDA 8.0 and Windows 10.
After download, unzip it into C:\Program Files.
Ensure that you add the directory where you installed the cuDNN DLL to your %PATH%
environment variable. Follow what we did above, but this time we add cuDNN DLL into PATH.
- C:\Program Files\cuda\bin
So far, we already get everything we need for the GPU supported version. We almost there!
Determine how to install TensorFlow
There are two ways to install TensorFlow:
- “native” pip. Native pip installs TensorFlow directly on your system without going through a virtual environment. Since a native pip installation is not walled-off in a separate container, the pip installation might interfere with other Python-based installations on your system. However, if you understand pip and your Python environment, a native pip installation often entails only a single command! Furthermore, if you install with native pip, users can run TensorFlow programs from any directory on the system.
- Anaconda. Anaconda is the most popular python data science platform, I recommend you to use this way to install TensorFlow. In Anaconda, you may use conda to create a virtual environment. However, within Anaconda, we recommend installing TensorFlow with the
pip install
command, not with theconda install
command since the conda package is community supported, not officially supported. That is, the TensorFlow team neither tests nor maintains this conda package. Use that package at your own risk.
Installing with Anaconda
- Follow the instructions on the Anaconda download site to download and install the right version of Anaconda.
- Create a conda environment named
tensorflow
by invoking the following command:1
C:> conda create -n tensorflow python=3.6
- Activate the conda environment by issuing the following command:
1
2C:> activate tensorflow
(tensorflow)C:> # Your prompt should change - Issue the appropriate command to install TensorFlow inside your conda environment. To install the GPU version of TensorFlow, enter the following command:In case someone want to use CPU-only version, here is the command:
1
(tensorflow)C:> pip install --ignore-installed --upgrade tensorflow-gpu
1
pip install --ignore-installed --upgrade tensorflow
Validate your installation
Let’s check if it is work or not. Open Anaconda Prompt, activate our Anaconda environment.
1 |
|
Invoke python from our shell as follows:
1 |
|
Enter the following short program inside the python interactive shell:
1 |
|
we can see this result in the Anaconda Promote:
1 |
|
Congratulations! We did it! You are all set!
If you are new to TensorFlow, see Getting Started with TensorFlow. Also, check this, MNIST for ML Beginners. MNIST has become the canonical dataset for trying out a new machine learning toolkit. This is the super famous “Hello, World!” in ML.
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!