How to Install Keras With TensorFlow Backend on Linux

Introduction

Keras is a neural network library based on the Python programming language designed to simplify machine-learning applications. Keras runs on top of frameworks such as TensorFlow.

In this guide, learn how to install Keras and Tensorflow on a Linux system.

Article on how to install Keras on Linux

Prerequisites

  • A Linux machine with access to a command-line/terminal
  • A user account with sudo or root privileges
  • The Python 3.5 – 3.8 development environment
  • The Python3-pip package manager

How to Install Keras on Linux

Keras is built to work with many different machine learning frameworks, such as TensorFlow, Theano, R, PlaidML, and Microsoft Cognitive Toolkit. However, the best framework to use with Keras is TensorFlow.

This article will cover installing TensorFlow as well.

STEP 1: Install and Update Python3 and Pip

Skip this step if you already have Python3 and Pip on your machine.

If not, open the terminal and enter the following command, depending on your Linux distribution:

CentOS / RedHat:

sudo yum install python3 python3-pip
Installing python3 in the terminal on CentOS

Type y when prompted. Let the installation complete the process.

Then, run this command to upgrade Pip:

sudo pip3 install ––upgrade pip
PIP upgrade on CentOS

Ubuntu / Debian:

The process for these distributions is similar:

sudo apt install python3 python3.pip
sudo pip3 install ––upgrade pip

Note: If Python 3 or Pip is already available, the system reports that there are no further changes.

STEP 2: Upgrade Setuptools

To upgrade setuptools, enter the following:

pip3 install ––upgrade setuptools
Installing setuptools on CentOS

Without this step, you may receive errors about certain packages requiring a different setuptools version than the one you have on your system.

STEP 3: Install TensorFlow

The TensorFlow installation is straightforward. Use Pip and this command to install it::

pip3 install tensorflow

Let the download and installation finish.

TensorFlow installation and downloading process in CentOS

Verify the installation was successful by checking the software package information:

pip3 show tensorflow

The system should display the TensorFlow version and other data.

TensorFlow version in CentOS Terminal

For a shorter input, use this command:

pip list | grep tensorflow
Show tensorflow version using pip and grep command

Note: If you encounter any issues, refer to our guides on how to install TensorFlow on Ubuntu and how to install TensorFlow on CentOS.

STEP 4: Install Keras

Finally, install Keras with the following command:

pip3 install keras

The terminal shows the confirmation message once the process completes.

CentOS Keras installation process in the terminal

Verify the installation by displaying the package information:

pip3 show keras
Showing Keras version in the terminal

STEP 5: Install Keras from Git Clone (Optional)

If you have Git on your system, you can use it to clone a copy of the Keras software package from GitHub.

Note: When Git is not installed, the operating system prompts you to install it before cloning from the Keras GitHub repository. Depending on your system’s OS, use one of our guides How to Install Git on Ubuntu, How to Install Git on CentOS 7, or How to Install Git on CentOS 8.

To clone the Keras package from GitHub, enter the following:

git clone https://github.com/keras-team/keras.git
Terminal cloning a copy of the Keras software package

Once the download completes, switch to the /keras directory:

cd keras

From there, run the Keras python installer:

sudo python3 setup.py install

The output shows the confirmation when the process completes:

Keras Git install confirmation

Keras vs. TensorFlow

Keras and TensorFlow are both open-source software. TensorFlow is a software library for machine learning. Keras runs on top of TensorFlow and expands the capabilities of the base machine-learning software. Keras also makes implementation, testing, and usage more user-friendly.

Keras works with TensorFlow to provide an interface in the Python programming language. It works by using layers and models.

Note: Martin Wielomski, Director of Products at phoenixNAP, explains how GPUs power Machine Learning and AI.

Layers

A layer is a processing unit. It accepts input, performs computations on that input, then outputs the transformed information.

A layer requires the following:

  • Shape of input: Defines how the layer will make sense of the input information
  • Initializer: Sets the weight, or importance, of each piece of information.
  • Activator: Transforms the data into a non-linear form.

Models

A model is a group of layers. A model also includes training and inference modules – this is where machine learning comes into play. Each model has the following:

  • Inputs: Scripts that send information into the Keras model.
  • Outputs: The information that comes out after being transformed by the Keras model.
  • Type: A model may be sequential, meaning that it is built one layer at a time to solve a problem. Or, it can be functional, where layers may interconnect in complex and non-linear ways.

Conclusion

By following the steps in this tutorial, you should have successfully installed Keras and Tensorflow on a Linux system with the necessary Python packages.

Next, you may be interested in learning why GPUs are used for Deep Learning algorithms.

Was this article helpful?
YesNo
Goran Jevtic
Goran combines his leadership skills and passion for research, writing, and technology as a Technical Writing Team Lead at phoenixNAP. Working with multiple departments and on various projects, he has developed an extraordinary understanding of cloud and virtualization technology trends and best practices.
Next you should read
Hadoop vs Spark - Detailed Comparison
June 4, 2020

This article explains how Hadoop and Spark are different in multiple categories. The tools are both free, but...
Read more
How to Install Spark on Ubuntu
October 10, 2024

This Spark tutorial shows how to get started with Spark. The guide covers the procedure for installing Java...
Read more
How to Install TensorFlow GPU on Ubuntu 18.04
August 29, 2024

Designed to simplify the process of implementing machine-learning models, TensorFlow is Google's open-source...
Read more
How to Install and Use TensorFlow on CentOS 7
October 8, 2019

TensorFlow is Google's open-source platform for machine learning. It was designed to simplify the process of...
Read more