Install Tensorflow with GPU support for Deep Learning on Windows 10

Hemanthhari2000
featurepreneur
Published in
6 min readMar 22, 2021

Prepare your PC to run Deep Learning algorithms on GPU.

Introduction

Deep Learning is a booming technology and an advancement in the field of Artificial Intelligence (AI). Deep Learning is solving countless problems, especially in the healthcare and agriculture sectors. The accuracies are off the charts and it is hoped to be the next big thing. They are used to classify different types of cancer cells just by looking at an image with high accuracy. They are used everywhere and even as I write this article deep learning is helping me to write proper sentences and is checking for any spelling mistakes and so.

But, to get such accuracies we need to train the algorithm for multiple epochs. This will cause more load on the CPU of the system. What if we use a GPU instead of a CPU? How can you set such a setup? Let’s see the installation of TensorFlow with the required software and packages to train our model on GPU rather than on the CPU.

Overview

Let’s take a look at the contents that we will cover in this article.

  • Prerequisites
  • Installing Microsoft Visual Studio
  • Installing NVIDIA CUDA ToolKit
  • Installing NVIDIA CuDNN
  • Setting up Environment Path
  • Testing TensorFlow with GPU
  • Conclusion

Prerequisites

All you need prior to set up TensorFlow GPU are

  • Python (latest recommended)
  • Anaconda or miniconda (latest)

That’s enough for now. We need Anaconda for creating an environment and handling packages easily. So, I chose Anaconda. You can also go with miniconda if you want.

Installing Microsoft Visual Studio

The very first thing you need to do is install Microsoft Visual Studio from their official download page. Download it from here. Make sure you download the community version. Now, go ahead and install it.

When you install Microsoft Visual Studio make sure that you select the following C++ distributions.

after selecting the following C++ distributions click install.

Note: This might take some time as it installs a very large package which is greater than 10 GB so take a break and have some TEA….

Installing NVIDIA CUDA ToolKit

Based on your GPU (GTX 1650, GTX 1660ti and so) you can select your NVIDIA CUDA ToolKit from the official website here. For higher-end GPUs, a CUDA version greater than 10.0 is recommended. Test your CUDA toolkit version with your GPU.

In my case for GTX 1650, CUDA ToolKit 10.0 was perfect. Make sure you download the right ToolKit version. If you have finalized the version then go ahead and hit that download button and let it download.

After selecting the specifications and when you click exe(local) as the Installer Type you will something like this below from where you can download the ToolKit.

As soon as you click the Download button the ToolKit will start installing and you can move forward to the next requirement.

Installing NVIDIA CuDNN

Alright, the next thing to download is a very important one that is NVIDIA’s CuDNN library. The NVIDIA CUDA® Deep Neural Network library (cuDNN) is a GPU-accelerated library of primitives for deep neural networks.cuDNN provides highly tuned implementations for standard routines such as forward and backward convolution, pooling, normalization, and activation layers.

So, it is important to have it in your system when you perform Deep Learning tasks. Go to the official NVIDIA’s CuDNN page from here.

Note: You need to sign in to the NVIDIA account to download the CuDNN library. Make sure you do that.

Install the required CuDNN based on the CUDA ToolKit you have selected and downloaded.

Download the required CuDNN library for Windows 10.

and that’s it, You have downloaded all the required libraries for your TensorFlow GPU setup. Now, we just need to set up all the libraries and make our deep learning algorithm run on the PC.

Setting up your Environment Path

Before, you edit your system environment variables you need to extract the CuDNN library that you have just downloaded. you will see a file called cuda, copy that folder and paste it in your C: Drive.

Note: You can extract the CuDNN and place it in any Drive you need. C: Drive is recommended.

Now, you need to open your edit your system environment variables and edit your system path. Go and select the path under the system variables tab and click on edit to edit the path. If you have placed the extracted CuDNN’s cuda folder in C: Drive then your system variables path should look like this.

C:\cuda\bin
C:\cuda\include
C:\cuda\lib\x64

Pheewww…. That’s it, we are done with setting up the system variables. Now we need to create a new anaconda environment and test our TensorFlow GPU whether the connection was successful or not.

Testing TensorFlow with GPU

Alright... Alright... Alright (Matthew McConaughey reference tho…) It’s time to test our TensorFlow with GPU. So, open your anaconda prompt and create a new environment using the following command.

conda create -n TensorFlow_GPU_Test python=3.7

After creating your environment, go ahead and activate your environment using the following command.

conda activate TensorFlow_GPU_Test

then, type the following command to install TensorFlow-GPU version 2.0.0

pip install tensorflow-gpu==2.0.0

That’s it. Now, it is the moment of TRUTH…

type python and enter into python interpreter mode. Import TensorFlow and start testing the following commands

import tensorflow as tf
print(tf.test.is_gpu_available())
print(tf.test.is_built_with_cuda())

This should give you the following result as TRUE. like this

If you followed all the steps discussed above then you will get an output that is very similar to what you see above.

Note: Based on your GPU your output may change like the name of the GPU and the ClockRate of it and so.

Conclusion

In this article, we have seen a detailed intro about deep learning package installations and installing some of the libraries that TensorFlow needs to run the Deep Learning algorithm on GPU. We have gone through each process step by step. I hope this article was useful to you all and I hope you all get the output as TRUE as I did. Will see you in my next article until then as always code learn repeat …….

Follow for more…

--

--