Install TensorFlow-GPU 1.8 on Ubuntu 18.04

Updated on Mar 21,2024

Install TensorFlow-GPU 1.8 on Ubuntu 18.04

Table of Contents

  1. Introduction
  2. Installing TensorFlow 1.8 on Ubuntu 18.04
    • Step 1: Update GPU Driver
    • Step 2: Install CUDA Toolkit 9.0
    • Step 3: Update PATH Variable
    • Step 4: Install CUDA cuDNN 7.0.5
    • Step 5: Install TensorFlow GPU
    • Step 6: Test TensorFlow Installation
  3. Conclusion

Installing TensorFlow 1.8 on Ubuntu 18.04

In this Tutorial, we will walk you through the step-by-step guide to install TensorFlow 1.8 on Ubuntu 18.04. TensorFlow is a popular open-source machine learning framework developed by Google. It provides a comprehensive set of tools and libraries for building and deploying machine learning models. Installing TensorFlow with GPU support can significantly speed up the training process by utilizing the power of NVIDIA GPUs.

Step 1: Update GPU Driver

The first step is to update the GPU driver to ensure compatibility with TensorFlow. To do this, we will install the PPA Package and update the GPU driver. Open the terminal and run the following commands:

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
sudo apt install nvidia-390

Once the installation is complete, reboot your system to apply the changes. After the reboot, run the following command to verify that the GPU driver is installed correctly:

nvidia-smi

Step 2: Install CUDA Toolkit 9.0

Next, we need to install the CUDA Toolkit 9.0, which is required for TensorFlow 1.8. Download the CUDA Toolkit 9.0 base installer and the two patches from the NVIDIA website. Once the downloads are complete, open the terminal and navigate to the directory where the downloaded files are located. Run the following commands to install the CUDA Toolkit:

sudo dpkg -i cuda-repo-ubuntu1710_9.0.176-1_amd64.deb
sudo apt-key add /var/cuda-repo-<version>/7fa2af80.pub
sudo apt-get update
sudo apt-get install cuda

Step 3: Update PATH Variable

After installing the CUDA Toolkit, we need to update the PATH variable to include the necessary paths. Open the terminal and run the following command to edit the .bashrc file:

sudo nano ~/.bashrc

Scroll to the bottom of the file and add the following lines:

export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

Save the file and exit the text editor. Run the following command to update the PATH variable:

source ~/.bashrc

Step 4: Install CUDA cuDNN 7.0.5

Next, we need to install CUDA cuDNN 7.0.5, which is a GPU-accelerated deep neural network library. Download the cuDNN library from the NVIDIA website and extract the files. Open the terminal and navigate to the directory where the extracted files are located. Run the following commands to install cuDNN:

sudo cp cuda/include/cudnn.h /usr/local/cuda-9.0/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-9.0/lib64
sudo chmod a+r /usr/local/cuda-9.0/include/cudnn.h /usr/local/cuda-9.0/lib64/libcudnn*

Step 5: Install TensorFlow GPU

Now, we can finally install TensorFlow GPU using pip. Create a Conda environment with Python 3.6 and activate it by running the following commands:

conda create -n TF python=3.6
conda activate TF

Once the environment is activated, install TensorFlow GPU by running the following command:

pip install tensorflow-gpu==1.8

Wait for the installation to complete. Congratulations, you have successfully installed TensorFlow GPU on Ubuntu 18.04!

Step 6: Test TensorFlow Installation

To test if TensorFlow is working correctly, open a new Python interpreter and import TensorFlow:

import tensorflow as tf

If there are no errors, TensorFlow is installed successfully. You can check the TensorFlow version by running the following command:

print(tf.__version__)

To verify that TensorFlow is using the GPU for computations, run the following code:

hello = tf.constant("Hello, TensorFlow!")
sess = tf.Session()
print(sess.run(hello))

If everything is set up correctly, you should see the following output:

b'Hello, TensorFlow!'

Congratulations! You have successfully installed TensorFlow 1.8 with GPU support on Ubuntu 18.04 and tested its functionality.

Conclusion

In this tutorial, we have covered the step-by-step process of installing TensorFlow 1.8 with GPU support on Ubuntu 18.04. We started by updating the GPU driver, followed by the installation of CUDA Toolkit 9.0, cuDNN 7.0.5, and finally TensorFlow GPU. Now, you can take advantage of the power of your NVIDIA GPU for training machine learning models using TensorFlow. If you encounter any issues or have any questions, feel free to leave a comment below. Happy deep learning!


Highlights:

  • Install TensorFlow 1.8 on Ubuntu 18.04 with GPU support
  • Update the GPU driver and install CUDA Toolkit 9.0
  • Set up the necessary paths for CUDA and cuDNN
  • Create a Conda environment and install TensorFlow GPU
  • Test the TensorFlow installation with GPU acceleration

FAQ:

Q: Can I install TensorFlow GPU on a different Linux distribution? A: While this tutorial focuses on Ubuntu 18.04, the installation steps should be similar for other Linux distributions. However, make sure to check the specific requirements and compatibility of the CUDA Toolkit and cuDNN for your distribution.

Q: Do I need an NVIDIA GPU to install TensorFlow GPU? A: Yes, TensorFlow GPU requires an NVIDIA GPU with a compute capability of 3.0 or higher. You can refer to the official NVIDIA website for a list of supported GPUs.

Q: Can I use a different version of TensorFlow or CUDA Toolkit? A: The tutorial covers the installation of TensorFlow 1.8 with CUDA Toolkit 9.0, as they are compatible with each other. However, you can explore using different versions of TensorFlow or CUDA Toolkit based on your specific requirements. Make sure to check the compatibility and requirements for your chosen versions.

Most people like