[{"data":1,"prerenderedAt":570},["ShallowReactive",2],{"content-query-qno7PaTaJi":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"cover":11,"type":12,"category":13,"body":14,"_type":564,"_id":565,"_source":566,"_file":567,"_stem":568,"_extension":569},"/technology-blogs/zh/2824","zh",false,"","论文精讲 | 基于昇思MindSpore实现多域原型对比学习下的泛化联邦原型学习","昇思MindSpore作为一个开源的AI框架，为产学研和开发人员带来端边云全场景协同、极简开发、极致性能，超大规模AI预训练、极简开发、安全可信的体验，","2023-10-13","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/10/20/416cbaeb762b49148eedd39c0a030476.png","technology-blogs","大V博文",{"type":15,"children":16,"toc":556},"root",[17,25,44,49,54,59,64,69,81,86,96,101,113,118,126,134,139,144,149,154,159,167,175,187,199,204,212,220,230,235,240,249,257,265,273,280,285,293,298,306,313,318,326,334,342,349,357,365,374,379,386,395,405,410,417,422,431,436,444,454,462,476,485,493,501,506,511,516,526,536,546],{"type":18,"tag":19,"props":20,"children":22},"element","h1",{"id":21},"论文精讲-基于昇思mindspore实现多域原型对比学习下的泛化联邦原型学习",[23],{"type":24,"value":8},"text",{"type":18,"tag":26,"props":27,"children":28},"p",{},[29,31,37,39],{"type":24,"value":30},"**作者：**",{"type":18,"tag":32,"props":33,"children":34},"strong",{},[35],{"type":24,"value":36},"李锐锋",{"type":24,"value":38}," ｜",{"type":18,"tag":32,"props":40,"children":41},{},[42],{"type":24,"value":43},"来源：知乎",{"type":18,"tag":26,"props":45,"children":46},{},[47],{"type":24,"value":48},"论文标题",{"type":18,"tag":26,"props":50,"children":51},{},[52],{"type":24,"value":53},"Rethinking Federated Learning with Domain Shift: A Prototype View",{"type":18,"tag":26,"props":55,"children":56},{},[57],{"type":24,"value":58},"论文来源",{"type":18,"tag":26,"props":60,"children":61},{},[62],{"type":24,"value":63},"CVPR 2023",{"type":18,"tag":26,"props":65,"children":66},{},[67],{"type":24,"value":68},"论文链接",{"type":18,"tag":26,"props":70,"children":71},{},[72],{"type":18,"tag":73,"props":74,"children":78},"a",{"href":75,"rel":76},"https://openaccess.thecvf.com/content/CVPR2023/papers/Huang%5C_Rethinking%5C_Federated%5C_Learning%5C_With%5C_Domain%5C_Shift%5C_A%5C_Prototype%5C_View%5C_CVPR%5C_2023%5C_paper.pdf",[77],"nofollow",[79],{"type":24,"value":80},"https://openaccess.thecvf.com/content/CVPR2023/papers/Huang\\_Rethinking\\_Federated\\_Learning\\_With\\_Domain\\_Shift\\_A\\_Prototype\\_View\\_CVPR\\_2023\\_paper.pdf",{"type":18,"tag":26,"props":82,"children":83},{},[84],{"type":24,"value":85},"代码链接",{"type":18,"tag":26,"props":87,"children":88},{},[89],{"type":18,"tag":73,"props":90,"children":93},{"href":91,"rel":92},"https://github.com/yuhangchen0/FPL%5C_MS",[77],[94],{"type":24,"value":95},"https://github.com/yuhangchen0/FPL\\_MS",{"type":18,"tag":26,"props":97,"children":98},{},[99],{"type":24,"value":100},"昇思MindSpore作为一个开源的AI框架，为产学研和开发人员带来端边云全场景协同、极简开发、极致性能，超大规模AI预训练、极简开发、安全可信的体验，2020.3.28开源来已超过5百万的下载量，昇思MindSpore已支持数百+AI顶会论文，走入Top100+高校教学，通过HMS在5000+App上商用，拥有数量众多的开发者，在AI计算中心，金融、智能制造、金融、云、无线、数通、能源、消费者1+8+N、智能汽车等端边云车全场景逐步广泛应用，是Gitee指数最高的开源软件。欢迎大家参与开源贡献、套件、模型众智、行业创新与应用、算法创新、学术合作、AI书籍合作等，贡献您在云侧、端侧、边侧以及安全领域的应用案例。",{"type":18,"tag":26,"props":102,"children":103},{},[104,106,111],{"type":24,"value":105},"在科技界、学术界和工业界对昇思MindSpore的广泛支持下，基于昇思MindSpore的AI论文2023年在所有AI框架中占比7%，连续两年进入全球第二，感谢CAAI和各位高校老师支持，我们一起继续努力做好AI科研创新。昇思MindSpore社区支持顶级会议论文研究，持续构建原创AI成果。我会不定期挑选一些优秀的论文来推送和解读，希望更多的产学研专家跟昇思MindSpore合作，一起推动原创AI研究，昇思MindSpore社区会持续支撑好AI创新和AI应用，本文是昇思MindSpore AI顶会论文系列第18篇，我选择了来自武汉大学计算机学院的",{"type":18,"tag":32,"props":107,"children":108},{},[109],{"type":24,"value":110},"叶茫老师",{"type":24,"value":112},"团队的一篇论文解读，感谢各位专家教授同学的投稿。",{"type":18,"tag":26,"props":114,"children":115},{},[116],{"type":24,"value":117},"昇思MindSpore旨在实现易开发、高效执行、全场景覆盖三大目标。通过使用体验，昇思MindSpore这一深度学习框架的发展速度飞快，它的各类API的设计都在朝着更合理、更完整、更强大的方向不断优化。此外，昇思不断涌现的各类开发工具也在辅助这一生态圈营造更加便捷强大的开发手段，例如MindSpore Insight，它可以将模型架构以图的形式呈现出来，也可以动态监控模型运行时各个指标和参数的变化，使开发过程更加方便。",{"type":18,"tag":26,"props":119,"children":120},{},[121],{"type":18,"tag":32,"props":122,"children":123},{},[124],{"type":24,"value":125},"01",{"type":18,"tag":26,"props":127,"children":128},{},[129],{"type":18,"tag":32,"props":130,"children":131},{},[132],{"type":24,"value":133},"研究背景",{"type":18,"tag":26,"props":135,"children":136},{},[137],{"type":24,"value":138},"在数字化的世界中，数据隐私和安全性成为了日益关注的核心议题。正是在这样的背景下，联邦学习应运而生，作为一种保护数据隐私的分布式机器学习方法，其核心思想是让多个设备或服务器共同训练一个模型，而无需共享原始数据。这种方法可以应对多台移动设备上的机器学习任务，特别是在数据隐私和安全性需求高的情况下。",{"type":18,"tag":26,"props":140,"children":141},{},[142],{"type":24,"value":143},"联邦学习中有个重要的待解决的问题：数据异构性。通常指的是参与学习的各节点（例如设备、服务器或组织）持有的数据可能存在巨大的差异。这些差异可能涉及数据的分布、质量、数量以及特征类型等多个方面。数据异构性问题在联邦学习中尤为重要，因为它可能直接影响模型的学习效果和泛化能力。",{"type":18,"tag":26,"props":145,"children":146},{},[147],{"type":24,"value":148},"本文指出，针对数据异构，现有的解决方案主要关注来自同一领域的所有私有数据。当分布式数据来源于不同的领域时，私有模型在其他领域（存在领域偏移）上容易展现出退化的性能，而且全局信号无法捕获丰富公平的领域信息。因此，作者期望在联邦学习过程中通过优化的全局模型能够稳定地在多个领域上提供泛化性能。",{"type":18,"tag":26,"props":150,"children":151},{},[152],{"type":24,"value":153},"在本文中，作者提出了一种针对领域偏移下的联邦学习的“联邦原型学习”(FPL)。核心思想是构建集群原型和无偏原型，提供丰富的领域知识和公平的收敛目标。一方面，将样本嵌入远离来自不同类别的群集原型，更接近于相同语义的群集原型。另一方面，引入了一致性正则化，以使本地实例与相应的无偏原型对齐。",{"type":18,"tag":26,"props":155,"children":156},{},[157],{"type":24,"value":158},"论文基于昇思MindSpore进行框架开发和实验，Digits和Office Caltech任务等实验结果证明了所提出的解决方案的有效性和关键模块的高效性。",{"type":18,"tag":26,"props":160,"children":161},{},[162],{"type":18,"tag":32,"props":163,"children":164},{},[165],{"type":24,"value":166},"02",{"type":18,"tag":26,"props":168,"children":169},{},[170],{"type":18,"tag":32,"props":171,"children":172},{},[173],{"type":24,"value":174},"团队介绍",{"type":18,"tag":26,"props":176,"children":177},{},[178,180,185],{"type":24,"value":179},"论文第一作者",{"type":18,"tag":32,"props":181,"children":182},{},[183],{"type":24,"value":184},"黄文柯",{"type":24,"value":186},"目前硕博连读于武汉大学（2021-至今），导师为杜博教授和叶茫教授。本科毕业于武汉大学，主要研究方向包括联邦学习，图学习，金融科技等，目前在CVPR、IJCAI、ACM MM 国际顶级会议上以第一作者发表论文4篇。研究生期间获得国泰君安奖学金、优秀研究生等称号。曾在阿里巴巴集团、微软亚洲研究院等担任研究实习生。",{"type":18,"tag":26,"props":188,"children":189},{},[190,192,197],{"type":24,"value":191},"论文通讯作者",{"type":18,"tag":32,"props":193,"children":194},{},[195],{"type":24,"value":196},"叶茫",{"type":24,"value":198},"是武汉大学计算机学院教授、博士生导师，国家级高层次青年人才，中国科协青年托举人才。曾任阿联酋起源人工智能研究院研究科学家和美国哥伦比亚大学访问学者。主要研究方向计算机视觉、多媒体检索、联邦学习等，发表国际期刊会议论文 80 余篇，ESI 高被引论文 10 篇，谷歌学术引用 5600 余次。担任CVPR24、ACM MM23等学术会议领域主席。主持湖北省重点研发计划、国家自然科学基金面上项目等科研项目。获谷歌优秀奖学金、国际计算机视觉顶会 ICCV2021无人机目标重识别赛道冠军、2021-2022年斯坦福排行榜 “全球前2%顶尖科学家”、2022年百度AI华人青年学者等荣誉。。",{"type":18,"tag":26,"props":200,"children":201},{},[202],{"type":24,"value":203},"研究团队MARS是由叶茫教授指导的专注研究监控视频行人/行为分析、无监督/半监督学习、跨模态理解与推理、联邦学习。",{"type":18,"tag":26,"props":205,"children":206},{},[207],{"type":18,"tag":32,"props":208,"children":209},{},[210],{"type":24,"value":211},"03",{"type":18,"tag":26,"props":213,"children":214},{},[215],{"type":18,"tag":32,"props":216,"children":217},{},[218],{"type":24,"value":219},"论文简介",{"type":18,"tag":221,"props":222,"children":224},"h3",{"id":223},"_31-介绍",[225],{"type":18,"tag":32,"props":226,"children":227},{},[228],{"type":24,"value":229},"3.1 介绍",{"type":18,"tag":26,"props":231,"children":232},{},[233],{"type":24,"value":234},"基于前述的研究背景，本文提出联邦原型学习(Federated Prototype Learning)，用于解决联邦多域泛化问题：私有数据来源于不同领域，不同的客户端存在差异较大的特征分布，由于本地模型会过度拟合本地分布，私有模型无法在其他领域表现好。比如说，一个在灰度图像MNIST上训练的本地模型A，在被服务器端聚合后，不能在另一个比如彩色图像SVHN数据集的客户端中表现正常，因为这个本地模型A无法学习到SVHN的领域信息，导致性能退化。",{"type":18,"tag":26,"props":236,"children":237},{},[238],{"type":24,"value":239},"由于全局信号无法表征多个领域的知识信息，并且可能偏向主导领域的信息，导致泛化能力下降。为了让模型学习到丰富的多领域知识，使用共有信号提供多个领域信息提升泛化能力，本文提出利用集群原型表征不同领域信息，利用对比学习，增强不同领域相同类别共性，增强不同类别差异性，称为集群原型对比学习（Cluster Prototypes Contrastive Learning）；为了避免朝潜在主导域优化，提升在少数域上的能力，本文利无偏原型提供公平稳定的信息，称为无偏原型一致性正则化（Unbiased Prototypes Consistent Regularization）。",{"type":18,"tag":26,"props":241,"children":242},{},[243],{"type":18,"tag":244,"props":245,"children":248},"img",{"alt":246,"src":247},"cke_863.png","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231019031730.91617863481869698306243994512097:50541019070811:2400:28B550646B0EEBB7B1AEE0E0FA88936F223E9A7165D2A376BCAAAA3E67CAD406.png",[],{"type":18,"tag":26,"props":250,"children":251},{},[252],{"type":18,"tag":244,"props":253,"children":256},{"alt":254,"src":255},"image.png","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231019031744.58882991438384449811645051447603:50541019070811:2400:4CAA4A4C5A63ECA55540EAE6301663E872AEE62B7C40B46113F3BB06D81A570D.png",[],{"type":18,"tag":26,"props":258,"children":259},{},[260],{"type":18,"tag":244,"props":261,"children":264},{"alt":262,"src":263},"cke_3032.png","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231019031821.75229071887708718559958393750953:50541019070811:2400:8D1EEA8FD5B2B30C0AA64DA28B687BF7E6EA2EC2591911BF78DC52AF4C444245.png",[],{"type":18,"tag":26,"props":266,"children":267},{},[268],{"type":18,"tag":244,"props":269,"children":272},{"alt":270,"src":271},"cke_4213.png","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231019031840.67306365866110726052178057266090:50541019070811:2400:85BE845A2A7DF9C243633DBF75069830D443D48DCDD5897401E883A0C2D830F5.png",[],{"type":18,"tag":26,"props":274,"children":275},{},[276],{"type":18,"tag":244,"props":277,"children":279},{"alt":254,"src":278},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231019031849.51306195136654969975702250099446:50541019070811:2400:F476FC1AD34B5560895AF0C7575EB920F2DB43F1D89C5B3AA3E6CD7928EB658C.png",[],{"type":18,"tag":26,"props":281,"children":282},{},[283],{"type":24,"value":284},"图2 不同种类原型表示",{"type":18,"tag":26,"props":286,"children":287},{},[288],{"type":18,"tag":32,"props":289,"children":290},{},[291],{"type":24,"value":292},"3.2.2 集群原型对比学习",{"type":18,"tag":26,"props":294,"children":295},{},[296],{"type":24,"value":297},"为了解决全局原型存在的问题，本文首先使用FINCH方法进行无监督聚类，将广泛的领域知识（每个样本的特征向量）无监督地进行分离，如此一来，来自于不同域的样本由于各自特征向量存在差异，不同的领域将被聚类为不同的集群，然后对同一集群内计算这个集群的原型，如图2b，防止多域之间相互平均后远离所有有用的领域知识。",{"type":18,"tag":26,"props":299,"children":300},{},[301],{"type":18,"tag":244,"props":302,"children":305},{"alt":303,"src":304},"cke_7930.png","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231019031920.50816860714422657145275998416342:50541019070811:2400:06EC6A99847B6221923D431D7B2D24BBAF3C472E9B7290B66EA3EC38D21724CD.png",[],{"type":18,"tag":26,"props":307,"children":308},{},[309],{"type":18,"tag":244,"props":310,"children":312},{"alt":254,"src":311},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231019031933.43222004236571407897224943445439:50541019070811:2400:1D9B6CD6C82FC6F66920B68AD8125D4E96E0EC6155438BEDAF52B4FA0566F08D.png",[],{"type":18,"tag":26,"props":314,"children":315},{},[316],{"type":24,"value":317},"为什么这种方法有效呢？作者给出下面的分析：",{"type":18,"tag":26,"props":319,"children":320},{},[321],{"type":18,"tag":244,"props":322,"children":325},{"alt":323,"src":324},"cke_12413.png","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231019032010.28138790868005089194472595274257:50541019070811:2400:26CB687B332AFA72E4094201555D89DD450C576221810631B1D6277A8EAC1E77.png",[],{"type":18,"tag":26,"props":327,"children":328},{},[329],{"type":18,"tag":244,"props":330,"children":333},{"alt":331,"src":332},"cke_14493.png","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231019032039.70757904927202792995485444549278:50541019070811:2400:06A42A5EDF56CAB1473F66CEF25DDA9230F1B81C02995C310597805949BD46AA.png",[],{"type":18,"tag":26,"props":335,"children":336},{},[337],{"type":18,"tag":244,"props":338,"children":341},{"alt":339,"src":340},"cke_16687.png","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231019032059.79944278683461908702825568120402:50541019070811:2400:F13EADAB1A9EF1082BF87B2E5D7146349B4A0E864007335003D956C233009278.png",[],{"type":18,"tag":26,"props":343,"children":344},{},[345],{"type":18,"tag":244,"props":346,"children":348},{"alt":254,"src":347},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231019032124.46808486470510874687277551066875:50541019070811:2400:77D567D07C08374E087AE6EDF7B0A344E5A52DB2F8BEC10CA92DDD5D8AF7D0A2.png",[],{"type":18,"tag":26,"props":350,"children":351},{},[352],{"type":18,"tag":32,"props":353,"children":354},{},[355],{"type":24,"value":356},"04",{"type":18,"tag":26,"props":358,"children":359},{},[360],{"type":18,"tag":32,"props":361,"children":362},{},[363],{"type":24,"value":364},"实验结果",{"type":18,"tag":221,"props":366,"children":368},{"id":367},"_41-与state-of-the-art的实验结果对比",[369],{"type":18,"tag":32,"props":370,"children":371},{},[372],{"type":24,"value":373},"4.1 与State-of-the-art的实验结果对比",{"type":18,"tag":26,"props":375,"children":376},{},[377],{"type":24,"value":378},"本文在Digits和Office Caltech数据集下进行测试，前者是数字的4种相同标签不同数据来源的数据集，后者是真实世界的4种相同标签不同数据来源的数据集。实验表明所提出的FPL不论是在单个领域上的性能还是多个领域上的平均性能，都优于当前SOTA。",{"type":18,"tag":26,"props":380,"children":381},{},[382],{"type":18,"tag":244,"props":383,"children":385},{"alt":254,"src":384},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231019032144.08831363257557380686234456085991:50541019070811:2400:079DC6558AB82B08DCDBC9C09D824A415C54DEBA8C7C35A9AF9A2D891E05BA37.png",[],{"type":18,"tag":221,"props":387,"children":389},{"id":388},"_42-消融实验",[390],{"type":18,"tag":32,"props":391,"children":392},{},[393],{"type":24,"value":394},"4.2 消融实验",{"type":18,"tag":26,"props":396,"children":397},{},[398],{"type":18,"tag":32,"props":399,"children":400},{},[401],{"type":18,"tag":244,"props":402,"children":404},{"alt":254,"src":403},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231019032200.99245365763031804003285981995880:50541019070811:2400:1DEDA79192C63435A10869A3F22F875A0A9375F3FD8122E347110E18C47B703D.png",[],{"type":18,"tag":26,"props":406,"children":407},{},[408],{"type":24,"value":409},"可以看出大部分情况下CPCL和UPCR共同作用能产生更好的性能。",{"type":18,"tag":26,"props":411,"children":412},{},[413],{"type":18,"tag":244,"props":414,"children":416},{"alt":254,"src":415},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231019032217.33699739020867315547583006805875:50541019070811:2400:12DB5085B7C47A82F394D69688E28073DF6BC5C20E12F3A28938873CC90C02A2.png",[],{"type":18,"tag":26,"props":418,"children":419},{},[420],{"type":24,"value":421},"比较两种方法采用普通的全局原型和所提出的原型所展示出的实验效果，表明集群原型和无偏原型的有效性。",{"type":18,"tag":221,"props":423,"children":425},{"id":424},"_43-昇思mindspore代码展示",[426],{"type":18,"tag":32,"props":427,"children":428},{},[429],{"type":24,"value":430},"4.3 昇思MindSpore代码展示",{"type":18,"tag":26,"props":432,"children":433},{},[434],{"type":24,"value":435},"本框架基于昇思MindSpore进行开发。",{"type":18,"tag":26,"props":437,"children":438},{},[439],{"type":18,"tag":32,"props":440,"children":441},{},[442],{"type":24,"value":443},"4.3.1 昇思MindSpore实现集群原型对比学习",{"type":18,"tag":26,"props":445,"children":446},{},[447],{"type":18,"tag":448,"props":449,"children":451},"code",{"className":450},[],[452],{"type":24,"value":453},"def calculate_infonce(self, f_now, label, all_f, all_global_protos_keys):         pos_indices = 0         neg_indices = []         for i, k in enumerate(all_global_protos_keys):             if k == label.item():                 pos_indices = i             else:                 neg_indices.append(i)          f_pos = Tensor(all_f[pos_indices][0]).reshape(1,512)         f_neg = ops.cat([Tensor(all_f[i]).reshape(-1, 512) for i in neg_indices], axis=0)         #aaa         f_proto = ops.cat((f_pos, f_neg), axis=0)         f_now = f_now.reshape(1,512)          f_now_np = f_now.asnumpy()         f_proto_np = f_proto.asnumpy()         def cosine_similarity_numpy(vec_a, vec_b):             dot_product = np.dot(vec_a, vec_b.T)             norm_a = np.linalg.norm(vec_a, axis=1, keepdims=True)             norm_b = np.linalg.norm(vec_b, axis=1)             return dot_product / (norm_a * norm_b)         l_np = cosine_similarity_numpy(f_now_np, f_proto_np)         l = Tensor(l_np)          #l = ops.cosine_similarity(f_now, f_proto, dim=1)         l = ops.div(l, self.infoNCET)          exp_l = ops.exp(l).reshape(1, -1)          pos_num = f_pos.shape[0]         neg_num = f_neg.shape[0]         pos_mask = Tensor([1] * pos_num + [0] * neg_num).reshape(1, -1)          pos_l = exp_l * pos_mask         sum_pos_l = ops.sum(pos_l, dim=1)         sum_exp_l = ops.sum(exp_l, dim=1)         infonce_loss = -ops.log(sum_pos_l / sum_exp_l)         return Tensor(infonce_loss)",{"type":18,"tag":26,"props":455,"children":456},{},[457],{"type":18,"tag":244,"props":458,"children":461},{"alt":459,"src":460},"cke_36194.png","https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/e64/154/b38/90a1d5d431e64154b387b3660e356ff5.20231019032302.92046520696083882664194186318777:50541019070811:2400:CA5E6C00CDFF95F886A32C74876861372CEBC716E3BCD26B22B0DC5BB32131C4.png",[],{"type":18,"tag":26,"props":463,"children":464},{},[465],{"type":18,"tag":32,"props":466,"children":467},{},[468],{"type":18,"tag":32,"props":469,"children":470},{},[471],{"type":18,"tag":32,"props":472,"children":473},{},[474],{"type":24,"value":475},"4.3.3 客户端本地模型训练",{"type":18,"tag":26,"props":477,"children":478},{},[479],{"type":18,"tag":448,"props":480,"children":482},{"className":481},[],[483],{"type":24,"value":484},"def _train_net(self, index, net, train_loader):          if len(self.global_protos) != 0:             all_global_protos_keys = np.array(list(self.global_protos.keys()))             all_f = []             mean_f = []             for protos_key in all_global_protos_keys:                 temp_f = self.global_protos[protos_key]                 all_f.append(copy.deepcopy(temp_f))                 mean_f.append(copy.deepcopy(np.mean(temp_f, axis=0)))             all_f = [item.copy() for item in all_f]             mean_f = [item.copy() for item in mean_f]         else:             all_f = []             mean_f = []             all_global_protos_keys = []                  optimizer = nn.SGD(net.trainable_params(), learning_rate=self.local_lr, momentum=0.9, weight_decay=1e-5)         criterion1 = nn.SoftmaxCrossEntropyWithLogits(sparse=True, reduction='mean')         criterion = CustomLoss(criterion1, self.loss2)         self.loss_mse = mindspore.nn.MSELoss()         train_net= nn.TrainOneStepCell(nn.WithLossCell(net,criterion), optimizer=optimizer)         train_net.set_train(True)          iterator = tqdm(range(self.local_epoch))         for iter in iterator:              agg_protos_label = {}             for di in train_loader.create_dict_iterator():                 images = di[\"image\"]                 labels = di[\"label\"]                  #   train_net.set_train(False)                 f = net.features(images)                 #train_net.set_train(True)                  if len(self.global_protos) == 0:                     loss_InfoNCE = 0                  else:                     i = 0                     loss_InfoNCE = None                      for label in labels:                         if label in all_global_protos_keys:                              f_now = f[i]                             cu_info_loss = self.hierarchical_info_loss(f_now, label, mean_f, all_global_protos_keys)                             xi_info_loss = self.calculate_infonce(f",{"type":18,"tag":26,"props":486,"children":487},{},[488],{"type":18,"tag":32,"props":489,"children":490},{},[491],{"type":24,"value":492},"05",{"type":18,"tag":26,"props":494,"children":495},{},[496],{"type":18,"tag":32,"props":497,"children":498},{},[499],{"type":24,"value":500},"总结与展望",{"type":18,"tag":26,"props":502,"children":503},{},[504],{"type":24,"value":505},"在本文中，我们探讨了在异构联邦学习中领域转移下的泛化性和稳定性问题。我们的研究引入了一个简单而有效的联邦学习算法，即联邦原型学习（FPL）。我们利用原型（类的典型表示）来解决这两个问题，享受集群原型和无偏原型的互补优势：多样的领域知识和稳定的收敛信号。我们使用昇思MindSpore架构实现了FPL框架并展现其在效率和准确性上的优势。",{"type":18,"tag":26,"props":507,"children":508},{},[509],{"type":24,"value":510},"在使用昇思MindSpore进行FPL框架开发中，我们注意到昇思MindSpore社区非常活跃，有许多华为开发者和使用者针对我们框架搭建中遇到的困难提供巨大帮助。不仅如此，借助昇思MindSpore提供的丰富的文档和教程以及社区中的实际案例和最佳实践，我们避免了许多潜在的陷阱，更快地达到了我们的研究目标。",{"type":18,"tag":26,"props":512,"children":513},{},[514],{"type":24,"value":515},"往期回顾",{"type":18,"tag":26,"props":517,"children":518},{},[519],{"type":18,"tag":73,"props":520,"children":523},{"href":521,"rel":522},"http://mp.weixin.qq.com/s?__biz=MzkxMTM2MjMzNg==&mid=2247609225&idx=2&sn=1700ef8a970b411bf878ea5155970c27&chksm=c11e3bc6f669b2d06066e7ba763832232783e2a4e600f14342622d6bca732c7cf01811486539&scene=21#wechat_redirect",[77],[524],{"type":24,"value":525},"论文精讲 | 基于昇思的等夹角向量基（EBVs）分类性能显著优于传统分类器详解",{"type":18,"tag":26,"props":527,"children":528},{},[529],{"type":18,"tag":73,"props":530,"children":533},{"href":531,"rel":532},"http://mp.weixin.qq.com/s?__biz=MzkxMTM2MjMzNg==&mid=2247606684&idx=1&sn=227d63a96075c1cc684806e223001ba1&chksm=c11e31d3f669b8c51da1bfbcdb528923356ee29ef4eefd15d42ceb9e2e6bd61ca479ffa64e6d&scene=21#wechat_redirect",[77],[534],{"type":24,"value":535},"论文精讲 | 基于昇思MindSpore的零售商品视觉结算原型学习PLACO，实现准确率提升2.89%",{"type":18,"tag":26,"props":537,"children":538},{},[539],{"type":18,"tag":73,"props":540,"children":543},{"href":541,"rel":542},"http://mp.weixin.qq.com/s?__biz=MzkxMTM2MjMzNg==&mid=2247604942&idx=2&sn=4aebf801a876b8eec6eb6405a1340b6b&chksm=c11e4a81f669c39710a29bf3ea3ff3c6dab3464331524772d8dd29cd09f907c1079529fc9084&scene=21#wechat_redirect",[77],[544],{"type":24,"value":545},"论文精讲 | 使用稀疏Ising机训练深度玻尔兹曼网络",{"type":18,"tag":26,"props":547,"children":548},{},[549],{"type":18,"tag":73,"props":550,"children":553},{"href":551,"rel":552},"http://mp.weixin.qq.com/s?__biz=MzkxMTM2MjMzNg==&mid=2247604795&idx=1&sn=b1eda3d7ddb36807cbeaf3fc2b21dbe4&chksm=c11e4a74f669c362b7327ef69aeeb78681b7338d1e546a2be7b3439c92122e418b2968d4bee6&scene=21#wechat_redirect",[77],[554],{"type":24,"value":555},"论文精讲 | 基于昇思提出的流场景下知识图谱表示学习框架",{"title":7,"searchDepth":557,"depth":557,"links":558},4,[559,561,562,563],{"id":223,"depth":560,"text":229},3,{"id":367,"depth":560,"text":373},{"id":388,"depth":560,"text":394},{"id":424,"depth":560,"text":430},"markdown","content:technology-blogs:zh:2824.md","content","technology-blogs/zh/2824.md","technology-blogs/zh/2824","md",1776506123220]