您现在的位置是:热点 >>正文
比用Pytorch框架快200倍!0.76秒后,笔记本上的CNN就搞定了MNIST
热点734726人已围观
简介...
本文经AI新媒体量子位(公众号ID:QbitAI)授权转载,转载请联系出处。
在MNIST上进行训练,可以说是计算机视觉里的“Hello World”任务了。
而如果使用PyTorch的标准代码训比用练CNN,一般需要3分钟左右。
但现在,在一台笔记本电脑上就能将时间缩短200多倍。
速度直达0.76秒!
那么,到底是如何仅在一次epoch的训练中就达到99%的准确率的呢?
八步提速200倍
这是一台装有PyGeForce GTX 1660 Ti GPU的笔记本。
我们需要的还有Python3.x和Pytorch 1.8。
先下载数据集进行训练,每次运行训练14个epoch。
这时两次运行的平均准确率在测试集上to为99.185%,平均运行时间为2min 52s ± 38.1ms。
接下来,就是一步一步来减少训练时间:
一、提前停止训练
在经历3到5个epoch,测试准确率达到99%时就提前停止训练。
这时的训练时间就减少了rc1/3左右,达到了57.4s±6.85s。
二、缩小网络规模,采用正则化的技巧来加快收敛速度
具体的,在第一个conv层之后添加一个2x2的最大采样层(max pool layer),将全连接层的参数h框减少4倍以上。
然后再将2个dropout层删掉一个。
这样,需要收敛的epoch数就降到了3个以下,训练时间也减少到30.3s±5.28s。
三、优化数据加载
使用data_loader.save架快_data(),将整个数据集以之前的处理方式保存到磁盘的一个pytorch数组中。
也就是不再一次一次地从磁盘上读取数据,而是将整个数据集一次性加载并保存到GPU内存中。
这时,我们只需要一次epoc20h,就能将平均训练时间下降到7.31s ± 1.36s。
四、增加Batch Size
将Batch Size从64增加到128,平均训练时间减少到4.66s ± 583ms。
五、提高学习率
使用Superconv0倍ergence来代替指数衰减。
在训练开始时学习率为0,到中期线性地最高值(4.0),再慢慢地降到0。
这使得我们的训练时间下降到3.14s±4.72ms。
六、再次增加Batch Size、缩小缩!0小网络规模
重复第二步,将Batch Size增加到256。
重复第四步,去掉剩余的dropout层,并通过减少卷积层的宽度来进行补偿。
最终将平均时间降到1.74s±18.3ms。
七、最后的微调
首先,将最.7大采样层移到线性整流函数(ReLU)激活之前。
然后,将卷积核大小从3增加到5.
最后进行超参数调整:
使学习率为0.01(默认为0.001),beta1为0.7(默认为0.9),bata2为0.96秒(默认为0.999)。
到这时,我们的训练已经减少到一个epoch,在762ms±24.9ms的时间内达到了99.04%的准确率。
“这只是一个Hello World案例”
对于这最后的结果,有人觉得司空见惯后,:
优化数据加载时间,缩小模型尺寸,使用ADAM而不是SGD等等,都是常识性的事情。
我想没有人会真的费心去加速运行MNIST,因为这是机器学习中的“Hello World”,重点只是像你展示最小的关键笔记值,让你熟悉这个框架——事实上3分钟也并不长吧。
而也有网友觉得,大多数人的工作都不在像是MNIST这样的超级集群上。因此他表示:
我所希望的是工作更多地集中在真正最小化训练时间方面。
GitHub:
h本上ttps://github.com/tuomaso/train_mnist_fast
Tags:
相关文章
标签: 众泰汽车 2025年业绩预告 整车业务重启 归母净利润
热点云梦级1月28日云梦级消息,今日众泰汽车发布公告,预计 2025 年度归母净利润亏损 2.81 亿元至 4.17 亿元,较上年同期亏损 10 亿元下降 58.32% 至 71.91%。 公司称,202...
【热点】
阅读更多标签: 英伟达 Anthropic Mythos 黄仁勋
热点云梦级4月17日云梦级消息,据彭博社报道,英伟达 CEO 黄仁勋周三表示,Anthropic 最新网络安全大模型 Mythos 取得的突破表明,美国应寻求与中国加强合作,以便这全球两大经济体的 AI...
【热点】
阅读更多网红李子柒介绍
热点前言:网红李子柒哪里人?李子柒出生地:四川省绵阳市。李子柒本名:李佳佳),1990年出生于四川省绵阳市,中国内地美食短视频创作者。2015年,李子柒开始拍摄美食短视频。2016年11月,凭借短视频《兰...
【热点】
阅读更多
热门文章
最新文章
友情链接
- 标签: 康师傅
- https://www.tombow.com/search/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,9jJ
- https://www.lechzuers.com/de/search?cat=163&q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,ZKE
- https://www.woorden.org/spreekwoord.php?woord=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,RMs
- https://www.zalora.sg/catalog/?cat=112&q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,uSo
- https://www.roberthalf.com/us/en/jobs/all/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】4GL
- https://www.pacific-lifestyle.co.uk/search?sort=alphabetical&term=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,NhR
- https://www.impactpool.org/search/?type=79&q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】n1c
- https://www.resilienz-akademie.com/?cat=71&s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,svr
- https://www.ushmm.org/search/results.php?q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,da9
- https://5gaa.org/?token=6e2l7hjt2i26gzgctgwdrv7v0j6nxorq&s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】UTY
- https://jihoon471.cafe24.com/product/search.html?banner_action=&keyword=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】Qj6
- https://www.selfsufficientish.com/main/?s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,Rlc
- https://www.rookwinkel.nl/catalogsearch/result/index/?q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,pc4
- https://www.otakuninjahero.com/en/search/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,Fzj
- https://www.solerpalau.com/en-en/catalogsearch/result/?q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,Bo6
- https://www.universal-music.co.jp/search/?q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,iQZ
- https://yokohama-oht.com/?action=CHECK&s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,MdF
- https://www.navylookout.com/?ID=nSBR6Ivdu6lZg1yr2SDs30Lo5sTs76yJ&s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,jDA
- https://www.lgnewsroom.com/search/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,U5Y
- https://www.lneg.pt/en/?s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,eDe
- https://www.synonyms.com/antonyms/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,TFp
- https://www.nuovabai.it/catalogsearch/result/?action=SEARCH&q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,otq
- https://www.zisha.com/shop/list.shtml?wap_keyword=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,lr9
- https://www.xbiao.com/search/index?tpf&wd=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,YQ3
- https://www.navymwr.org/search/?query=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,MZA
- https://www.jusoen.com/addreng.asp?p1=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】i1x
- https://www.reginatangoshoes.com/en/catalogsearch/result/index/?T=1686132113407&q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,hxW
- https://www.pearson.com/en-us/search.html?aq=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,9lo
- https://www.nyif.com/catalogsearch/result/?q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,ms5
- https://www.rostaing.com/catalogsearch/result/?cat=22&q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,0sk
- https://www.teacherspayteachers.com/Browse/Price-Range/Free/Search:谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,Lv3
- https://yscc1986.net/search/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】DVX
- https://www.udc.co.uk/index.php?route=product/search&sort=p.price&order=DESC&tag=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,Fhn
- https://www.sensorshop24.de/catalogsearch/result/index/?type=132&q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,Jyk
- https://www.revere.org/search?action=SEARCH&q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,B3n
- https://www.pixiv.net/tags/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,8Kg
- https://www.teamlab.art/fr/?submit=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,Yxr
- https://www.lenovo.com/gb/en/search?action=SEARCH&text=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,Efq
- https://www.maine.gov/pfr/professionallicensing/search/node?keys=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,BRM
- https://www.teamlab.art/it/?submit=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,1Ky
- https://www.teacherspayteachers.com/Browse/Search:谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,Up5
- https://www.qidulp.com/search?query=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,I9L
- https://www.pierreherme.com/catalogsearch/result/?q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,k1y
- https://www.nss.nhs.scot/search?q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,4lR
- https://www.sic-info.org/?s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,FiQ
- https://www.remit.co.jp/id/?s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,idQ
- https://www.silentiumpc.com/en/search/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,e2p
- https://www.wuv.edu/?s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,AC4
- https://www.nslcleaders.org/?s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,4RT
- https://www.tmtpost.com/search?q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,xZi