当前位置:网站首页>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,推荐大家收藏一份。
下面是部分截图,文末附免费下载方式。
一、人工智能课程及项目

二、国内外知名精华资源

三、人工智能论文合集

四、人工智能行业报告

学好人工智能,要多看书,多动手,多实践,要想提高自己的水平,一定要学会沉下心来慢慢的系统学习,最终才能有所收获。
点击下方名片,扫码免费下载文中资料。
边栏推荐
- ImportError: cannot import name ' get_ ora_ doc' from partially initialized module
- DNS attack surface analysis
- Browser console injection JS
- ucore lab3
- MySQL lpad() and rpad() concatenate string functions with specified length
- Using com0com/com2tcp to realize TCP to serial port (win10)
- Pipelines in go concurrency mode
- [LeetCode]28. Implement strstr()
- Kali system -- fierce of DNS collection and analysis
- 2022 beautician (technician) certificate title and answer
猜你喜欢

Stack overflow learning summary
![[GYCTF2020]Ezsqli --BUUCTF](/img/8b/3c8b48daf7719482a235fd622737aa.png)
[GYCTF2020]Ezsqli --BUUCTF

Maybe we can figure out the essence of the Internet after the dust falls
![[Error] invalid use of incomplete type 使用了未定义的类型](/img/8a/7cb5d270cfd8831ddc146687fe4499.png)
[Error] invalid use of incomplete type 使用了未定义的类型

Antdpro - protable realizes the linkage effect of two selection boxes

JPA execution failed in scheduled task -executing an update/delete query transactionrequiredexception

Build your own PE manually from winpe of ADK

Composite key relationships using Sqlalchemy - relationships on composite keys using Sqlalchemy

Kali system -- fierce of DNS collection and analysis

Aunt learning code sequel: ability to sling a large number of programmers
随机推荐
How to solve the duplication problem when MySQL inserts data in batches?
Pipelines in go concurrency mode
Kalix system - use of information collection gadgets
New blog address
kotlin 协程withContext切换线程
Another year 1024, happy programmer's Day!
MySQL queries the quantity of each month and the year-on-year and month on month data of each month
6.824 Lab 3A: Fault-tolerant Key/Value Service
6.824 Lab 2: Raft
[GYCTF2020]Ezsqli --BUUCTF
今日在家休息
6.824 Lab 1: MapReduce
[CISCN2019 华北赛区 Day2 Web1]Hack World --BUUCTF
[gxyctf2019] no dolls -- detailed explanation
Conversion of integer part and decimal part between binary / octal / decimal / hexadecimal
RCC clock configuration of stm32f401
Stm32f4 development of DMA transmission to GPIO port
6.824 Lab 3B: Fault-tolerant Key/Value Service
三角波与三角波卷积
Map from getting started to performance optimization