Getting Started with Keras

In this tutorial, we will learn the basics of the Deep Learning framework – Keras. This tutorial will cover the whole introduction of Keras and it’s functions.

Intuition will be provided on the installation of Keras and its modules and built-in datasets.

There will be three sections in this tutorial:

  1. Introduction
  2. Installation
  3. Features provided – in which we will be seeing modules and datasets and one example of each topic.

KERAS – A Deep Learning Python Framework

1. INTRODUCTION

Deep learning is one of the most sought after fields in Machine learning or the Artificial Intelligence domain. And for creating Deep Neural Networks we need a framework because implementing it from scratch using python and numpy will be very tiresome and it’s not practical to implement very large models like Convolution Neural Networks or Recurring Neural Networks.

Keras is one of those high-level neural network frameworks. This API is written in python and it supports multiple backend engines. It is easy to understand and user-friendly. This was designed for human beings and not machines. Its main author is a Google Engineer, Mr. Francois Chollet.

It can be integrated to at least five backend engines which are :

  • Tensorflow
  • CNTK (Microsoft Cognitive Toolkit)
  • Theano
  • MXNet
  • PlaidML
    while Tensorflow being the primary backend engine.

2. INSTALLATION

Before installing Keras, we need to make sure that we have installed python in our machines.

For installing Python, click the below link :

https://www.python.org/downloads/

For installing Keras :

pip install keras

Or you can install Tensorflow:

pip install tensorflow

3. FEATURES PROVIDED

MODULES:

These are the modules that are present in the Keras API :

  • Initializers
  • Regularizers
  • Constraints
  • Activations
  • Losses
  • Metrics
  • Optimizers
  • Callback
  • Text Processing
  • image Processing
  • Sequence Processing
  • Backend
  • Utilities

If we don’t use Keras API, we would need to write code for every other module which is very time consuming and also a complex process.

Here’s an example of using the backend module:

First, we need to import the backend module from the keras library.

from keras import backend as back

Now, let’s use a function from the backend module which is dot() function.

a = back.placeholder(shape = (4,2)) 
b = back.placeholder(shape = (2,3)) 
c = back.dot(a,b)
print(c)

This will give us the output:

Tensor("MatMul_2:0", shape=(4, 3), dtype=float32)

Thus, we have created a vector c which is the product of a and b.

DATASETS:

Apart from these above modules, Keras also provides a few datasets such as the MNIST digits dataset, IMDB movie review sentiment classification dataset, etc.

Here’s an example of loading MNIST dataset:

First, we need to import the mnist module from Keras library.

from keras.datasets import mnist

After this, we need to divide the data into training and testing sets.

(X_train, y_train), (X_test, y_test) = mnist.load_data()

And now to look at the shape of the dataset:

print(X_train.shape)
print(y_train.shape)
print(X_test.shape)
print(y_test.shape)

This will give us the shape of the dataset as follows:

(60000, 28, 28)
(60000,)
(10000, 28, 28)
(10000,)

For further information on Keras documentation, you can click here.

Also, you may visit:

Assigning a value to a TensorFlow variable in Python

Thank you for reaching till here.

 

Leave a Reply

Your email address will not be published.