Setting Up A Deep Learning Workplace With An NVIDIA Graphics Card (GPU) - For Windows OS
Setting Up A Deep Learning Workplace With An NVIDIA Graphics Card (GPU) - For Windows OS
You have 1 free member-only story left this month. Sign up for Medium and get an extra one.
Member-only story
Listen Share
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 1/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
In our “Neural Networks and Deep Learning Course”, we’ll often use Keras and
TensorFlow libraries to do the programming part of deep learning models.
Before using any of these libraries, we need to set up our PC or laptop by installing
and configuring them on our system. Although these libraries can be installed on
different types of operating systems, today’s discussion is limited to the Windows
operating system. I also assume that you have a laptop or PC with the latest edition
of Windows installed.
How to install Keras and TensorFlow libraries with both CPU and GPU support
How to verify the installations so that you will not get any installation error
Keras and TensorFlow are Python-based libraries. Before installing any of them,
first, we need to install Python.
Step 2: Select the type of Anaconda installer that you’re looking for. For me, it’s
the 64-Bit Windows Graphical Installer.
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 2/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
Or the website will automatically detect the right installer for your PC or laptop as
follows.
Step 3: Either way, download the right installer and save the .exe file.
Step 4: Run the .exe file and follow the on-screen instructions to install the
software. The important thing is to keep the recommended settings and default
selections when you install Anaconda. Only change them if you know what
you’re doing!
After completing the setup, Python, data science-related libraries such as NumPy,
Pandas, Matplotlib, Scikit-learn, etc and the Anaconda Navigator will be installed on
your PC.
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 3/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
Step 5: To verify the Python installation, open the Anaconda Prompt, type
python and hit enter.
(Image by author)
Step 1: Open the Anaconda Navigator — A GUI included in Anaconda that allows
you to easily manage packages (libraries), environments, IDEs, etc.
(Image by author)
Step 3: Type the following command and hit enter to install both Keras and
TensorFlow. Since TensorFlow includes Keras, it’s not necessary to install Keras
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 4/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
separately. We only install TensorFlow and import Keras from TensorFlow! This
is the most recommend method when working with these two libraries.
(Image by author)
The above command will install the current stable release of TensorFlow and Keras
with both CPU and GPU support. As in older versions of TensorFlow, we do not need
to install separate packages for CPU and GPU. The pip installation includes both
CPU and GPU support but requires additional drivers and software to be configured
later (more on this shortly).
Step 4: To verify the installation, open a Python 3 Jupyter Notebook from the
Anaconda Navigator and execute the following commands.
To get the TensorFlow version, run the following two lines of code.
import tensorflow as tf
tf.__version__
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 5/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
To get GPU support with Keras and TensorFlow, we need to do some additional
configurations on our system. We need to download and install the following
software.
CUDA Toolkit
cuDNN SDK
By default, Keras and TensorFlow are looking for a GPU and if it is not available or
not configured, they will run on the CPU.
Only the NVIDIA GPUs are supported with TensorFlow and Keras. I repeat this. Only
the NVIDIA GPUs! Your NVIDIA GPU should also be CUDA-capable (more on this
shortly).
If you do not have an NVIDIA GPU, unfortunately, you cannot get GPU support with
Keras and TensorFlow. Therefore, you do not need to follow the below steps.
Alternatively, you can use Colab's free GPU!
Some deep learning models and tensors require a lot of computational power to execute.
This is because they have a vast amount of data and thousands of parameters. A CPU
cannot handle these types of resource-intensive tasks efficiently.
As data and model parameters increase, more computational power is required to train
the models. You should expect higher runtime for those models if you only use the CPU.
To overcome this, high-performance GPUs are available at an affordable cost. GPUs are
ideal for doing computations that involve a lot of data. GPUs are capable of executing
operations with lower runtime thanks to their higher number of cores.
Configuring the system to get GPU support for Keras and TensorFlow
Checking for a CUDA-capable NVIDIA GPU
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 6/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
CUDA (by NVIDIA) is the most popular platform for parallel computing and
programming. Almost all the GPU-supported Python libraries like CatBoost,
TensorFlow, Keras, PyTorch, OpenCV, and CuPy were designed to run on NVIDIA
CUDA-enabled graphics cards. That's why we’re searching for a CUDA-capable
NVIDIA GPU.
Step 1: Check whether there is any GPU and its part number if a GPU is
available. There are two ways to do it.
(Image by author)
Step 2: If you have an NVIDIA GPU, check for its CUDA compatibility by visiting
this website. Choose the correct section that matches your GPU part number.
For me, it is the “CUDA-Enabled GeForce and TITAN Products” section on the
website. If your GPU is listed in the table, it is CUDA-capable (Hint: Almost all
the recently-launched NVIDIA graphics cards should be CUDA capable).
If your graphics card is not CUDA capable, you do not need to follow the below
steps. Alternatively, you can use Colab’s free GPU!
Installing the GPU drivers
If you don’t have GPU drivers installed on your PC or laptop, you need to install the
correct driver through this website. If your GPU driver is already shown in the
Display Adaptors, you can skip this step.
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 7/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
Selecting the right driver for my NVIDIA GPU (Image from NVIDIA website, screenshot by author)
Selecting the right version for the CUDA Toolkit (Image from TensorFlow website, screenshot by author)
The most important thing is selecting the correct CUDA Toolkit version that
matches the installed Python and TensorFlow versions. We installed Python 3.9 and
TensorFlow 2.9.0. So, the correct CUDA Toolkit version is 11.2. At the time of writing
this tutorial, CUDA Toolkit version 11.7.0 (May 2022) is also available. You may
consider installing this newest version to get the latest features but you might get
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 8/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
compatibility issues because the newest version has not yet been fully tested with
Python 3.9 and TensorFlow 2.9.0.
Step 2: Go to this website to download the CUDA Toolkit. Select the version,
operating system type, architecture, operating system version and installer type.
Step 4: Run the .exe file and follow the on-screen instructions to install the
CUDA Toolkit. The important thing is to keep the recommended settings and
default selections when you install CUDA. Only change them if you know what
you’re doing!
(Image by author)
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 9/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
(Image by author)
(Image by author)
Step 1: Visit this website to see the cuDNN SDK version number that is compatible
with the installed Python and TensorFlow versions.
Selecting the right version for the cuDNN SDK (Image from TensorFlow website, screenshot by author)
The most important thing is selecting the correct cuDNN SDK version that matches
the installed Python, TensorFlow and CUDA Toolkit versions. We installed Python
3.9 and TensorFlow 2.9.0. So, the correct cuDNN SDK version is 8.1. At the time of
writing this tutorial, cuDNN SDK version 8.4.0 (April 2022) is also available for CUDA
Toolkit 11.x. You may consider installing this newest version to get the latest
features but you might get compatibility issues because the newest version has not
yet been fully tested with Python 3.9 and TensorFlow 2.9.0.
Step 2: Go to this website to download the cuDNN SDK. You should have an
account on NVIDIA to proceed. You will also need to fill out a small survey form
before downloading.
Step 4: Extract the .zip file and copy the following folders inside it.
(Image by author)
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 11/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
Step 5: Go the following path. Your path may vary depending on the architecture
and the version numbers of installed software. So, do not copy my path!
Step 6: Paste the copied folders. The system may ask to replace the files.
Step 7: Go to the bin folder and copy the path. Go to the libnvvp folder and copy
the path. Your paths may vary depending on the architecture and the version
numbers of installed software. So, do not copy my paths!
(Image by author)
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 12/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
(Image by author)
(Image by author)
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 13/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
(Image by author)
import tensorflow as tf
tf.test.gpu_device_name()
(Image by author)
import tensorflow as tf
tf.config.list_physical_devices('GPU')
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 14/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
(Image by author)
len(tf.config.list_physical_devices('GPU'))
Congratulations! TensorFlow has detected the NVIDIA GPU on your system. From
now on, Keras and TensorFlow will run on GPU by default.
import tensorflow as tf
tf.debugging.set_log_device_placement(True)
# Create some tensors
a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
c = tf.matmul(a, b)
print(c)
(Image by author)
To force TensorFlow or Keras to run on CPU, we can use with tf.device(): to create
a device context and put all the operations within that context.
import tensorflow as tf
tf.debugging.set_log_device_placement(True)
# Place tensors on the CPU
with tf.device('/device:CPU:0'):
a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
# Run on the GPU (default)
c = tf.matmul(a, b)
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 15/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
(Image by author)
The tensors a and b are not run on the GPU by default. They are run on the CPU.
I hope you enjoyed reading this article. If you’d like to support me as a writer, kindly
consider signing up for a membership to get unlimited access to Medium. It only costs $5
per month and I will receive a portion of your membership fee.
Thank you so much for your continuous support! See you in the next article. Happy
learning to everyone!
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 16/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
Don’t have a laptop or PC with an NVIDIA GPU? Don’t worry! Google Colab provides
you with free GPU resources.
How to Use Google Colab Free GPU to Run Deep Learning Code
Incredibly Faster
Neural Networks and Deep Learning Course: Part 13
rukshanpramoditha.medium.com
Choose the right laptop for data science, machine learning and deep learning tasks.
Rukshan Pramoditha
2022–05–23
Follow
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 17/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
2,000,000+ Views | BSc in Stats | Top 50 Data Science/AI/ML Writer on Medium | Sign up:
https://rukshanpramoditha.medium.com/membership
Rukshan Pramoditha
44 1
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 18/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
322 3
376 1
784 19
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 20/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
61
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 21/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
Determining the Right Batch Size for a Neural Network to Get Better and
Faster Results
Guidelines for choosing the right batch size to maintain optimal training speed and accuracy
while saving computer resources
38
Lists
AI Regulation
6 stories · 16 saves
ChatGPT
21 stories · 23 saves
ChatGPT prompts
17 stories · 62 saves
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 22/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
105
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 23/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
1.5K 18
62
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 24/25
06/07/23, 13:16 Setting up a Deep Learning Workplace with an NVIDIA Graphics Card (GPU) — for Windows OS | by Rukshan Pramoditha | D…
322 3
https://medium.com/data-science-365/setting-up-a-deep-learning-workplace-with-an-nvidia-graphics-card-gpu-for-windows-os-b6bff06eeec7 25/25