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.
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
Type y
when prompted. Let the installation complete the process.
Then, run this command to upgrade Pip:
sudo pip3 install ––upgrade pip
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
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.
Verify the installation was successful by checking the software package information:
pip3 show tensorflow
The system should display the TensorFlow version and other data.
For a shorter input, use this command:
pip list | grep tensorflow
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.
Verify the installation by displaying the package information:
pip3 show keras
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
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 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.