Now Reading
PyTorch vs Keras: Who Suits You The Best

PyTorch vs Keras: Who Suits You The Best

PyTorch and Keras are both very powerful open-source tools in Deep Learning framework. Usually, beginners struggle to decide which framework to work with when it comes to starting a new project. According to a recent survey by KDnuggets, Keras and Python emerged as the two fastest growing tools in data science. Here is a step-by-step comparison of both the tools with respect to various aspects, to help to decide what framework to use for your next deep learning project.

1.Supporting system and language:

PyTorch, developed by Facebook, supports Windows, Linux and OSX operating systems. Meanwhile, Keras, developed by Google engineer Francois Chollet, works only on Linux and OSX. Although it does not make much of a difference, since most deep learning enthusiasts do not prefer Windows, but in case it matters to you, Keras would lose the competition here. Both tools support Python versions of 2.7, 3.5 and 3.6. Some users of PyTorch are Twitter, Salsesforce and the University of Oxford and that of Keras are Home61, Suggestic and Stylight.

PyTorch wins.


It is easier and faster to debug in PyTorch than in Keras. Keras has a lot of computational junk in its abstractions and so it becomes difficult to debug. PyTorch allows an easy access to the code and it is easier to focus on the execution of the script of each line. Debugging can be done using the standard way, by printing after any line of the code. In Keras, the possibility of the code going wrong is less than PyTorch, but it is not completely impossible. So once the code goes wrong in Keras, it is very difficult to note where the actual flaw was.

Despite model complexity, PyTorch allows for an easy and direct error identification. Moreover, PyTorch repo can also be used to check whether it is readable code. With static graph libraries like Theano and Tensorflow in Keras, it is very difficult to find the cause of the error, while in dynamic  libraries like PyTorch with dynamic computational graph, it is easier to track which line is responsible for which error. You can even stop the interpreter in the debugger to see what layer produces the error. In cases where one cannot debug with the debugger, there is a high probability of there being either too much of abstraction or the code being  of low value. PyTorch: Common debugging tools in PyTorch are pdb, ipdb or PyCharm.

PyTorch wins.


It is very important to have control over your models in terms of RAM, CPU and file loading, while deploying them. PyTorch saves its models in Python-based Pickles, which is not portable. Exporting models of PyTorch is more difficult because of its Python code and for this issue the widely recommended solution is to convert the PyTorch model to Caffe2 using ONNX. Keras has a wider set of options for deployment of its models to mobile platforms, when operating on TensorFlow, like Flask, GitLab, Docker.

Keras wins.

Image source: Deep learning framework power source 2018.


See Also

Keras was released in the year March 2015, and PyTorch in October 2016. Keras has more support from the online community like tutorials and documentations on the internet. It also has more codes on GitHub and more papers on arXiv, as compared to PyTorch. PyTorch has also gained popularity in spite of releasing later than Keras but it has comparatively less online support than Keras which is slightly older. Although it is maintained by a group of engineers at Facebook and they actively provide users with online support.

A tie.

5.Visualisation: Keras can have Tensorflow as its backend and therefore has Tensorboard for visualization that it can use. There is currently nothing equivalent for PyTorch in this regard.

Keras wins.

In Conclusion

Both the tools have a very close competition and which one to use depends on the user’s background, the tool requirements for the project and what programming language one leans on. If one is more into understanding the mathematics behind models and is really keen to know what the model is really doing, Keras is highly recommended. On the other hand, if you are more inclined towards only building, training and deploying the model, without giving much emphasis on understanding the meaning of the model, then PyTorch is more suitable.

That being said, it is recommended to learn the basics of both the platforms and experience which one is more suitable for your work. Once the basics of both are known, it is easy to transfer on the other platform and operate fully on it. But if you are a complete beginner, Keras is very beginner-friendly and easy to work with.

Provide your comments below


If you loved this story, do join our Telegram Community.

Also, you can write for us and be one of the 500+ experts who have contributed stories at AIM. Share your nominations here.

Copyright Analytics India Magazine Pvt Ltd

Scroll To Top