DEV Community

Cover image for TensorFlow vs Pytorch - The Best deep Learning Framework!
Josue Luzardo Gebrim
Josue Luzardo Gebrim

Posted on

TensorFlow vs Pytorch - The Best deep Learning Framework!

TensorFlow vs Pytorch! Deep learning solutions comparative!
Obs: This post was first posted on Medium

A brief comparison between Tensorflow and Pytorch wins the best of the best in the world! :)

In the last few week’s I was taken to research and consider two trendy deep learning frameworks, Tensorflow and Pytorch. Below we have an accumulation of all the purchases found during my search.

Tensorflow is an open-source deep learning framework developed and maintained mainly by Google since 2015, being widely used by companies, startups, and business firms for automation and the development of new solutions. Its wide adoption by the market is mainly due to its ease of use, support for distributed training, scalable product, and deployment options.

Airbnb uses Tensorflow to classify images and detect objects to improve the guest experience, Coca-Cola using the Framework was able to prove proof of purchases in a simplified way, Lenovo created a platform to accelerate the smart revolution, Paypal uses in fraud prevention, WPS has developed an intelligent office for different scenarios with image recognition and character recognition in images.

Pytorch is the first and the last open-source framework created in 2017 and maintained today on Github by Facebook. With each passing day, more and more, your community grows mainly due to the ease of its use, efficiency in the use of memory.

Its use is not limited only to large educational institutions. Still, in the most diverse projects around the world, it is already present in the quantum computing area, incorporated in the Xanadu project, Pennylane, a mix between Python platform and library for the development of quantum machine learning (QML), automatic differentiation, and optimization of hybrid quantum-classical computations, as well as integration with other libraries for quantum computing such as Microsoft’s Q#.

Looking at these two Frameworks, we have distinct differences in the community’s behavior, as is due to the popularity of each one and the diverse growing opportunities and even learning for those who want to start deep learning.

#Apprenticeship

One of the factors that made both Tensorflow and Pytorch so famous is the ease of use and the rich documentation with varied examples of service in the most different code repositories like GitHub and GitLab and the growing wave of articles published in colleges, universities, magazines, and even on websites that host blogs on the subject such as Medium.

To get off the ground with Tensorflow, the student can use courses made available by Google with certificate; in the case of Pytorch, there are several college and university that offer free courses using some Pytorch descendant framework to teach deep learning, as is the case of Fast.ia

Another way to learn how to use these Frameworks and gain experience is by participating in competitions on specialized sites such as Kaggle, where many companies that have a challenge can create matches to solve this with cash prizes for the person or team that returns the best model.

#Community

While the Tensorflow community of scholars, researchers, developers, data scientists, machine learning engineers are struggling every day and using their strengths together to make Tensorflow a better Framework, we see that from Pytorch, several other Frameworks will emerge with unique proposals and objectives and with its community such as Fast.ia.

In Brazil, we have several communities and events where Frameworks appear as regulations, particularly in TensorFlow. We have the google developer group, and in the case of Pytorch, Facebook Circle, both active mainly in the country’s major centers.

#Popularity

We are looking at two giants that, each day that passes gain new converts for their simplicity of use and a large amount of documentation and examples of their service available on the internet.

Another way to understand the popularity of each one is to look at their demand on the internet; for that, we can use Google Trends by placing Tensorflow and Pytorch as a search term; we can see that both are very popular. Still, in terms of search, we have Tensorflow as most wanted.

#Opportunities

Looking at available vacancies, we can see that in many of them, recruiters are after people who know how to solve the problem or work in a specific area of artificial intelligence and not just those who are specialists in Tensorflow or Pytorch only.

There are many sites with open positions for the most diverse performance profiles in artificial intelligence. Professionals who can understand and work with both will have a broader range available.

Looking technically at Tensorflow and Pytorch, how do they differ? What are its advantages and disadvantages?
Large communities maintain the two Frameworks with the help of technology giants, Google and Facebook; with this, we have a scenario of constant updates, improvements, and bug fixes, and in many cases, in a matter of time, new features, algorithms, or strategies available in one of the Frameworks will be implemented and will be available in the other.
However, some points must be considered, namely:

#Dynamic or statistical definition in computer graphics
Pytorch, since its inception, has implemented computer graphics aiming at the importance of optimization for large-scale neural networks, starting from the precept of the dynamic definition of the use of GPU. Using Tensorflow, we use computational resources during statistically defined graphics processing; in practice, we have achieved the non-dependence of a single scheduling drive, graphic optimization, and automatic differentiation with this strategy.

#Distributed training
Pytorch taking advantage of the native support for Python asynchronous execution to implement data parallelism, the main feature that differentiates it from Tensorflow, because while in Tensorflow, the developer will have to manually code and adjust all operations to be performed in one specific device to allow distributed training, in Pytorch this is done automatically and very simple to be implemented. Still, if necessary, it can do all this manual configuration as well.

#Preview
For visualization of the training process in Tensorflow, we have the Tensorboard, with it, we can monitor and visualize metrics such as loss and precision, visualization of the model graph (ops and layers), visualization of histograms of weights, bias, or other tensors according to them change over time, projection of embeddings in a lower-dimensional space, display of image, text and audio data, creation of TensorFlow program profiles. To view the training in Pytorch, we have VisDOM, a minimalist and limited solution.

#Leading for production (Deploy):
Production of Machine Learning (ML), in practice through commands made from a Python library, installed before the process; we can deploy the model quickly and happily. :)
Unfortunately, Pytorch does not have such an automated solution, and generally, to deploy a web model, it will be necessary to create a back-end application in flask or Django.

Another possibility for deployment for both TensorFlow and Pytorch is to adopt some MLOps / AIOPS solutions such as MLflow or Kubeflow to create automated pipelines or create your solution from scratch, customized to your scenario, using continuous integration tools (CI) and continuous deploy (CD).

#Monitoring
Nowadays, we have several solutions for monitoring the environment where each model will be deployed, such as the Elastic stack with Beasts, mini-applications that generate customizable metrics logs, Logstach to capture these logs and work on their information, Elastickseah to save and enable the research and analysis of this data and Kibana, an excellent solution for visualization, with this we can monitor the environment in an effective and scalable way.

To monitor the model, TensorFlow provides a history of the accuracy and loss of each model and can be used as a metric to measure the quality and efficiency of the model over time; in the case of Pytorch, no solution was found for monitoring the models.

#Model Drift

Over time, the company and startups that use artificial intelligence have their business model changed or are constantly evolving. The models used to work may start showing inconsistent results or even false positives and affect the business in its entirety.

To solve these problems, TensorFlow, using TFX, can analyze the model’s data with the model’s training dataset to follow the deviation and take the model’s retraining attitude.

Pytorch does not have its solution to deal with this problem. Still, several companies that can deploy models made with the Framework have created their alternative, as is the case with Microsoft. Azure has monitors to detect the “data gap” in the data sets used in its cloud computing solution.

Taking all of this into account, we can see that both Frameworks are widely spread and land extremely active communities, in addition to the large number of companies and startups that use and help to maintain, each having peculiarities, which over time will also be available and evolved in another Framework.

References:

https://medium.datadriveninvestor.com/tensorflow-extended-tfx-data-analysis-validation-and-drift-detection-part-2-6a9c5f8c6210

https://docs.microsoft.com/pt-br/azure/machine-learning/how-to-monitor-datasets?tabs=python

https://www.elastic.co/what-is/elk-stack

https://medium.com/ai%C2%B3-theory-practice-business/tensorflow-1-0-vs-2-0-part-1-computational-graphs-4bb6e31c1a0f

https://binaryinformatics.com/pytorch-vs-tensorflow/

https://medium.com/@UdacityINDIA/tensorflow-or-pytorch-the-force-is-strong-with-which-one-68226bb7dab4

https://towardsdatascience.com/pytorch-vs-tensorflow-in-code-ada936fd5406

https://towardsdatascience.com/pytorch-vs-tensorflow-spotting-the-difference-25c75777377b

https://builtin.com/data-science/pytorch-vs-tensorflow

https://pennylane.ai/

https://www.tensorflow.org/about/case-studies

Buy Me A Coffee

Follow me on Medium :)

Top comments (0)