Setup Windows 10 for Machine Learning Using Tensorflow with GPU support

Using the GPU(the video card in your PC or laptop) with Tensorflow is a lot faster than the fastest CPU(processor). Even a laptop GPU will beat a 2 x AMD Opteron 6168 1.9 GHz Processor (2×12 cores total)¹. Luckily, my Windows 10 laptop has a NVIDIA GeForce GTX 1050 video card and decided to use it for machine learning while away.

Ingredients:

  1. Latest GPU driver NVIDIA GeForce GTX 1050
  2. CUDA 9.0 Toolkit
  3. CUDA 9.0 Tookit Patch 4
  4. NVIDIA CUDA Deep Neural Network library
  5. Anaconda3 v4.1.1
  6. Python 3.5
  7. Tensorflow with GPU 1.12

Instructions:

  1. Install the latest GPU driver. Reboot.
  2. Install CUDA 9.0 Toolkit
  3. Install the CUDA 9.0 Toolkit Patch 4
  4. Extract the CUDA Deep Neural Network Library to <cudnn folder> of your choice
  5. Install Anaconda
  6. Open a command prompt and set PATH for CUDA and cudnn
     SET PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin;%PATH%
    SET PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\extras\CUPTI\libx64;%PATH%
    SET PATH=&amp;amp;lt;cudnn folder&amp;amp;gt;\cuda\bin;%PATH%
  7. Reboot.
  8. Let’s create a Python 3.5 Environment. It is a good practice to create an environment for our particular need because some dependencies are only compatible with Python 3.5. We don’t want to mess up our setup when we accidentally update the root environment of Python. Open a command prompt and run code below.
    conda create -n tf-gpu python=3.5.2

    The tf-gpu is the name of our environment. You can choose any name.

  9. Let’s activate the new environment
    activate tf-gpu
    (tf-gpu) D:\&gt;
  10. After activating the environment, let’s install Tensorflow version 1.12 using PIP – Python package manager.
    (tf-gpu) D:\&gt;pip install --upgrade tensorflow-gpu==1.12.0
  11. Let’s verify the install.
    (tf-gpu) D:\&gt;python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"

    Sample output:

    (tf-gpu) D:\&gt;python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"
    2019-01-16 09:07:42.324696: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
    2019-01-16 09:07:43.288456: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 0 with properties:
    name: GeForce GTX 1050 major: 6 minor: 1 memoryClockRate(GHz): 1.493
    pciBusID: 0000:01:00.0
    totalMemory: 4.00GiB freeMemory: 3.30GiB
    2019-01-16 09:07:43.293825: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1511] Adding visible gpu devices: 0
    2019-01-16 09:07:45.237102: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix:
    2019-01-16 09:07:45.241664: I tensorflow/core/common_runtime/gpu/gpu_device.cc:988] 0
    2019-01-16 09:07:45.243892: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0: N
    2019-01-16 09:07:45.247982: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 3020 MB memory) -&gt; physical GPU (device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1)
    tf.Tensor(240.87163, shape=(), dtype=float32)
  12. Now, that Tensorflow is installed, we can now start our journey to machine learning –> deep neural network.
  13. If you don’t have a GPU that supports CUDA Deep Neural Network Library, skip 1, 2, 3, 4, 6 and replace 10 with
    (tf-gpu) D:\&amp;amp;gt;pip install --upgrade tensorflow==1.12.0

To avoid headaches in your setup, install the exact version specified in our ingredients. Been there, been that!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.