Overview of Some Deep Learning Libraries

[ad_1]

Last Updated on June 26, 2022

Machine learning is a broad topic. Deep learning, in particular, is a way of using neural networks for machine learning. Neural network is probably a concept older than machine learning, dated back to 1950s. Unsurprisingly, there were many libraries created for it.

In the following, we will give an overview of some of the famous libraries for neural network and deep learning.

After finishing this tutorial, you will learn

  • Some of the deep learning or neural network libraries
  • The functional difference between two common libraries, PyTorch and TensorFlow

Let’s get started.

Overview of Some Deep Learning Libraries
Photo by Francesco Ungaro. Some rights reserved.

Overview

This tutorial is in three parts, they are

  • The C++ Libraries
  • Python Libraries
  • PyTorch and TensorFlow

The C++ Libraries

Deep learning gained attention in the last decade. Before that, we were not confident on how to train a neural network with many layers. However, the understanding on how to build a multilayer perceptrons was around for many years.

Before we have deep learning, probably the most famous neural network library is libann. It is a library for C++ and the functionality is limited due to its age. This library has stopped development. A newer library for C++ is OpenNN. It allows modern C++ syntax.

But that’s pretty much all for C++. The rigid syntax of C++ may be the reason we do not have too many libraries for deep learning. The training phase of deep learning project is about experiments. We would like some tools that allows us to iterate faster. Hence a dynamic programming language could be a better fit. Therefore, you will see Python comes on the scene.

Python Libraries

One of the earliest library for deep learning is Caffe. It is developed in U.C. Berkeley and specifically for computer vision problems. While it is developed in C++, it is served as a library with a Python interface. Hence we can build our project in Python with the network defined in a JSON-like syntax.

Chainer is another library in Python. It is an influential one because the syntax makes a lot of sense. While it is less common nowadays, the API in Keras and PyTorch bears resemblence to Chainer. The following is an example from Chainer’s documentation and you may mistaken it as Keras or PyTorch:

The other obsoleted library is Theano. It has ceased development but once upon a time it is a major library for deep learning. In fact, the earlier version of Keras library allows to choose between Theano or TensorFlow backend. Indeed, neither Theano nor TensorFlow are deep learning libraries precisely. Rather, they are tensor libraries that make matrix operations and differentiation handy, which deep learning operations can be built upon. Hence these two are considered replacement from each other from Keras’ perspective.

CNTK from Microsoft and Apache MXNet are the two other libraries that worth to mention. They are large with interface for multiple languages. Python, of course, is one of them. CNTK has C# and C++ interfaces while MXNet provides interfaces for Java, Scala, R, Julia, C++, Clojure, and Perl. But recently, Microsoft decided to stop developing CNTK. But MXNet does have some momentum and it is probably the most popular library after TensorFlow and PyTorch.

Below is an example of using MXNet via the R interface. Conceptually, you see the syntax similar to Keras functional API:

PyTorch and TensorFlow

PyTorch and TensorFlow are the two major libraries nowadays. In the past when TensorFlow was in version 1.x, they are vastly different. But as TensorFlow absorbed Keras as part of its library, these two library are working similarly most of the time.

PyTorch is backed by Facebook and its syntax is stable over the years. There are also a lot of existing models that we can borrow. The common way of defining a deep learning model in PyTorch is to create a class:

but there are also a sequential syntax to makes the code more concise:

TensorFlow in version 2.x adopted Keras as part of its libraries. In the past, these two are separate projects. In TensorFlow 1.x, we need to build a computation graph, set up a session, and derive gradients from a session for the deep learning model. Hence it is a bit too verbose. Keras is designed as a library to hide all these low level details.

The same network as above can be produced by TensorFlow’s Keras syntax as follows:

One major difference between PyTorch and Keras syntax is on the training loop. In Keras, we just need to assign the loss function, the optimization algorithm, the dataset, and some other parameters to the model. Then we have a fit() function to do all the training work, as follows:

But in PyTorch, we need to write our own training loop code:

This may not be an issue if you’re experimenting a new design of network which you want to have more control on how the loss is calculated and how the optimizer updates the model weights. But otherwise, you would appreciate the simpler syntax from Keras.

Note that, both PyTorch and TensorFlow are libraries with Python interface. Therefore, it is possible to have interface for other languages too. For example, there are Torch for R and TensorFlow for R.

Also note that, the libraries we mentioned above are full-featured libraries that includes training and prediction. If we consider a production environment where we make use of a trained model, there could be wider choice. TensorFlow has a “TensorFlow Lite” counterpart that allows a trained model to be run in mobile or on the web. Intel also has a OpenVINO library that aims at optimizing the performance in prediction.

Further Reading

Below are the links to the libraries we mentioned above:

Summary

In this post you discovered various deep learning libraries and some of their characteristics. Specifically, you learned:

  • What are the libraries available for C++ and Python
  • How the Chainer library influenced the syntax in building a deep learning model nowadays
  • The relationship between Keras and TensorFlow 2.x
  • What are the difference between PyTorch and TensorFlow

Develop Deep Learning Projects with Python!

Deep Learning with Python

 What If You Could Develop A Network in Minutes

…with just a few lines of Python

Discover how in my new Ebook:

Deep Learning With Python

It covers end-to-end projects on topics like:

Multilayer PerceptronsConvolutional Nets and Recurrent Neural Nets, and more…

Finally Bring Deep Learning To

Your Own Projects

Skip the Academics. Just Results.

See What’s Inside

[ad_2]

Image and article originally from machinelearningmastery.com. Read the original article here.