[{"data":1,"prerenderedAt":837},["ShallowReactive",2],{"content-query-tmHUveDXsY":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"cover":11,"type":12,"body":13,"_type":831,"_id":832,"_source":833,"_file":834,"_stem":835,"_extension":836},"/technology-blogs/zh/340","zh",false,"","大V博文论文系列（一）：MindSpore训练和端侧部署TinyNet","这篇论文是关于华为诺亚方舟实验室、北京邮电大学以及香港科技大学的研究者们提出了一个新的轻量模型范式TinyNet。相比于EfficientNet的复合放缩范式（compound scaling），通过TinyNet范式得到的模型在ImageNet上的精度要优于相似计算量（FLOPs）的EfficientNet模型。","2020-12-06","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/74c4c2c1a7f340e4a99e855914456d49.png","technology-blogs",{"type":14,"children":15,"toc":828},"root",[16,24,30,43,54,59,64,72,83,88,97,102,111,116,121,126,131,138,143,148,160,170,180,188,196,207,215,225,233,241,251,259,267,277,285,295,303,313,321,331,339,349,357,367,375,385,393,403,411,421,431,439,447,458,466,474,484,492,502,510,518,526,536,544,552,562,576,592,603,616,627,638,651,662,701,716,734,749,767,778,789,802,813],{"type":17,"tag":18,"props":19,"children":21},"element","h1",{"id":20},"大v博文论文系列一mindspore训练和端侧部署tinynet",[22],{"type":23,"value":8},"text",{"type":17,"tag":25,"props":26,"children":27},"p",{},[28],{"type":23,"value":29},"作者：金雪峰",{"type":17,"tag":25,"props":31,"children":32},{},[33,35],{"type":23,"value":34},"作者主页：",{"type":17,"tag":36,"props":37,"children":41},"a",{"href":38,"rel":39},"https://www.zhihu.com/people/jin-xue-feng",[40],"nofollow",[42],{"type":23,"value":38},{"type":17,"tag":25,"props":44,"children":45},{},[46,48],{"type":23,"value":47},"文章转自：",{"type":17,"tag":36,"props":49,"children":52},{"href":50,"rel":51},"https://zhuanlan.zhihu.com/p/325923211",[40],[53],{"type":23,"value":50},{"type":17,"tag":25,"props":55,"children":56},{},[57],{"type":23,"value":58},"最近基于MindSpore的论文逐步增多，我们后续会挑选一些好论文给大家分享一下，方便大家第一时间使用相关成果。",{"type":17,"tag":25,"props":60,"children":61},{},[62],{"type":23,"value":63},"这篇论文是关于华为诺亚方舟实验室、北京邮电大学以及香港科技大学的研究者们提出了一个新的轻量模型范式TinyNet。相比于EfficientNet的复合放缩范式（compound scaling），通过TinyNet范式得到的模型在ImageNet上的精度要优于相似计算量（FLOPs）的EfficientNet模型。例如， TinyNet-A的Top1准确率为76.8% ，约为339M FLOPs，而EfficientNet-B0类似性能需要约387M FLOPs。另外，仅24M FLOPs 的TinyNet-E的准确率达到59.9%，比之前体量相当的MobileNetV3高约1.9％。",{"type":17,"tag":25,"props":65,"children":66},{},[67],{"type":17,"tag":68,"props":69,"children":71},"img",{"alt":7,"src":70},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/09135bd78c264b8b9944958ad7a9ad6d.jpg",[],{"type":17,"tag":25,"props":73,"children":74},{},[75,77],{"type":23,"value":76},"注：上图部分来源于：",{"type":17,"tag":36,"props":78,"children":81},{"href":79,"rel":80},"https://www.youtube.com/watch?v=mqOdIYxxNCs",[40],[82],{"type":23,"value":79},{"type":17,"tag":25,"props":84,"children":85},{},[86],{"type":23,"value":87},"论文链接：",{"type":17,"tag":25,"props":89,"children":90},{},[91],{"type":17,"tag":36,"props":92,"children":95},{"href":93,"rel":94},"https://arxiv.org/pdf/2010.14819.pdf",[40],[96],{"type":23,"value":93},{"type":17,"tag":25,"props":98,"children":99},{},[100],{"type":23,"value":101},"开源地址：",{"type":17,"tag":25,"props":103,"children":104},{},[105],{"type":17,"tag":36,"props":106,"children":109},{"href":107,"rel":108},"https://gitee.com/mindspore/mindspore/tree/master",[40],[110],{"type":23,"value":107},{"type":17,"tag":25,"props":112,"children":113},{},[114],{"type":23,"value":115},"感谢林枫的供稿，感谢诺亚实验室云鹤/韩凯等专家的支持。",{"type":17,"tag":25,"props":117,"children":118},{},[119],{"type":23,"value":120},"简介",{"type":17,"tag":25,"props":122,"children":123},{},[124],{"type":23,"value":125},"深度卷积神经网络（CNN）在许多视觉任务中取得了很大成功。然而，如果要在移动设备上部署AI模型，我们需要持续调整网络深度（模型层数）、宽度（卷积通道的数量）和图像分辨率这些网络结构要素来优化内存使用并减少延迟。EfficientNet在模型深度，宽度，图像分辨率这三个维度复合缩放来调整神经网络结构。然而EfficientNet更多关注在如何产生大体量的模型，轻量模型的设计有待更好的发掘。",{"type":17,"tag":25,"props":127,"children":128},{},[129],{"type":23,"value":130},"一个直接的方法是应用EfficientNet的缩放公式。例如，我们可以进一步缩小EfficientNet-B0，并得到一个具有200M FLOPs的EfficientNet-B-1。然而这种策略无法得到最有效的模型。我们随机生成了100个通过改变基线模型EfficientNet-B0的三维（模型深度，宽度，图像分辨率）得到的网络模型。这些模型的计算量小于或等于基线模型（图1）。我们发现这其中最佳模型的精度比用EfficientNet缩放公式得到的模型高出约2.5%。",{"type":17,"tag":25,"props":132,"children":133},{},[134],{"type":17,"tag":68,"props":135,"children":137},{"alt":7,"src":136},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/6718465ffac0417681d91632ad1c3534.jpg",[],{"type":17,"tag":25,"props":139,"children":140},{},[141],{"type":23,"value":142},"图1：图像分类精度与模型的计算量的关系。使用EfficientNet缩放公式生成的5个的模型（绿色）性能要劣于一些基于EfficientNet-B0随机突变产生的前沿模型（红色）。",{"type":17,"tag":25,"props":144,"children":145},{},[146],{"type":23,"value":147},"本文研究的是模型精度和三个维度（模型深度，宽度，图像分辨率）的关系并希望探索出比EfficientNet更优的模型压缩范式。首先，我们发现对于轻量模型，图像分辨率和模型深度比宽度更重要。然后我们指出，EfficientNet的复合放缩方法不再适合为移动设备设计轻量网络。因此，我们通过对于前沿模型（图1中的红线）的大量实验和观察探索了一个新的压缩模型的范式‘Tiny Formula’。具体来说，给定FLOPs上限，我们通过在前沿模型上进行高斯过程回归，并用‘Tiny Formula’计算最佳输入图像分辨率和模型深度。然后根据最大FLOPs的约束来确定模型的宽度。论文中所提出的‘Tiny Formula’简单有效：例如， TinyNet-A的Top1准确率为76.8% ，计算量约为339M FLOPs，而EfficientNet-B0类似性能需要约387M FLOPs。另外，仅24M FLOPs 的TinyNet-E在ImageNet上图像分类的准确率达到59.9%，比当前体量相当的MobileNetV3高约1.9％。该文章原创地研究了如何通过同时改变分辨率、深度和宽度来生成微小且有效的神经网络。",{"type":17,"tag":25,"props":149,"children":150},{},[151],{"type":17,"tag":152,"props":153,"children":154},"strong",{},[155],{"type":17,"tag":152,"props":156,"children":157},{},[158],{"type":23,"value":159},"图像分辨率，模型深度和宽度对精度的影响",{"type":17,"tag":25,"props":161,"children":162},{},[163,165],{"type":23,"value":164},"****图像分辨率，模型深度和宽度(Resolution, Depth, Width, 或r, d, w)",{"type":17,"tag":152,"props":166,"children":167},{},[168],{"type":23,"value":169},"是影响卷积神经网络性能的三个关键因素。但是，哪一种对性能影响更大现在并没有一个明确的结论。为了探究这个问题，我们选取了EfficientNet-B0作为基线模型，并约定其计算量为C0 FLOPs。之后，依据EfficientNet的放缩方式我们进一步得到了计算量为0.5C0的EfficientNet-B-1。我们进一步约定EfficientNet-B-1的分辨率、深度和宽度为单位1。为了在0.5C0 FLOPs这个计算量限制附近进行搜索，我们随机地改变分辨率和模型深度，并调整模型宽度w=，使新产生的模型有约0.5C0 FLOPs的计算量，这些随机搜索的模型在ImageNet-100数据集上训练了的100个epochs，训练结果如图2所示。",{"type":17,"tag":25,"props":171,"children":172},{},[173],{"type":17,"tag":152,"props":174,"children":175},{},[176],{"type":17,"tag":68,"props":177,"children":179},{"alt":7,"src":178},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/8d7567c517dd4e8fa05b066d9e76a92e.jpg",[],{"type":17,"tag":25,"props":181,"children":182},{},[183],{"type":17,"tag":152,"props":184,"children":185},{},[186],{"type":23,"value":187},"图2：在200M FLOPs的约束下，调整模型三维（图片分辨率，模型深度和宽度）对精度的影响",{"type":17,"tag":25,"props":189,"children":190},{},[191],{"type":17,"tag":152,"props":192,"children":193},{},[194],{"type":23,"value":195},"我们发现，高精度模型的输入图像分辨率大约在0.8到1.4之间。当r \u003C 0.8时，分辨率越大，精度越高，而当r > 1.4时精度略微下降。在深度方面，高性能的模型深度从0.5到2不等。当固定计算量时，模型宽度与精度大致呈负相关。好模型主要分布在w \u003C 1处。从图2中我们也发现EfficientNet-B-1精度只有75.8%，精度比相同计算量下的最佳模型要差很多。因此我们需要探索一种新的模型放缩公式，在计算量的约束下获得更好的模型。",{"type":17,"tag":25,"props":197,"children":198},{},[199],{"type":17,"tag":152,"props":200,"children":201},{},[202],{"type":17,"tag":152,"props":203,"children":204},{},[205],{"type":23,"value":206},"探索最优Tiny Formula",{"type":17,"tag":25,"props":208,"children":209},{},[210],{"type":17,"tag":152,"props":211,"children":212},{},[213],{"type":23,"value":214},"对于给定的具有 FLOPs的神经网络（0 \u003C c \u003C 1，c是计算量系数），我们的目标是提供用于收缩模型的三维: r, d, w的最优值。",{"type":17,"tag":25,"props":216,"children":217},{},[218],{"type":17,"tag":152,"props":219,"children":220},{},[221],{"type":17,"tag":68,"props":222,"children":224},{"alt":7,"src":223},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/2ef78a303fdf454dbe52ee7675183eca.jpg",[],{"type":17,"tag":25,"props":226,"children":227},{},[228],{"type":17,"tag":152,"props":229,"children":230},{},[231],{"type":23,"value":232},"其中f1(·)、f2(·)、f3(·)为计算三个维度的函数。",{"type":17,"tag":25,"props":234,"children":235},{},[236],{"type":17,"tag":152,"props":237,"children":238},{},[239],{"type":23,"value":240},"为了寻找这样的函数，我们从[0.25,4]这个区间内对r, d, w进行随机采样，采样出n个参数组合。根据参数组合对基础模型的r, d, w进行改变，得到n个新模型，同时计算出n个新模型的计算量。我们根据计算量和精度，从这n个新模型中选出在帕累托前沿的m个模型（m \u003C= n），这m个模型是我们需要的优秀模型，从而得到其r, d, w与计算量之间的关系。比如，我们得到三个关系如下所示：",{"type":17,"tag":25,"props":242,"children":243},{},[244],{"type":17,"tag":152,"props":245,"children":246},{},[247],{"type":17,"tag":68,"props":248,"children":250},{"alt":7,"src":249},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/ed5f88b4aaeb496caebba14ef6ce1f2b.jpg",[],{"type":17,"tag":25,"props":252,"children":253},{},[254],{"type":17,"tag":152,"props":255,"children":256},{},[257],{"type":23,"value":258},"图3.帕累托前沿模型的三维（图片分辨率，模型深度和宽度）与计算量的关系",{"type":17,"tag":25,"props":260,"children":261},{},[262],{"type":17,"tag":152,"props":263,"children":264},{},[265],{"type":23,"value":266},"我们使用高斯过程回归来拟合上述3张图的3个曲线。以分辨率r为例，图中的m个点的横纵坐标分别为计算量FLOPs",{"type":17,"tag":25,"props":268,"children":269},{},[270],{"type":17,"tag":152,"props":271,"children":272},{},[273],{"type":17,"tag":68,"props":274,"children":276},{"alt":7,"src":275},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/30f18766f0ea4a9dbfaee49e44501798.jpg",[],{"type":17,"tag":25,"props":278,"children":279},{},[280],{"type":17,"tag":152,"props":281,"children":282},{},[283],{"type":23,"value":284},"和分辨率",{"type":17,"tag":25,"props":286,"children":287},{},[288],{"type":17,"tag":152,"props":289,"children":290},{},[291],{"type":17,"tag":68,"props":292,"children":294},{"alt":7,"src":293},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/307116016778429d83fae5dc97f4ee3d.jpg",[],{"type":17,"tag":25,"props":296,"children":297},{},[298],{"type":17,"tag":152,"props":299,"children":300},{},[301],{"type":23,"value":302},"。这m个点作为训练数据，训练数据和测试点c*的联合分布为如下高斯分布：",{"type":17,"tag":25,"props":304,"children":305},{},[306],{"type":17,"tag":152,"props":307,"children":308},{},[309],{"type":17,"tag":68,"props":310,"children":312},{"alt":7,"src":311},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/804c37030a404564922497e29f475e73.jpg",[],{"type":17,"tag":25,"props":314,"children":315},{},[316],{"type":17,"tag":152,"props":317,"children":318},{},[319],{"type":23,"value":320},"其中",{"type":17,"tag":25,"props":322,"children":323},{},[324],{"type":17,"tag":152,"props":325,"children":326},{},[327],{"type":17,"tag":68,"props":328,"children":330},{"alt":7,"src":329},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/97a35d2571084276b27d4a37d723c7e3.jpg",[],{"type":17,"tag":25,"props":332,"children":333},{},[334],{"type":17,"tag":152,"props":335,"children":336},{},[337],{"type":23,"value":338},"有",{"type":17,"tag":25,"props":340,"children":341},{},[342],{"type":17,"tag":152,"props":343,"children":344},{},[345],{"type":17,"tag":68,"props":346,"children":348},{"alt":7,"src":347},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/e41d60463d0f4ec08b690548fa8207b9.jpg",[],{"type":17,"tag":25,"props":350,"children":351},{},[352],{"type":17,"tag":152,"props":353,"children":354},{},[355],{"type":23,"value":356},"，k()是核函数（比如内积函数），",{"type":17,"tag":25,"props":358,"children":359},{},[360],{"type":17,"tag":152,"props":361,"children":362},{},[363],{"type":17,"tag":68,"props":364,"children":366},{"alt":7,"src":365},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/c84db94a45eb49b6a8c208665393482c.jpg",[],{"type":17,"tag":25,"props":368,"children":369},{},[370],{"type":17,"tag":152,"props":371,"children":372},{},[373],{"type":23,"value":374},"，",{"type":17,"tag":25,"props":376,"children":377},{},[378],{"type":17,"tag":152,"props":379,"children":380},{},[381],{"type":17,"tag":68,"props":382,"children":384},{"alt":7,"src":383},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/d7ce7008e83d453186fa86c308b9a3a6.jpg",[],{"type":17,"tag":25,"props":386,"children":387},{},[388],{"type":17,"tag":152,"props":389,"children":390},{},[391],{"type":23,"value":392},"，δ是r的标准差。经过推导，我们可以得到预测值r*，也就是拟合的曲线公式：",{"type":17,"tag":25,"props":394,"children":395},{},[396],{"type":17,"tag":152,"props":397,"children":398},{},[399],{"type":17,"tag":68,"props":400,"children":402},{"alt":7,"src":401},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/bdccb2e6c08a400a879b766811b8fc09.jpg",[],{"type":17,"tag":25,"props":404,"children":405},{},[406],{"type":17,"tag":152,"props":407,"children":408},{},[409],{"type":23,"value":410},"其中：",{"type":17,"tag":25,"props":412,"children":413},{},[414],{"type":17,"tag":152,"props":415,"children":416},{},[417],{"type":17,"tag":68,"props":418,"children":420},{"alt":7,"src":419},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/1492c949acc54ce0bac5a6af64415053.jpg",[],{"type":17,"tag":25,"props":422,"children":423},{},[424],{"type":17,"tag":152,"props":425,"children":426},{},[427],{"type":17,"tag":68,"props":428,"children":430},{"alt":7,"src":429},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/9c67af95b5ff47c999cb8f9ddd6267a8.jpg",[],{"type":17,"tag":25,"props":432,"children":433},{},[434],{"type":17,"tag":152,"props":435,"children":436},{},[437],{"type":23,"value":438},"其他2个曲线公式也可以通过类似的方式得到。",{"type":17,"tag":25,"props":440,"children":441},{},[442],{"type":17,"tag":152,"props":443,"children":444},{},[445],{"type":23,"value":446},"得到了上述拟合曲线公式，用户只要输入想要的计算量c*，就可以得到预测的r*,d*,w*值。通过(r*,d*,w*)对基础模型EfficientNet的宽度、深度和输入分辨率进行改变，就可以得到计算量为c*的TinyNet模型。",{"type":17,"tag":25,"props":448,"children":449},{},[450],{"type":17,"tag":152,"props":451,"children":452},{},[453],{"type":17,"tag":152,"props":454,"children":455},{},[456],{"type":23,"value":457},"实验结果",{"type":17,"tag":25,"props":459,"children":460},{},[461],{"type":17,"tag":152,"props":462,"children":463},{},[464],{"type":23,"value":465},"通过改变计算量系数c的值（c = {0.9, 0.5, 0.25, 0.13, 0.06}）我们生成了5个轻量模型，TinyNet-A 到E。跟已有的方法相比，在同等计算量量的情况下，我们的方法能够得到性能更优的模型。其中，RA表示Random Augmentation, 一种自动数据增强的方法。",{"type":17,"tag":25,"props":467,"children":468},{},[469],{"type":17,"tag":152,"props":470,"children":471},{},[472],{"type":23,"value":473},"表1. TinyNet A-E在 ImageNet数据集上的精度与同样体量的业界领先模型对比",{"type":17,"tag":25,"props":475,"children":476},{},[477],{"type":17,"tag":152,"props":478,"children":479},{},[480],{"type":17,"tag":68,"props":481,"children":483},{"alt":7,"src":482},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/300933e78c684666afdbebb34ae64595.jpg",[],{"type":17,"tag":25,"props":485,"children":486},{},[487],{"type":17,"tag":152,"props":488,"children":489},{},[490],{"type":23,"value":491},"为了更好地体现TinyNet的优势，我们展示了EfficientNetB−4和TinyNet-E的可视化类激活图谱（Class Activation Map），如图4所示，相比于EfficientNetB−4，TinyNet-E会关注图片中更相关的部分。",{"type":17,"tag":25,"props":493,"children":494},{},[495],{"type":17,"tag":152,"props":496,"children":497},{},[498],{"type":17,"tag":68,"props":499,"children":501},{"alt":7,"src":500},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/32064491f675443983786dd93aa1a1ae.jpg",[],{"type":17,"tag":25,"props":503,"children":504},{},[505],{"type":17,"tag":152,"props":506,"children":507},{},[508],{"type":23,"value":509},"图4：TinyNet-E和EfficientNetB−4类激活图谱（Class Activation Map）对比",{"type":17,"tag":25,"props":511,"children":512},{},[513],{"type":17,"tag":152,"props":514,"children":515},{},[516],{"type":23,"value":517},"TinyNet提出的缩放方法具有很好的泛化性。除了EfficientNet-B0之外，我们还应用了我们的方法来压缩ResNet的网络架构的规模。采用ResNet-50模型作为基线模型，我们应用了EfficientNet和我们的方法对模型进行压缩。在ImageNet-100上的结果如表2所示。我们的模型总体上优于其他模型，表明所提出的‘tiny formula’的有效性。",{"type":17,"tag":25,"props":519,"children":520},{},[521],{"type":17,"tag":152,"props":522,"children":523},{},[524],{"type":23,"value":525},"表2. ImageNet-100数据集上使用不同方法压缩ResNet的精度对比",{"type":17,"tag":25,"props":527,"children":528},{},[529],{"type":17,"tag":152,"props":530,"children":531},{},[532],{"type":17,"tag":68,"props":533,"children":535},{"alt":7,"src":534},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/e94b63dabac44cf99da29faef53c9f99.jpg",[],{"type":17,"tag":25,"props":537,"children":538},{},[539],{"type":17,"tag":152,"props":540,"children":541},{},[542],{"type":23,"value":543},"我们也把TinyNet应用到目标检测任务中。从表3的结果可以看出，我们的TinyNet-D与EfficientNet-B-3相比，其性能大大占优，且计算成本相当。",{"type":17,"tag":25,"props":545,"children":546},{},[547],{"type":17,"tag":152,"props":548,"children":549},{},[550],{"type":23,"value":551},"表3. MS COCO数据集上结果对比",{"type":17,"tag":25,"props":553,"children":554},{},[555],{"type":17,"tag":152,"props":556,"children":557},{},[558],{"type":17,"tag":68,"props":559,"children":561},{"alt":7,"src":560},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/efa7622bc9f1438c96eacd16fd18301a.jpg",[],{"type":17,"tag":25,"props":563,"children":564},{},[565],{"type":17,"tag":152,"props":566,"children":567},{},[568],{"type":17,"tag":152,"props":569,"children":570},{},[571],{"type":17,"tag":152,"props":572,"children":573},{},[574],{"type":23,"value":575},"MindSpore 代码实现",{"type":17,"tag":25,"props":577,"children":578},{},[579],{"type":17,"tag":152,"props":580,"children":581},{},[582],{"type":17,"tag":152,"props":583,"children":584},{},[585,587],{"type":23,"value":586},"相关训练与推理代码，以及使用方法已经开源在：",{"type":17,"tag":36,"props":588,"children":590},{"href":107,"rel":589},[40],[591],{"type":23,"value":107},{"type":17,"tag":25,"props":593,"children":594},{},[595],{"type":17,"tag":152,"props":596,"children":597},{},[598],{"type":17,"tag":152,"props":599,"children":600},{},[601],{"type":23,"value":602},"为了方便大家验证我们的结果，以及创新，我们将模型的结构，以及超参数的设置汇总到了相关代码仓的/script文件夹，我们同时提供了多卡分布式训练的启动脚本。参数设置以单卡训练脚本train_1p_gpu.sh为例：",{"type":17,"tag":25,"props":604,"children":605},{},[606],{"type":17,"tag":152,"props":607,"children":608},{},[609],{"type":17,"tag":152,"props":610,"children":611},{},[612],{"type":17,"tag":68,"props":613,"children":615},{"alt":7,"src":614},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/df7a9b239f48482e858eedab0a35e63b.jpg",[],{"type":17,"tag":25,"props":617,"children":618},{},[619],{"type":17,"tag":152,"props":620,"children":621},{},[622],{"type":17,"tag":152,"props":623,"children":624},{},[625],{"type":23,"value":626},"如果想切换其他的TinyNet模型，只需在—model的位置将模型从tinynet_c更改即可。",{"type":17,"tag":25,"props":628,"children":629},{},[630],{"type":17,"tag":152,"props":631,"children":632},{},[633],{"type":17,"tag":152,"props":634,"children":635},{},[636],{"type":23,"value":637},"相关模型结构定义在/src/tinynet.py中：",{"type":17,"tag":25,"props":639,"children":640},{},[641],{"type":17,"tag":152,"props":642,"children":643},{},[644],{"type":17,"tag":152,"props":645,"children":646},{},[647],{"type":17,"tag":68,"props":648,"children":650},{"alt":7,"src":649},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/bad0b5c3bd114652bc55d4a0176b4e73.jpg",[],{"type":17,"tag":25,"props":652,"children":653},{},[654],{"type":17,"tag":152,"props":655,"children":656},{},[657],{"type":17,"tag":152,"props":658,"children":659},{},[660],{"type":23,"value":661},"其中EfficientNet-B0为基线模型，它的输入图像分辨率，宽度和深度三维值为（1，1，1）。",{"type":17,"tag":25,"props":663,"children":664},{},[665],{"type":17,"tag":152,"props":666,"children":667},{},[668],{"type":17,"tag":152,"props":669,"children":670},{},[671,673,678,680,692,694,699],{"type":23,"value":672},"TinyNet模型沿用了EfficientNet的模块化设计，其中又分为",{"type":17,"tag":152,"props":674,"children":675},{},[676],{"type":23,"value":677},"DepthwiseSeparableConv",{"type":23,"value":679}," , ",{"type":17,"tag":152,"props":681,"children":682},{},[683,685,690],{"type":23,"value":684},"InvertedResidual，SqueezeExcite，DropConnect，",{"type":17,"tag":152,"props":686,"children":687},{},[688],{"type":23,"value":689},"这些模块等。每一个模块都衍生自",{"type":23,"value":691},"mindspore.nn.Cell",{"type":23,"value":693},"。这些模块统一在",{"type":17,"tag":152,"props":695,"children":696},{},[697],{"type":23,"value":698},"GenEfficientNet",{"type":23,"value":700},"中被调用，并依据用户给出的图像分辨率，宽度和深度三个数值生成神经网络。MindSpore的网络定义请参考：",{"type":17,"tag":25,"props":702,"children":703},{},[704],{"type":17,"tag":152,"props":705,"children":706},{},[707],{"type":17,"tag":152,"props":708,"children":709},{},[710],{"type":17,"tag":36,"props":711,"children":714},{"href":712,"rel":713},"https://www.mindspore.cn/tutorial/training/zh-CN/master/use/defining_the_network.html",[40],[715],{"type":23,"value":712},{"type":17,"tag":25,"props":717,"children":718},{},[719],{"type":17,"tag":152,"props":720,"children":721},{},[722],{"type":17,"tag":152,"props":723,"children":724},{},[725,727,732],{"type":23,"value":726},"数据集的加载定义在了/src/dataset.py中，主要使用了MindSpore强大的数据集加载和处理工具",{"type":17,"tag":152,"props":728,"children":729},{},[730],{"type":23,"value":731},"mindspore.dataset",{"type":23,"value":733},"。具体使用方法大家可以参考：",{"type":17,"tag":25,"props":735,"children":736},{},[737],{"type":17,"tag":152,"props":738,"children":739},{},[740],{"type":17,"tag":152,"props":741,"children":742},{},[743],{"type":17,"tag":36,"props":744,"children":747},{"href":745,"rel":746},"https://www.mindspore.cn/tutorial/training/en/master/use/load_dataset_image.html",[40],[748],{"type":23,"value":745},{"type":17,"tag":25,"props":750,"children":751},{},[752],{"type":17,"tag":152,"props":753,"children":754},{},[755],{"type":17,"tag":152,"props":756,"children":757},{},[758,760,765],{"type":23,"value":759},"模型权重的指数移动平均(Exponential Moving Average)，模型精度验证和训练数据的记录定义在了/src/callback.py。利用",{"type":17,"tag":152,"props":761,"children":762},{},[763],{"type":23,"value":764},"mindspore.train.callback",{"type":23,"value":766},"模块，用户可以灵活地选择每一步训练或每一轮epochs后希望进行的操作，例如模型验证，Loss打印，模型保存，权重平均等。具体使用方法大家可以参考官网。",{"type":17,"tag":25,"props":768,"children":769},{},[770],{"type":17,"tag":152,"props":771,"children":772},{},[773],{"type":17,"tag":152,"props":774,"children":775},{},[776],{"type":23,"value":777},"最后，我们使用MindSpore Lite工具转换了模型权重，并测试了EfficientNet和TinyNet在华为P40上的推理时延。TinyNet-A比EfficientNet-B0的运行速度快15%，但其精度与EfficientNet-B0相似。TinyNet-E与EfficientNet-B-4相比，在同等时延下，精度提升3.2%。",{"type":17,"tag":25,"props":779,"children":780},{},[781],{"type":17,"tag":152,"props":782,"children":783},{},[784],{"type":17,"tag":152,"props":785,"children":786},{},[787],{"type":23,"value":788},"表4. 手机端推理时延对比",{"type":17,"tag":25,"props":790,"children":791},{},[792],{"type":17,"tag":152,"props":793,"children":794},{},[795],{"type":17,"tag":152,"props":796,"children":797},{},[798],{"type":17,"tag":68,"props":799,"children":801},{"alt":7,"src":800},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2020/12/06/d6dfd74d726847e1a72623cef957eeb3.jpg",[],{"type":17,"tag":25,"props":803,"children":804},{},[805],{"type":17,"tag":152,"props":806,"children":807},{},[808],{"type":17,"tag":152,"props":809,"children":810},{},[811],{"type":23,"value":812},"端测模型转换，部署等请参考：",{"type":17,"tag":25,"props":814,"children":815},{},[816],{"type":17,"tag":152,"props":817,"children":818},{},[819],{"type":17,"tag":152,"props":820,"children":821},{},[822],{"type":17,"tag":36,"props":823,"children":826},{"href":824,"rel":825},"https://www.mindspore.cn/lite",[40],[827],{"type":23,"value":824},{"title":7,"searchDepth":829,"depth":829,"links":830},4,[],"markdown","content:technology-blogs:zh:340.md","content","technology-blogs/zh/340.md","technology-blogs/zh/340","md",1776506129450]