Which Deep Learning Library to Choose | Keras vs. Tensorflow vs. Others

If you ever ventured into the world of Deep Learning, you might have gotten stuck where many other people do: Which technology do I use?

We have quite a few options of deep learning APIs but not all are suitable for first-time users. The thing about the Deep Learning API scene is that it is highly curated for researchers still. So finding a suitable framework to use can be a bit trickier than expected.

If you ever looked for the possible APIs you can use, chances are you heard these ones:

  • Theano
  • PyTorch
  • Tensorflow
  • Keras

Let’s look into them one by one and decide on which one to use.

Theano is a low level API that helps you efficiently do multi-dimensional calculations. Thanks to its being low level, it is quite fast and is good at handling very large datasets. The downside for a beginner is that you need to build the algorithms from scratch. You only get the simplest components with Theano. You need to code all of the calculations yourself. So it will be equal to writing the decision tree algorithm from scratch using Python instead of calling sklearn.tree.DecisionTreeClassifier() in one line. You will need this library only if you are building an algorithm that behaves significantly different than the default ones found in other higher-level libraries. That’s why it’s mostly used by researchers when building a new type of algorithm or when they need to make their model quite fast and efficient.

PyTorch is an API that was developed by Facebook. It is easier to use than Theano but it’s still a low-level API that requires a complete understanding of all the processes that are happening under the hood to be able to build a deep learning model. PyTorch is also highly preferred by researchers.

Tensorflow is basically a math library developed by Google that can be used for machine learning. It offers both high-level and low-level APIs. It offers users multiple levels of abstraction so you can go lower or higher level as you need. It is not known for its ease of use. The architecture of models can get quite complicated and it’s not very easy to debug it. That’s why it’s not a great starting point for beginners.

Keras is my weapon of choice. It is an API that wraps around a bunch of different lower-level libraries. These can be Tensorflow, Theano or the Microsoft CNTK (Tensorflow is a common choice for this.). In Keras, many high-level components you would need are pre-made and you can call them with one line. Some examples are hidden layers, input/output layers, RNN layers or even batch normalization layers. Keras will let you build and train deep learning algorithms simply by adding these layers on top of each other. You don’t need to manually code any of the calculations. All that is needed is to determine the architecture of the model and provide the hyperparameters. This way, it helps you build, train and evaluate your model quickly. Of course, you sacrifice some of the flexibility for the comfort it brings but likely you will not need that flexibility just yet.

One important thing to mention here is that low-level APIs tend to be faster than higher-level APIs. If you’re familiar with programming languages you’d know it’s the same for them too. For example, C++ which is a language that is closer to machine language (lower level) runs faster. Whereas Python, which is a high-level language (you can do more with fewer lines of code, it’s more human-readable, many complex actions are done with built-in functions) is slower.

That’s why lower-level APIs are preferred when you want to work with very big datasets or if you’re going for speed.

I would suggest starting with Keras either way if you’re new to deep learning. As you do projects and you require new areas you want to explore, you will need more flexibility and your needs will guide you towards using a more low-level API. There is no need to try to learn deep learning and a complex low-level API at the same time. Start with the easy option and build your way up from there.