Install tensorflow-gpu and use it using Kernel in Jupyter

Sachinjose
3 min readAug 28, 2020

GPU’s are optimized for training artificial learning and deep learning models, as they can process multiple computations simultaneously. TensorFlow programs typically run significantly faster on a GPU than on a CPU.

So if you have a GPU, why not use it.

In the below tutorial, we will look into how we can create a separate environment to include our TensorFlow-gpu libraries and add a kernel in jupyter notebook to work on the environment.

Pre-requisites

  1. Windows 10 OS.
  2. Anaconda installed
  3. Machine with CUDA supported GPU: Check if your Nvidia in this list.

Tensorflow-GPU uses two software component from Nvidia to access Nvidia GPU. They are CUDA toolkit and cuDNN. If your GPU supports CUDA, then we shall be able to use it to do GPU accelerated TensorFlow.

Make sure the path for CUDA is included in environment variables.

SET PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin;%PATH%SET PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\extras\CUPTI\lib64;%PATH%SET PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include;%PATH%SET PATH=C:\tools\cuda\bin;%PATH%

Step 1: Create a Conda Environment

Open anaconda prompt

conda create -n your_env_name python=3.7

The above command will create an environment with python 3.7 pre-installed

To view a list of all environment in anaconda.

conda info --envs

To activate an environment in anaconda.

conda activate your_env_name

Step 2. Installing libraries in the environment

Once we have activated the environment, we can start installing the packages we need.

First, we look into how we can set a kernel in jupyter notebook.

pip install ipykernel

Let’s include kernel in the jupyter notebook

python -m ipykernel install --user --name your_env_name \              --display-name disp_name

Let’s install GPU version TensorFlow

conda install tensorflow-gpu

Let's install Jupyter notebook in our environment

conda install jupyter

Note: When installing all these libraries, make sure you have activated the environment and installing the libraries inside it.

Step 3: Working on the environment through the Kernel.

Open Jupyter notebook and select the kernel name, when opening a new notebook.

Step 4: Hello world program using TensorFlow.

Hello world for tensorflow

For detailed info about installing tensorflow-gpu, visit this site.

These steps will help you in experimenting with various versions of the same libraries in different separate environments without affecting your workspace.

Extra Stuff!

Removing the environment from anaconda

conda env remove -n ENV_NAME

To view the list of the kernel in the Jupyter notebook

jupyter kernelspec list

To delete the kernel use the below command.

jupyter kernelspec remove <kernel_name>

You can go ahead, create a separate environment with the specified version of libraries instead of installing all the dependent libraries again and again into the environment.

For creating anaconda environment using yml file, check this out

--

--