Step 7: Install Dependencies
If you have already git then skip this else do this.
go to https://git-scm.com/download/win download git and install with all default settings.
Goto https://cmake.org/download/ and download Windows win64-x64 Installer.
Install it but make sure to check Add Cmake to system path for all users.
goto http://www.swig.org/download.html and download swigwin.
Extract it to C:\
Step 8: Verify if your CPU support AVX/ AVX2:
AVX/AVX2 optimization make tensorflow perform faster.
You can verify for AVX/ AVX2 support for your CPU by using Coreinfo tool.
Goto https://docs.microsoft.com/en-us/sysinternals/downloads/coreinfo to get it.
Extract it to C:\
Goto run (Win+R) and type cmd
Run following command:
Look for AVX
AVX * Supports AVX intruction extensions
If you got * then it supports AVX.
Step 9: Configure Tensorflow from source using CMake:
Start the process of building TensorFlow by downloading latest tensorflow 1.5.0
Goto run (Win+R) and copy paste following:
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2015\Visual Studio Tools\Windows Desktop Command Prompts\VS2015 x64 Native Tools Command Prompt.lnk"
cd c:\ git clone https://github.com/tensorflow/tensorflow cd tensorflow git checkout r1.5 cd tensorflow\contrib\cmake mkdir build cd build
Activate your virtual environment eg. Virtualenv, conda, anaconda with python version 3.5. This makes CMake detect python automatically with python related to your virtual environment.
Install numpy (required):
pip install --upgrade numpy pip install --upgrade wheel
If AVX is supported by your CPU then do following:
cmake -G "Visual Studio 14 2015 Win64" -T host=x64 -DCMAKE_BUILD_TYPE=Release -DSWIG_EXECUTABLE=c:/swigwin-3.0.12/swig.exe -Dtensorflow_ENABLE_GPU=ON -Dtensorflow_CUDA_VERSION=9.1 -Dtensorflow_CUDNN_VERSION=7 -Dtensorflow_WIN_CPU_SIMD_OPTIONS=/arch:AVX2 ..
Else do following:
cmake -G "Visual Studio 14 2015 Win64" -T host=x64 -DCMAKE_BUILD_TYPE=Release -DSWIG_EXECUTABLE=c:/swigwin-3.0.12/swig.exe -Dtensorflow_ENABLE_GPU=ON -Dtensorflow_CUDA_VERSION=9.1 -Dtensorflow_CUDNN_VERSION=7 ..
You can see:
-- Configuring done -- Generating done -- Build files have been written to: C:/tensorflow/tensorflow/contrib/cmake/build
Goto “C:\tensorflow\third_party\gpus\cuda\ ” and open “cuda_config.h” with any editor or notepad.
Edit this line with your CUDA capability noted in step 1:
#define TF_CUDA_CAPABILITIES CudaVersion("3.0"),CudaVersion("3.5"),CudaVersion("5.2")
For my GPU, CUDA capability is 5.0
#define TF_CUDA_CAPABILITIES CudaVersion("5.0")
Verify following files with numbers as specified below:
#define TF_CUDA_VERSION "64_91" #define TF_CUDNN_VERSION "64_7" "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\bin\cudart64_91.dll" "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\bin\cudnn64_7.dll"
If all good then we are ready to build Tensorflow.
Step 10: Build Tensorflow using MSbuild
Copy this file (required):
"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\include\crt\math_functions.hpp" to "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\include\"
Disable real-time protection of Windows Defender or any other antivirus. We found that doing this dramatically decreases build time by a few hours.
Build using MSbuild to create whl file (pip package) using the following command:
MSBuild /p:Configuration=Release /verbosity:detailed tf_python_build_pip_package.vcxproj
It will take 4 -5 hours if antivirus disabled.
Step 11: Install Tensorflow GPU on Windows
Finally… Activate virtual environment here where you want to install tensorflow.
To install tensorflow gpu on windows with pip:
pip install "C:\tensorflow\tensorflow\contrib\cmake\build\tf_python\dist\tensorflow_gpu-1.5.0-cp35-cp35m-win_amd64.whl"
note- correct whl filename if not found.
Step 12: Verify Tensorflow installation
Run in terminal
python import tensorflow as tf hello = tf.constant('Hello, TensorFlow!') sess = tf.Session() print(sess.run(hello))
If the system outputs the following, then you are ready to begin writing TensorFlow programs:
Success! You have now successfully installed tensorflow GPU on windows machine.
Since it is experimental as stated on the official website, comment below if any errors occurred.
If you can’t make it, then go to How to install Tensorflow 1.5.0 using official pip package. for alternative.
For prebuilt wheel with optimization for AVX2 and cuda 9.1, cudnn 7.0.5, compute capability 5.0 go to this link .
Do let us know in the comments below if it worked for you. Or if you got any errors. Cheers!