当前位置:网站首页>pytorch和tensorflow有什么区别?
pytorch和tensorflow有什么区别?
2022-06-13 00:37:00 【程序媛珂珂】
PyTorch 是一种用于构建深度学习模型的功能完备框架,同时tensorflow也是常用的框架之一。大家在学习的时候,尝尝会用来做比较。那么pytorch和tensorflow有什么区别?大家所关心的问题,解答来了。
pytorch和tensorflow有什么区别?
创建和运行计算图可能是两个框架最不同的地方。在PyTorch中,图结构是动态的,这意味着图在运行时构建。而在TensorFlow中,图结构是静态的,这意味着图先被“编译”然后再运行。
举一个简单的例子,在PyTorch中你可以用标准的Python语法编写一个for循环结构
for _ in range(T):
h = torch.matmul(W, h) + b
此处T可以在每次执行代码时改变。而TensorFlow中,这需要使用“控制流操作”来构建图,例如tf.while_loop。TensorFlow确实提供了dynamic_rnn用于常见结构,但是创建自定义动态计算真的更加困难。
PyTorch中简单的图结构更容易理解,更重要的是,还更容易调试。调试PyTorch代码就像调试Python代码一样。你可以使用pdb并在任何地方设置断点。调试TensorFlow代码可不容易。要么得从会话请求要检查的变量,要么学会使用TensorFlow的调试器(tfdbg)。
灵活性
tensorflow:静态计算图,数据参数在CPU与GPU之间迁移麻烦,调试麻烦
pytorch:动态计算图,数据参数在CPU与GPU之间迁移十分灵活,调试简便
计算速度
同等条件下:
tensorflow 在CPU上运行速度比 pytorch 快
tensorflow 在GPU上运行速度和 pytorch 差不多
依赖库
tensorflow:支持更多库函数,比如图像数据预处理方式会更多
pytorch:正在扩充,未来和tensorflow应该差别不大
数据加载
tensorflow:API设计庞大,使用有技巧,但有时候不能直接把数据加载进TensorFlow
pytorch:API整体设计粗糙,但加载数据的API设计很友好。加载数据的接口由一个数据集、一个取样器和一个数据加载器构成。
设备管理
tensorflow:不需要手动调整,简单
pytorch:需要明确启用的设备
关于这点,凭个人喜好,我比较喜欢手动启用CUDA_VISIBLE_DEVICES,我个人对内存、显存的管理较严。
免费分享一些我整理的人工智能学习资料给大家,包括一些AI常用框架实战视频、图像识别、OpenCV、NLQ、机器学习、pytorch、计算机视觉、深度学习与神经网络等视频、课件源码、国内外知名精华资源、AI热门论文、行业报告等。
为了更好的系统学习AI,推荐大家收藏一份。
下面是部分截图,文末附免费下载方式。
一、人工智能课程及项目
二、国内外知名精华资源
三、人工智能论文合集
四、人工智能行业报告
学好人工智能,要多看书,多动手,多实践,要想提高自己的水平,一定要学会沉下心来慢慢的系统学习,最终才能有所收获。
点击下方名片,扫码免费下载文中资料。
边栏推荐
- Basic operations of FreeMarker
- 也许尘埃落地,我们才能想清楚互联网的本质
- [LeetCode]7. Integer inversion thirty-nine
- In / out / inout details of MySQL stored procedures
- [GYCTF2020]Ezsqli --BUUCTF
- Druid reports an error connection holder is null
- Stack overflow learning summary
- Go design concurrent web crawler
- [error] invalid use of incomplete type uses an undefined type
- 为什么磁盘分区的时候,第一个分区前面总有一段空间(63或者2048个扇区)
猜你喜欢
阿姨学代码续集:能力吊打大批程序员
Kali system -- dnsrecon for DNS collection and analysis
People and gods are angry. Details of Tangshan "mass beating of women incident"
Tsinghua Bosch joint ml center, thbi lab:cheng Yang Ying | realize safety reinforcement learning through the value at risk of constraints
[GYCTF2020]Ezsqli --BUUCTF
antdPro - ProTable 实现两个选择框联动效果
Buuctf babyupload[gxyctf2019]
MySQL lpad() and rpad() concatenate string functions with specified length
Kotlin 协程的作用域构建器 coroutineScope与runBlocking 与supervisorScope,协程同步运行,协程挂掉的时候其他协程如何不被挂掉。
In / out / inout details of MySQL stored procedures
随机推荐
Aunt learning code sequel: ability to sling a large number of programmers
Buuctf babyupload[gxyctf2019]
Hard (magnetic) disk (II)
Can branches sign labor contracts with employees
MySQL query table field information
Is the brokerage account in qiniu business school safe? Is the account opening rate low
Context of go concurrency mode
JPA execution failed in scheduled task -executing an update/delete query transactionrequiredexception
天津银行周传凯:从 0 到 1,我的分布式数据库落地经验谈
Also on STM32 using dma+ serial port to obtain variable length data
MySQL locates the position of the character in the string String substitution
Kotlin 协程,job的生命周期
Learning and Development notes of mongdb
[CISCN2019 华北赛区 Day2 Web1]Hack World --BUUCTF
La différence entre philosophie et littérature
Basic operations of FreeMarker
People and gods are angry. Details of Tangshan "mass beating of women incident"
[LeetCode]1. Sum of two numbers thirty-four
String类中split()方法的使用
Basics of network security (1)