BOOTLEGSOFT
Published in

BOOTLEGSOFT

Installing Tensorflow GPU on Ubuntu 20.04, This Is the Way

This guide is the best way to install Tensorflow GPU when other methods are not successful on my Ubuntu 20.04 machine.

  1. Removing the old package.
sudo apt-get clean
sudo apt-get update
sudo apt-get purge cuda
sudo apt-get purge nvidia-*
sudo apt-get autoremove

2. Install Nvidia package repositories

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pinsudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pubsudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"sudo apt-get update

3. Install Nvidia cudnn package repositories

wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu2004/x86_64/nvidia-machine-learning-repo-ubuntu2004_1.0.0-1_amd64.deb

sudo apt install ./nvidia-machine-learning-repo-ubuntu2004_1.0.0-1_amd64.deb
sudo apt-get update

4. Install Nvidia cuda and cudnn

sudo apt-get install cuda-11-2 nvidia-cuda-toolkit libcudnn8 libcudnn8-devsudo reboot # Reboot your machine

5. Install the Tensorflow on the system Python3.8 from Ubuntu

sudo apt install python3 python3-pipsudo pip3 install tensorflow

6. Test in Python

python3 -c 'import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices("GPU")))'

The result should be like this:

If found error “Failed to call ThenRnnBackward with model config” use this code to allow memory growth.

gpu_devices = tf.config.experimental.list_physical_devices('GPU')
for device in gpu_devices:
tf.config.experimental.set_memory_growth(device, True)

--

--

--

Handcrafted Software and Innovation.

Recommended from Medium

My First Experience as a Lecturer

Machine Learning Models

Finding image pathways

History of the Neural Networks — Part 2

Remove 1 or multiple Column in Pytorch Tensor

Image Captioning With Flickr8k Dataset & BLEU

LSTM-FCN for cardiology

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Artiya

Artiya

Programmer • Innovator • Photographer https://www.buymeacoffee.com/artiya4u

More from Medium

Nexus: Using Machine Learning to Label Abstract Art

Recognize Volleyball Game Stages with Machine Learning

I Walk so Randomly on the Boulevard of Broken Links: Random Walks and Node Embeddings

Intelligent automation: when RPA meets AI

Intelligent automation masterclass