【NAS训练技巧】分析更新supernet中Batch Norm参数和Batchsize大小之间的关系

举报
苏道 发表于 2021/11/27 15:37:45 2021/11/27
【摘要】 当supernet(超网络)训练完备后,需要从中抽取子架构并继承已经训练完备的supernet的参数,因为在训练supernet时,batch norm的moving mean 和moving var是不更新的,需要在训练supernet完备后,通过re-calibration这个操作,针对某个架构重新用训练集更新一般这个架构对应的batch norm的moving参数,再用moving的参

背景说明:

      当supernet(超网络)训练完备后,需要从中抽取子架构并继承已经训练完备的supernet的参数,因为在训练supernet时,batch norm的moving mean 和moving var是不更新的,需要在训练supernet完备后,通过re-calibration这个操作,针对某个架构重新用训练集更新一般这个架构对应的batch norm的moving参数,再用moving的参数来对验证集验证。
      这里面有个tricky是,不用完整的训练集去更新moving参数,因为一般训练集过大,用这么大的训练集去更新,获取子架构精度/指标 会变得非常慢,论文有提到可以用部分的训练集去更新moving即可:
  • 实际测试中用整个训练集去更新supernet中bn的参数的效果和用随机2w【imagenet】张训练数据去更新supernet的bn参数最终出来的精度相近,但是效率高很多
  • 715e0741667b84f07990d503ff27c131_810x234.png@900-0-90-f.png

实验:

       最近在做一个检测任务的NAS,发现更新batch norm的参数,不仅和更新图片的数量有影响,和batch size大小也有影响,以下实验都是用同一批数据集并且数据排序都完全一致,分别采用samples为 10240、5120、2560,都来自训练集,训练集总大小为11w张:

batch size 8:



batch size 8 batch size 8
update bn samples 2560 update bn samples 5120
use time 1min40s use time 2mins15s
arch1 update mAP@0.5 eval Map@0.5 arch1 update mAP@0.5 eval Map@0.5
0.468 0.49454 0.4778 0.4947
arch2 update mAP@0.5 eval Map@0.5 arch2 update mAP@0.5 eval Map@0.5
0.4851 0.505072 0.4949 0.50722
arch3 update mAP@0.5 eval Map@0.5 arch3 update mAP@0.5 eval Map@0.5
0.4838 0.5038378 0.4916 0.505585


batch size 16:


batch size 16 batch size 16
update bn samples 2560 update bn samples 5120
use time 1mins30s use time 2mins
arch1 update mAP@0.5 eval Map@0.5 arch1 update mAP@0.5 eval Map@0.5
0.44 0.4964033 0.4654 0.4966
arch2 update mAP@0.5 eval Map@0.5 arch2 update mAP@0.5 eval Map@0.5
0.4605 0.508583 0.4832 0.5087966
arch3 update mAP@0.5 eval Map@0.5 arch3 update mAP@0.5 eval Map@0.5
0.4577 0.506637 0.4794 0.507569

batch size 16
update bn samples 10240
use time 3mins
arch1 update mAP@0.5 eval Map@0.5
0.4831 0.492936
arch2 update mAP@0.5 eval Map@0.5
0.4968 0.505962
arch3 update mAP@0.5 eval Map@0.5
0.4944 0.5052664



batch size 32:

batch size 32 batch size 32
update bn samples 2560 update bn samples 5120
use time 1mins30s use time 2mins
arch1 update mAP@0.5 eval Map@0.5 arch1 update mAP@0.5 eval Map@0.5
0.3843 0.49717 0.4379 0.4973
arch2 update mAP@0.5 eval Map@0.5 arch2 update mAP@0.5 eval Map@0.5
0.4093 0.50911 0.4584 0.5094
arch3 update mAP@0.5 eval Map@0.5 arch3 update mAP@0.5 eval Map@0.5
0.4046 0.507647 0.4533 0.5074
batch size 32
update bn samples 10240
use time 2mins50s
arch1 update mAP@0.5 eval Map@0.5
0.4693 0.495272
arch2 update mAP@0.5 eval Map@0.5
0.4844 0.5076802
arch3 update mAP@0.5 eval Map@0.5
0.4805 0.5062097

batch size 64:

batch size 64 batch size 64
update bn samples 2560 update bn samples 5120
use time 1min30s use time 2min10s
arch1 update mAP@0.5 eval Map@0.5 arch1 update mAP@0.5 eval Map@0.5
0.2623 0.4847 0.3773 0.496722
arch2 update mAP@0.5 eval Map@0.5 arch2 update mAP@0.5 eval Map@0.5
0.3123 0.4991 0.4082 0.50898615
arch3 update mAP@0.5 eval Map@0.5 arch3 update mAP@0.5 eval Map@0.5
0.2945 0.4995 0.3977 0.5072075
batch size 64
update bn samples 10240
use time 3min
arch1 update mAP@0.5 eval Map@0.5
0.4385 0.4956
arch2 update mAP@0.5 eval Map@0.5
0.459 0.5072
arch3 update mAP@0.5 eval Map@0.5
0.4526 0.5059



总结

     从上述结果能看到,因为统计batch norm 是当前批次的滑动平均,对于固定数量的samples,batch size大了统计的次数就少了,更新时候的mAP和实际eval的mAP就差的更远,无法达到好的效果,如果想用大batch size,samples也需要相应的提升才能得到好的效果,从耗时来看,大batch会使得总的获取子架构指标速度慢了,所以推荐用小batch size这样能用少点samples,获取架构指标更快速

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。