Build TensorFlow on Windows

Requirements:

  1. GIT for Windows: https://git-scm.com/download/win
  2. SWIG: https://sourceforge.net/projects/swig/files/swigwin/swigwin-3.0.10/
  3. Visual Studio 2015: https://www.visualstudio.com/downloads/, https://www.visualstudio.com/vs/older-downloads/
  4. CMake 3.4 or higher: https://cmake.org/download/
  5. Python 3.5 Anaconda x64: https://repo.continuum.io/archive/Anaconda3-4.2.0-Windows-x86_64.exe
  6. CUDA 8.0:  https://developer.nvidia.com/cuda-downloads
  7. cuDNN v5.1: https://developer.nvidia.com/cudnn

Instructions:

  1. Install Cmake and add it to system path.
  2. Install CUDA v8.0 (For GPU support only)
  3. Extract cuDNN (For GPU Support only)
    • copy all files from bin folder to 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin'
    • similarly from include to 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include' 
    • and 'lib\x64' to  ''C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64'.
  4. Install Anaconda in "C:\tools\", make sure you select Register Anaconda as system path for Python 3.5.
  5. Extract SWIG in "C:\tools\" folder.
  6. Open command window in the desired folder "D:\Downloads\tensorflow" (Shift+RightClick and Open Command Window here).
  7. Enter the following commands
    D:\Downloads>call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
  8. Clone tensorflow directory and set up cmake configuration:
    D:\Downloads> git clone https://github.com/tensorflow/tensorflow.git
    D:\Downloads> cd tensorflow
    D:\Downloads\tensorflow> git checkout r1.2
    D:\Downloads\tensorflow> cd tensorflow\contrib\cmake
    D:\Downloads\tensorflow\tensorflow\contrib\cmake> mkdir build
    D:\Downloads\tensorflow\tensorflow\contrib\cmake> cd build
    D:\Downloads\tensorflow\tensorflow\contrib\cmake\build>  
    
  9. Invoke CMake and create Visual Studio solution by entering the following commands
    D:\Downloads\tensorflow\tensorflow\contrib\cmake\build> cmake .. -A x64 -DCMAKE_BUILD_TYPE=Release ^
     More? -DSWIG_EXECUTABLE=C:/tools/swigwin-3.0.10/swig.exe ^
     More? -DPYTHON_EXECUTABLE=C:/tools/Anaconda3/python.exe ^
     More? -DPYTHON_LIBRARIES=C:/tools/Anaconda3/libs/python35.lib ^
     More? -Dtensorflow_ENABLE_GPU=ON ^
     More? -DCUDNN_HOME="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0" 
    
  10. Build C++ tensorflow example
    D:\Downloads\tensorflow\tensorflow\contrib\cmake\build> MSBuild /p:Configuration=Release tf_tutorials_example_trainer.vcxproj
    D:\Downloads\tensorflow\tensorflow\contrib\cmake\build> Release\tf_tutorials_example_trainer.exe
    
  11. Build PIP package as .whl file
    D:\Downloads\tensorflow\tensorflow\contrib\cmake\build> MSBuild /p:Configuration=Release tf_python_build_pip_package.vcxproj
    
  12. PIP package is built in .\tf_python\dist folder. Enter the following commands to install tensorflow for python
    D:\Downloads\tensorflow\tensorflow\contrib\cmake\build> cd tf_python\dist
    D:\Downloads\tensorflow\tensorflow\contrib\cmake\build\tf_python\dist>
    D:\Downloads\tensorflow\tensorflow\contrib\cmake\build\tf_python\dist> pip install tensorflow_gpu-1.2.1-cp35-cp35m-win_amd64
    
  13. Enter the following commands to run tensorflow using python
    D:\Downloads\tensorflow\tensorflow\contrib\cmake\build\tf_python\dist> python
     >>> import tensorflow as tf
     >>> hello = tf.constant('Hello, TensorFlow!')
     >>> sess = tf.Session()
     >>> print(sess.run(hello))
     'Hello, TensorFlow!'
    
  14. The command should print 'Hello, TensorFlow!' if you have successfully installed tensorflow.

 

2 comments:

  1. Hi Shan,

    Thank you very much for the post, its very helpful. I did all the steps but at the end I didn't see any .whl file generated. do you have any advise on what may I be missing?

    Thank you very much
    Regards
    Amit

    ReplyDelete
    Replies
    1. Did you build for python? Do you have a compatible version of python installed on your machine?

      Delete

How to run R code in Python

R is freely available language and computational tool which is very popular among the statisticians and bioinformatics community. In this p...