Introduction to Keras — Deep Learning Library

Source: Deep Learning on Medium

Introduction to Keras — Deep Learning Library

What You Will Learn?

  • Introduction to Keras
  • Example Code, explaining Keras

Introduction to Keras

Keras is a deep learning framework for Python that provides a convenient way to define and train almost any kind of deep learning model. Keras is a high-level neural networks API, written in Python which is capable of running on top of Tensorflow, Theano and CNTK. It was developed for enabling fast experimentation.

Being able to go from idea to result with the least possible delay is key to doing good research.

Keras has the following features :

  • Allows for easy and fast prototyping
  • Run seamlessly on CPU and GPU
  • Supports both convolutional networks(for computer vision) and recurrent networks(for sequence and time-series), as well as the combination of two.
  • It supports arbitrary network architectures: multi-input or multi-output models, layer sharing, model sharing and so on. This means Keras is appropriate for building deep learning models, from generative adversarial networks to a neural Turing machine.

Keras is compatible with versions of Python from 2.7 to 3.6 till date.

Keras is used by around 200,000 users, ranging from academic researchers and engineers at both startups and large companies to graduate students and hobbyist. Keras is used at Google, Netflix, Uber, Microsoft, Square and many startups working on the wide variety of machine learning problems.

Deep Learning Book by Francois cholloet

Keras recommend users to switch to tf.keras in Tensorflow 2.0, who use multi-backend keras with the tensorflow backend.

Guiding principles

  • User Friendliness
  • Modularity
  • Easy Extensibility
  • Work with Python

Keras doesn’t handle low-level operations such as tensor manipulations and differentiation. Instead, it relies on a specialized, well-optimized tensor library to do so which serves as the backend engine of Keras. We can use several backend engine for keras, and currently three existing backend implementations are the Tensorflow backend, the Theano backend, and the Microsoft Cognitive Toolkit (CNTK) backend.

Example Code, explaining Keras

Install Keras

pip install keras

The typical Keras workflows looks like:

  • Define your training data: input tensor and target tensor
  • Define a network of layers(or model ) that maps input to our targets.
  • Configure the learning process by choosing a loss function, an optimizer, and some metrics to monitor.
  • Iterate your training data by calling the fit() method of your model.

You can define your model in two ways :

  • Sequential Class: Linear Stack of layers

<script src=”https://gist.github.com/patidarparas13/406b30136c9ea5afff93db69fd0e890e.js“></script>

  • Functional API: Directed acyclic graphs of layers

<script src=”https://gist.github.com/patidarparas13/f2f115ad0d7cf82b54be5b2d95166057.js“></script>

Implementing Loss Functiom, Optimizer and Metrics

<script src=”https://gist.github.com/patidarparas13/c5cc9f5863613293e7128a5b922be4de.js“></script>

Finally, passing input and target tensors

<script src=”https://gist.github.com/patidarparas13/a5e817e4b21166de5a7e5be4c1cf8563.js“></script>

This is the basic overview of keras and we will be making more tutorials on keras. Want to learn about neural networks ? , check this article :

Thank You!

Stay Tuned & Stay Connected with #MLAIT

Follow Us for more tutorials on ML, AI and Cloud