Friday, July 5, 2024
HomeTutorialsHow to Install Keras With TensorFlow Backend on Linux

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 LinuxArticle 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 CentOSInstalling 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 CentOSPIP 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 CentOSInstalling 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 CentOSTensorFlow 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 TerminalTensorFlow version in CentOS Terminal

For a shorter input, use this command:

pip list | grep tensorflow
Show tensorflow version using pip and grep commandShow 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 terminalCentOS Keras installation process in the terminal

Verify the installation by displaying the package information:

pip3 show keras
Showing Keras version in the terminalShowing 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 packageTerminal 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 confirmationKeras 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

Nango Kalahttps://www.kala.co.za
Experienced Support Engineer with a demonstrated history of working in the information technology and services industry. Skilled in Microsoft Excel, Customer Service, Microsoft Word, Technical Support, and Microsoft Office. Strong information technology professional with a Microsoft Certificate Solutions Expert (Privet Cloud) focused in Information Technology from Broadband Collage Of Technology.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments