Install TensorFlow GPU with Jupiter notebook for Windows

conda install tensorflow gpu

Your system has NVIDIA GPU and you want to Install Tensorflow on your GPU machine to run Deep Learning Algorithms? In this tutorial, I will show you how to adequately use Conda to install TensorFlow GPU and integrate it with Jupyter notebook on your Windows computer.

Must Read:

Requirements

  • You must have NVIDIA graphics card in your system to install and use tensorflow-gpu in windows.
  • Your graphics card should be eligible for CUDA Toolkit framework (check this tutorial to understand eligibility)
  • You already have installed Anaconda for python in your system
  • You are using a Windows computer (because in this tutorial I will not guide you to install the TensorFlow library in other operating systems)

Steps to install Tensorflow on Windows

In this tutorial, I will show you the steps to install the latest Tensorflow version with GPU in windows using Anaconda. I will divide the entire process into some steps.

Note: At this point, I am assuming you have installed Anaconda and using it for python.

Step 1: Update NVIDIA GPU drivers

To use Tensorflow with GPU, your NVIDIA driver version must be 450.80.02 or higher. For proper installation of Tensorflow, I will recommend you update your GPU driver by this link.

You need to select the proper NVIDIA product and operating system you are using. In my case, I have NVIDIA GeForce GTX 1050 Ti and I want to install it for windows10.

update nvidia gpu driver

Once you select your specific product and model, click on Search button. A new page will open.

download nvidia gpu driver

Now click on Download button and install the downloaded NVIDIA driver file.

Also Read:  Extract Custom Keywords using NLTK POS tagger in python

After installation go to NVIDIA control panel and check your updated driver version. It should be 450.80.02 or higher. In my case version is 517.48 after the driver update.

check NVIDIA driver version

Step 2: Download & install Visual Studio

  • Download the Community edition Visual Studio, In my case, I have downloaded Visual Studio 2019: 
  • Check on “Desktop development with C++”, and Continue with defaults and click on install
Download and Install Visual Studio 19
Install Visual Studio 19

Step 3: Download and install CUDA Toolkit

So your driver is ready, now you need to install CUDA Toolkit. For this tutorial, I am going to download Cuda 11.2.0 for windows 10. You can try another version.

download and install cuda to install-tensorflow gpu
  • Once you downloaded, install CUDA (keep everything default)
  • Make sure your CUDA_PATH & CUDA_PATH_V11_2 is there, if not then add those paths
add cuda path for tensorflow gpu installation

Step 4: Download and install CuDNN library

Now you need to download and install CuDNN according to CUDA.

4.1: Download CuDNN for windows

To download cuDNN you have to register to the NVIDIA website, then you can download cuDNN:

Download and extract cuDNN (the version which corresponds to your suitable Cuda version).

I have downloaded CUDA 11.2 so I am going to download cuDNN 8.1.0

select cudnn version for installing tensorflow gpu with Jupyter notebook

Note: After clicking a particular version of cuDNN, It will open various cuDNN libraries for the different operating systems. I am using windows 10 so I am going to download the cuDNN Library for Windows.

download cudnn library for windows for tensorflow installation with GPU in windows

4.2: Install CuDNN for windows

  • Locate the CUDA installation folder, In my case: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2
  • Extract and open the downloaded cuDNN folder
  • Copy the below files from the cuDNN folder and paste them into the CUDA installation folder
    1. Copy all files (one file in my case) from the CuDNN bin folder and paste them inside CUDA (installation folder) bin folder
    2. Copy all files (one file in my case) from CuDNN include folder and paste them inside CUDA (installation folder) include folder
    3. Copy all files (one file in my case) from CuDNN lib/x64 folder and paste them inside CUDA (installation folder) lib/x64 folder
Also Read:  Learn CNN from scratch with Python and Numpy

By doing that we are done with the cuDNN installation.

Step 5: Create Virtual Environment

At this point, I am assuming you have successfully installed CUDA with the corresponding cuDNN library.

Now for TensorFlow GPU installation, I will recommend you create a virtual environment so that everything can be isolated and later you can try a different version of Tensorflow.

To do that run type the below command in cmd:

Note: I am going to create a virtual environment with the python 3.9 version.

conda create -n tf_gpu python=3.9
activate tf_gpu

Step 6: Install Tensorflow

Now just run the below command inside the newly created virtual environment.

  • The first command to upgrade pip installation is to be sure you’re running the latest version.
  • Second command for TensorFlow installation with pip
pip install --upgrade pip
pip install tensorflow

Note: Don’t get confused with the second command (pip install tensorflow). It will automatically check for CUDA and cuDNN compatibility. If it found the proper GPU setup in your system (which we have done in step 1 to step 4 ) then it will automatically install tensorflow-gpu else it will install the CPU version of Tensorflow.

Step 7: Verify Tensorflow GPU installation

Now let’s check if TensorFlow is using GPU. To do that run the below code one by one in the command line.

import tensorflow as tf
# how to check tensorflow version
tf.__version__
len(tf.config.list_physical_devices('GPU'))>0
how to check if tensorflow is using gpu

If you are getting output as “True” means TensorFlow is using GPU.

Step 8: Install TensorFlow in Jupyter notebook

So you have successfully installed TensorFlow with GPU configuration inside your virtual environment. Now to write any python code you need IDE like Jupyter notebook. But you will notice that while trying to check tensorflow gpu inside Jupyter you may get errors like:

modulenotfounderror: no module named 'tensorflow'

To solve the above error you need to run the below commands inside your virtual environment in cmd:

conda install jupyter
conda install nb_conda
conda install ipykernel

Once done, Jupyter notebook should use GPU backend for Tensorflow. You just need to select the proper virtual environ from kernel section in Jyoyter.

how to install tensorflow in jupyter notebook

Conclusion

In this article I have shown you:

  • How to install TensorFlow with the latest version for python 3.9
  • How to install TensorFlow in Jupiter notebook
  • How to check if TensorFlow is using gpu
Also Read:  Sentence Similarity Matching using Transformer

If you have any questions or suggestions regarding this tutorial, please let me know in the comment section.

3 thoughts on “Install TensorFlow GPU with Jupiter notebook for Windows”

  1. It is now 2023, and I will give a litle tip, that last version of tf that support natively GPU in Windows was 2.10
    so use:
    conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0
    # Anything above 2.10 is not supported on the GPU on Windows Native
    python -m pip install “tensorflow2.11 is supported on WLS2 on Ubuntu distribution or on Docker Images

    Reply

Leave a comment