[{"data":1,"prerenderedAt":228},["ShallowReactive",2],{"content-query-rxh13uMwGM":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"cover":11,"type":12,"body":13,"_type":222,"_id":223,"_source":224,"_file":225,"_stem":226,"_extension":227},"/technology-blogs/zh/2941","zh",false,"","极致高效压缩，手机就能实时跑的分割一切模型TinySAM已在昇思MindSpore开源","分割一切模型（Segment Anything Model，SAM）展现出了强大的分割万物能力，但是网络结构复杂，计算代价高，在资源受限的端侧应用中无法直接使用","2024-01-09","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/01/12/df40147aba6741e7920cea232af67d21.png","technology-blogs",{"type":14,"children":15,"toc":211},"root",[16,24,43,48,61,66,77,82,90,100,105,112,117,127,132,139,144,153,158,167,172,179,184,192,197,204],{"type":17,"tag":18,"props":19,"children":21},"element","h1",{"id":20},"极致高效压缩手机就能实时跑的分割一切模型tinysam已在昇思mindspore开源",[22],{"type":23,"value":8},"text",{"type":17,"tag":25,"props":26,"children":27},"p",{},[28,30,36,38],{"type":23,"value":29},"**作者：**",{"type":17,"tag":31,"props":32,"children":33},"strong",{},[34],{"type":23,"value":35},"王云鹤",{"type":23,"value":37}," ｜",{"type":17,"tag":31,"props":39,"children":40},{},[41],{"type":23,"value":42},"来源：知乎",{"type":17,"tag":25,"props":44,"children":45},{},[46],{"type":23,"value":47},"分割一切模型（Segment Anything Model，SAM）展现出了强大的分割万物能力，但是网络结构复杂，计算代价高，在资源受限的端侧应用中无法直接使用。同时，我们发现在SAM的Everything推理模式中，原始的网格点prompt的方式会带来巨大的计算代价。针对这个问题，我们提出了TinySAM模型，利用知识蒸馏、量化等手段对模型做了极致的压缩，同时提出了再Everything推理模式下的层次化推理策略。TinySAM在计算代价降低多个数量级的情况下，仍然保持了SAM模型强大的zero-shot分割能力。",{"type":17,"tag":25,"props":49,"children":50},{},[51,53],{"type":23,"value":52},"论文见：",{"type":17,"tag":54,"props":55,"children":59},"a",{"href":56,"rel":57},"https://arxiv.org/abs/2312.13789",[58],"nofollow",[60],{"type":23,"value":56},{"type":17,"tag":25,"props":62,"children":63},{},[64],{"type":23,"value":65},"同时我们开源了TinySAM的MindSpore代码和模型，供大家试用：",{"type":17,"tag":25,"props":67,"children":68},{},[69,71],{"type":23,"value":70},"MindSpore代码：",{"type":17,"tag":54,"props":72,"children":75},{"href":73,"rel":74},"https://gitee.com/mindspore/models/tree/master/research/cv/TinySAM",[58],[76],{"type":23,"value":73},{"type":17,"tag":25,"props":78,"children":79},{},[80],{"type":23,"value":81},"下面是demo效果展示，TinySAM在手机端侧可完成给定点或框作为prompt的自动分割功能。",{"type":17,"tag":25,"props":83,"children":84},{},[85],{"type":17,"tag":86,"props":87,"children":89},"img",{"alt":7,"src":88},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/01/12/804b02f3c441451f8c292eb7500d0000.png",[],{"type":17,"tag":91,"props":92,"children":94},"h2",{"id":93},"tinysam-极致高效的分割一切模型",[95],{"type":17,"tag":31,"props":96,"children":97},{},[98],{"type":23,"value":99},"TinySAM: 极致高效的分割一切模型",{"type":17,"tag":25,"props":101,"children":102},{},[103],{"type":23,"value":104},"这个工作通过知识蒸馏、后量化等方法对SAM模型做极致压缩，同时提出一种针对Everything推理的加速方法，探索分割一切模型性能和效率的极限。",{"type":17,"tag":25,"props":106,"children":107},{},[108],{"type":17,"tag":86,"props":109,"children":111},{"alt":7,"src":110},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/01/12/30a6d90a36184b4a8d34431cd917ad15.png",[],{"type":17,"tag":25,"props":113,"children":114},{},[115],{"type":23,"value":116},"图1：(a)展示了TinySAM的框架，通过一种全阶段知识蒸馏、后量化和层次化推理加速方法，模型计算量可以降低到原来的1/50；（b）展示了模型在zero-shot下游分割任务上仍然保持了良好的性能。",{"type":17,"tag":118,"props":119,"children":121},"h3",{"id":120},"_1-全阶段知识蒸馏",[122],{"type":17,"tag":31,"props":123,"children":124},{},[125],{"type":23,"value":126},"(1) 全阶段知识蒸馏",{"type":17,"tag":25,"props":128,"children":129},{},[130],{"type":23,"value":131},"针对分割一切模型多模块、难优化的结构特点，我们提出一种全阶段的知识蒸馏方法，从多个特征层面进行蒸馏学习，从图像特征（embedding）、最终监督特征（mask）、中间过渡特征（token）三个层面进行蒸馏损失的设计，最大程度减少轻量化学生网络的学习难度。",{"type":17,"tag":25,"props":133,"children":134},{},[135],{"type":17,"tag":86,"props":136,"children":138},{"alt":7,"src":137},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/01/12/b8d96b4b8b3941e7b233da02acc7f373.png",[],{"type":17,"tag":25,"props":140,"children":141},{},[142],{"type":23,"value":143},"图2：全阶段知识蒸馏框架",{"type":17,"tag":118,"props":145,"children":147},{"id":146},"_2-模型后量化",[148],{"type":17,"tag":31,"props":149,"children":150},{},[151],{"type":23,"value":152},"(2) 模型后量化",{"type":17,"tag":25,"props":154,"children":155},{},[156],{"type":23,"value":157},"为了进一步降低模型计算量，提升推理效率，我们将TinySAM量化到8bit，其中卷积层和反卷积层采用channel-wise的非对称均匀量化，matmul和linear层分别采用headwise和layerwise的对称均匀量化。在量化策略上，逐层对网络进行串行量化，并采用与任务Loss更一致的hessian guided metric作为量化前后输出的距离度量。量化后的模型计算量能进一步减少到全精度的1/4左右，大幅降低计算量。",{"type":17,"tag":118,"props":159,"children":161},{"id":160},"_3-层次化分割一切",[162],{"type":17,"tag":31,"props":163,"children":164},{},[165],{"type":23,"value":166},"(3) 层次化分割一切",{"type":17,"tag":25,"props":168,"children":169},{},[170],{"type":23,"value":171},"SAM模型在Everything（分割一切）推理模式中，通过密集的网格点作为Prompt进行推理，我们发现这种密集的Prompt输入和推理耗费了大量的计算量。因此，我们设计了一种层次化的分割一切的推理策略。先用较少的初始采样点得到初始结果，然后把高置信度区域的密集采样点移除，得到二次推理结果，与初始推理结果进行后处理融合得到最终的推理结果。这种策略在保持分割一切效果的同时，大幅减少了采样点数量，推理加速一倍左右。",{"type":17,"tag":25,"props":173,"children":174},{},[175],{"type":17,"tag":86,"props":176,"children":178},{"alt":7,"src":177},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/01/12/44e921855c4e4a0884fd7e1b27397925.png",[],{"type":17,"tag":25,"props":180,"children":181},{},[182],{"type":23,"value":183},"图3：我们设计的层次化分割一切推理模式，我们先用较少的采样点得到初始的结果，然后我们把高置信度区域的密集采样点移除，得到二次推理结果后通过后处理与初始结果融合得到最终的分层推理结果。",{"type":17,"tag":91,"props":185,"children":187},{"id":186},"实验结果",[188],{"type":17,"tag":31,"props":189,"children":190},{},[191],{"type":23,"value":186},{"type":17,"tag":25,"props":193,"children":194},{},[195],{"type":23,"value":196},"我们在多个zero-shot下游任务上进行了实验，包括在COCO和LVIS数据集的zero-shot实例分割实验，我们按照SAM论文的设置通过ViTDet得到的检测框作为Prompt输入到TinySAM模型中。相比MobileSAM，TinySAM在COCO的平均准确率提升0.9%，在LVIS的平均准确率能提升1.6%。即使采用8bit量化后，TinySAM仍然保持了性能优势。更多的实验结果和可视化结果请参考论文。",{"type":17,"tag":25,"props":198,"children":199},{},[200],{"type":17,"tag":86,"props":201,"children":203},{"alt":7,"src":202},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/01/12/2bde1587be5346449e8b91648be58012.png",[],{"type":17,"tag":25,"props":205,"children":206},{},[207],{"type":17,"tag":86,"props":208,"children":210},{"alt":7,"src":209},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/01/12/f6c73c7975664e7e99d3fd1f39b4627b.png",[],{"title":7,"searchDepth":212,"depth":212,"links":213},4,[214,221],{"id":93,"depth":215,"text":99,"children":216},2,[217,219,220],{"id":120,"depth":218,"text":126},3,{"id":146,"depth":218,"text":152},{"id":160,"depth":218,"text":166},{"id":186,"depth":215,"text":186},"markdown","content:technology-blogs:zh:2941.md","content","technology-blogs/zh/2941.md","technology-blogs/zh/2941","md",1776506124443]