📜  PyTorch 与 Tensorflow

📅  最后修改于: 2022-05-13 01:58:09.046000             🧑  作者: Mango

PyTorch 与 Tensorflow

在过去的几十年里,深度学习在人工智能领域取得了惊人的进步。有几个框架可以帮助您开始深度学习。但是为您的项目选择合适的产品是一项艰巨的任务。虽然有很多框架可供选择,但 PyTorch 和 TensorFlow 是深度学习中最常用的两种。让我们看看其中一个的一些特性、优点和缺点,什么时候使用哪个框架,哪个最适合你的项目。

PyTorch 与 Tensorflow

两个框架都使用称为Tensor的基本基本数据类型。张量是一种能够进行高速计算的多维数组。

PyTorch:这个开源深度学习框架由 Facebook 团队开发。该框架支持Python和 C++。 PyTorch 提供了灵活性并允许用Python语言表达深度学习模型。

TensorFlow:这个开源深度学习框架由谷歌开发并于 2015 年发布。该框架用于自动化系统。该框架快速、灵活,提供分布式训练支持、可扩展性和对 Android 的支持,服务器使用较轻的版本,即 Tensorflow Lite,这使其最适合研究和生产。 Tensorflow 的最新版本集成了高级 API Keras。 Tensorflow 模式是使用 Keras 创建的。 API 提供快速简单的原型设计,因为它提供了称为层的现成构建块。

让我们看看 PyTorch 和 Tensorflow 之间的一些不同之处。



区别:

Features

 

PyTorch

TensorFlow

Development Wizards Facebook developed PyTorch using the Torch library.                              TensorFlow was developed by Google and is based on Theano (Python library)
Computation GraphPyTorch uses a dynamic computational graph where the computations are done line by line at the time when code is interpreted.Tensorflow uses the static computation graph i.e we have to define the computations that we want to do in a sequence and then run the Machine Learning Model. 
DebuggingThe dynamic approach of Pytorch where the computation graph is defined at the run time makes it eligible to use python debugging tools.The static computation graph of the TensorFlow makes it hard to debug. To debug the code in TensorFlow, we can use a tool called tfdgb, which can test and ‘evaluate the TensorFlow expression at the run time.
Production PyTorch is easier to learn and lighter to work with, and hence, is relatively better for passion projects and building rapid prototypes.There are a lot of advantages that TensorFlow enjoys over PyTorch when it comes to production. Better performance due to the static computation graphs, packages/tools which help in fast development over platforms like browser, mobile, and cloud.
Data Visualization PyTorch doesn’t have such a tool. Although we have tools like MatPlot library using which we can compare different training runs.Tensorflow comes up with a brilliant tool called TensorBoard which helps the user to visualize the Machine Learning Model, debug and compare different training runs i.e training a model and the tuning hyperparameters and then training again.TensorBoard can show both the runs at the same time to show the differences between them.

哪一个最好?

尽管这两个框架在很多方面都不同,但很难说哪一个最好。有些人发现 PyTorch 更好用,而另一些人则认为 TensorFlow 更好。但是,这两个框架各有千秋。这两个框架都提供了有用的抽象来减少代码大小并加速生产/开发。

什么时候用哪一种?

PyTorch

TensorFlow

ResearchProduction Models
Better development and debugging tools.Models that need to be deployed on mobile phones.
Python-like experienceModels that require large-scale distributed training.