How to test your Keras, CUDA, CuDNN, and TensorFlow install

Setting up TensorFlow, Keras, CUDA, and CuDNN can be a painful experience on Ubuntu 20.04. Here is the combination of packages that worked for me.

How to test your Keras, CUDA, CuDNN, and TensorFlow install
4 minutes to read

Despite having been a Linux user for about 20 years, there are times when I find I have wasted days trying to solve a seemingly simple problem. One such issue that seems to be hampering many data scientists at present is getting CUDA, CuDNN, Keras and TensorFlow up and running correctly on Ubuntu 20.04.

NVIDIA produce many fantastic things for the data science community, but unfortunately, getting them all to work together can sometimes be a challenge. It’s a shame that NVIDIA don’t produce a custom Ubuntu spin containing everything pre-configured so it just works.

I experienced a raft of issues trying to get everything work together. When I eventually did get my setup working, the NVIDIA graphics card driver decided to send a signal to only one display from my two GeForce GTX 690 graphics cards (packing around 6000 CUDA cores between them). Switching to a newer GeForce RTX 2060 solved my problems, so perhaps much of my bad luck can be attributed to using older (but still very capable) graphics cards.

Here are the software versions that worked for me, plus a series of commands you can run in a Jupyter Notebook or your terminal to confirm that your machine is correctly configured.

My data science workstation

  • Ryzen 3700X (overclocked to 4.3GHz)
  • 64GB of G.Skill Trident Z 3200 MHz RAM
  • 1TB M.2 NVME SSD
  • NVIDIA GeForce RTX 2060 graphics card

My software setup

  • Ubuntu 20.04.1
  • Python 3.8.3
  • NVIDIA CUDA compilation tools 10.1 v10.1.243
  • NVIDIA-SMI 450.51.06 graphics card driver, CUDA version 11.0
  • CuDNN 7.6.5
  • TensorFlow GPU 2.3.0
  • Keras 2.3.1

Testing your software setup

To check all of the version numbers you’ve got installed, you can run a series of commands on Ubuntu via the terminal to get some useful diagnostic data back.

Python version

!python --version
Python 3.8.3

NVIDIA CUDA compiler driver

!nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243

NVIDIA graphics card driver and CUDA version

Wed Aug 12 20:48:34 2020       
| NVIDIA-SMI 450.51.06    Driver Version: 450.51.06    CUDA Version: 11.0     |
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|   0  GeForce RTX 2060    On   | 00000000:26:00.0  On |                  N/A |
|  0%   45C    P5    14W / 170W |    437MiB /  5931MiB |     27%      Default |
|                               |                      |                  N/A |

| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|    0   N/A  N/A      1600      G   /usr/lib/xorg/Xorg                 59MiB |
|    0   N/A  N/A      2175      G   /usr/lib/xorg/Xorg                145MiB |
|    0   N/A  N/A      2380      G   /usr/bin/gnome-shell              112MiB |
|    0   N/A  N/A      3594      G   ...AAAAAAAAA= --shared-files      104MiB |

CUDA install path

!whereis cuda
cuda: /usr/local/cuda

CuDNN version and patch level

!cat /usr/include/cudnn.h | grep CUDNN_MAJOR -A 2
#define CUDNN_MAJOR 7
#define CUDNN_MINOR 6

#include "driver_types.h"

TensorFlow version

Running the below command will import TensorFlow and return the version number, if it has been installed correctly.

!pip list | grep tensorflow
tensorflow-estimator               2.3.0
tensorflow-gpu                     2.3.0

Keras version

!pip list | grep Keras
Keras                              2.3.1
Keras-Applications                 1.0.8
Keras-Preprocessing                1.1.2

TensorFlow GPU configuration

import tensorflow as tf

List TensorFlow GPUs

import tensorflow as tf
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
## Print TensorFlow version
import tensorflow as tf

Matt Clarke, Tuesday, March 02, 2021

Matt Clarke Matt is an Ecommerce and Marketing Director who uses data science to help in his work. Matt has a Master's degree in Internet Retailing (plus two other Master's degrees in different fields) and specialises in the technical side of ecommerce and marketing.