[{"data":1,"prerenderedAt":441},["ShallowReactive",2],{"content-query-ERoDaS79XK":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"cover":11,"type":12,"body":13,"_type":435,"_id":436,"_source":437,"_file":438,"_stem":439,"_extension":440},"/technology-blogs/zh/660","zh",false,"","技术干货| 更快更轻量的三维重建，MindSpore非线性最小二乘优化器","MindSpore非线性最小二乘优化器","2021-07-23","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/871339e76c754c4b92e544216735e4eb.png","technology-blogs",{"type":14,"children":15,"toc":432},"root",[16,24,33,38,72,114,121,126,131,138,155,162,167,174,182,187,194,199,207,214,219,226,231,261,266,279,284,291,299,304,311,316,323,328,335,342,354,359,376,394,399,410,415,420,425],{"type":17,"tag":18,"props":19,"children":21},"element","h1",{"id":20},"技术干货-更快更轻量的三维重建mindspore非线性最小二乘优化器",[22],{"type":23,"value":8},"text",{"type":17,"tag":25,"props":26,"children":27},"p",{},[28],{"type":17,"tag":29,"props":30,"children":32},"img",{"alt":7,"src":31},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/bf3023ccfe1e4a0e96acb003033b0af4.gif",[],{"type":17,"tag":25,"props":34,"children":35},{},[36],{"type":23,"value":37},"三维重建的目标是确定真实世界物体的相互空间关系。随着VR/AR的发展、元宇宙概念的提出，越来越多与现实场景融合的应用依赖于真实世界的三维信息还原，三维重建作为提供真实世界信息的基础，逐步成为使能上层应用的核心技术挑战。",{"type":17,"tag":25,"props":39,"children":40},{},[41,43,49,51,56,58,63,65,70],{"type":23,"value":42},"三维重建在工业界中普遍的解决方案是以环境中多视角采集的图片作为输入，通过分析不同图片中特征点的对应关系，建立非线性最小二乘数学模型进行图片空间位置以及特征点空间位置的联合求解。我们",{"type":17,"tag":44,"props":45,"children":46},"strong",{},[47],{"type":23,"value":48},"基于MindSpore",{"type":23,"value":50},"设计了一套高效的非线性最小二乘优化器，",{"type":17,"tag":44,"props":52,"children":53},{},[54],{"type":23,"value":55},"快速求解城市级的图片空间位姿",{"type":23,"value":57},"，文章已被计算机视觉三大顶会之一的",{"type":17,"tag":44,"props":59,"children":60},{},[61],{"type":23,"value":62},"CVPR接收",{"type":23,"value":64},"。该算法的",{"type":17,"tag":44,"props":66,"children":67},{},[68],{"type":23,"value":69},"开源代码已经在MindSpore上发布",{"type":23,"value":71},"。",{"type":17,"tag":73,"props":74,"children":75},"ul",{},[76,100],{"type":17,"tag":77,"props":78,"children":79},"li",{},[80,82,86,88,91],{"type":23,"value":81},"论文：",{"type":17,"tag":83,"props":84,"children":85},"br",{},[],{"type":23,"value":87},"Huang, Jingwei, Shan Huang, and Mingwei Sun. \"DeepLM: Large-Scale Nonlinear Least Squares on Deep Learning Frameworks Using Stochastic Domain Decomposition.\" Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition. 2021.",{"type":17,"tag":83,"props":89,"children":90},{},[],{"type":17,"tag":92,"props":93,"children":97},"a",{"href":94,"rel":95},"https://openaccess.thecvf.com/content/CVPR2021/html/Huang%5C_DeepLM%5C_Large-Scale%5C_Nonlinear%5C_Least%5C_Squares%5C_on%5C_Deep%5C_Learning%5C_Frameworks%5C_Using%5C_CVPR%5C_2021%5C_paper.html",[96],"nofollow",[98],{"type":23,"value":99},"https://openaccess.thecvf.com/content/CVPR2021/html/Huang\\_DeepLM\\_Large-Scale\\_Nonlinear\\_Least\\_Squares\\_on\\_Deep\\_Learning\\_Frameworks\\_Using\\_CVPR\\_2021\\_paper.html",{"type":17,"tag":77,"props":101,"children":102},{},[103,105,108],{"type":23,"value":104},"开源地址：",{"type":17,"tag":83,"props":106,"children":107},{},[],{"type":17,"tag":92,"props":109,"children":112},{"href":110,"rel":111},"https://gitee.com/mindspore/mindspore/tree/master",[96],[113],{"type":23,"value":110},{"type":17,"tag":25,"props":115,"children":116},{},[117],{"type":17,"tag":29,"props":118,"children":120},{"alt":7,"src":119},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/9bcd90efd9c44d3f8f8ce1ec0a699850.png",[],{"type":17,"tag":25,"props":122,"children":123},{},[124],{"type":23,"value":125},"非线性最小二乘优化器在处理实际重建问题时的挑战在于效率以及对于大规模数据的处理能力。针对效率，我们主要的解决方案是将其与深度学习框架结合起来，类似于AI框架训练神经网络的原理，利用硬件资源进行并行化的计算处理。",{"type":17,"tag":25,"props":127,"children":128},{},[129],{"type":23,"value":130},"非线性最小二乘规划问题的数学表达形式为优化若干残差函数平方和的能量函数：",{"type":17,"tag":25,"props":132,"children":133},{},[134],{"type":17,"tag":29,"props":135,"children":137},{"alt":7,"src":136},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/60d83d0e5d174bbaa379f6b5d3dddaff.png",[],{"type":17,"tag":25,"props":139,"children":140},{},[141,143,147,149,153],{"type":23,"value":142},"以三维还原问题为例，其目标是求解特征点所对应三维物点的空间位置",{"type":17,"tag":29,"props":144,"children":146},{"alt":7,"src":145},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/33697fdaf0b840c79bee3a893ab47924.png",[],{"type":23,"value":148},"与图片位次物点i和可见物点的图片",{"type":17,"tag":29,"props":150,"children":152},{"alt":7,"src":151},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/ded83fce99184c95a276323457cd2691.png",[],{"type":23,"value":154}," ，残差函数为：",{"type":17,"tag":25,"props":156,"children":157},{},[158],{"type":17,"tag":29,"props":159,"children":161},{"alt":7,"src":160},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/f5885f6b93934d26b021d5d51030679a.png",[],{"type":17,"tag":25,"props":163,"children":164},{},[165],{"type":23,"value":166},"成熟的解决方案是使用Levenberg-Marquardt迭代算法。",{"type":17,"tag":25,"props":168,"children":169},{},[170],{"type":17,"tag":29,"props":171,"children":173},{"alt":7,"src":172},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/d117b737a002439fb21463eafa277e2f.png",[],{"type":17,"tag":25,"props":175,"children":176},{},[177],{"type":17,"tag":44,"props":178,"children":179},{},[180],{"type":23,"value":181},"雅可比网络",{"type":17,"tag":25,"props":183,"children":184},{},[185],{"type":23,"value":186},"这里涉及到残差对于自变量的稀疏雅可比矩阵的求解，也是现有AI框架不具备的能力。我们提出了雅可比矩阵计算网络，使用单次反向传播即可完成稀疏雅可比矩阵的计算。",{"type":17,"tag":25,"props":188,"children":189},{},[190],{"type":17,"tag":29,"props":191,"children":193},{"alt":7,"src":192},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/45c1399f65f74c2581c41ee86be69796.png",[],{"type":17,"tag":25,"props":195,"children":196},{},[197],{"type":23,"value":198},"对于用户给定的残差函数 ，雅可比网络将每个残差涉及的变量压缩排列，并通过压缩排列后张量化的变量计算残差和。残差和对于压缩张量的偏导数与稀疏雅可比矩阵非零项一一对应，可以通过单次反向传播，结合残差与自变量的索引关系，组成稀疏雅可比矩阵的三元组表达。",{"type":17,"tag":25,"props":200,"children":201},{},[202],{"type":17,"tag":44,"props":203,"children":204},{},[205],{"type":23,"value":206},"随机域分解",{"type":17,"tag":25,"props":208,"children":209},{},[210],{"type":17,"tag":29,"props":211,"children":213},{"alt":7,"src":212},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/eb07b6792a034064ad2f47f1ccd7b91e.jpg",[],{"type":17,"tag":25,"props":215,"children":216},{},[217],{"type":23,"value":218},"除了效率之外，对于大规模问题的处理也是我们需要重点解决的问题，解决思路是将问题随机分块求解。通过分块，我们将全局问题分解为较小的子问题，这样可以显著降低单次求解问题的内存消耗。同时，通过随机分块算法，所有变量都有概率被分配在块的内部而非边界，从而有效提升了分块求解方案的收敛质量。",{"type":17,"tag":25,"props":220,"children":221},{},[222],{"type":17,"tag":29,"props":223,"children":225},{"alt":7,"src":224},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/b67f67118c1143af9ec734f4e4e6d20d.png",[],{"type":17,"tag":25,"props":227,"children":228},{},[229],{"type":23,"value":230},"本方案可以高效求解大规模的平差(Bundle Adjustment)问题，通过使用GPU进行计算能够提速4倍以上。下面为平差优化问题公开数据集BAL上的实验结果以及BAL、1DSFM中一些场景的空间特征与相机位姿求解的可视化结果。",{"type":17,"tag":73,"props":232,"children":233},{},[234],{"type":17,"tag":77,"props":235,"children":236},{},[237,239,242,244,250,253,255],{"type":23,"value":238},"测试集链接：",{"type":17,"tag":83,"props":240,"children":241},{},[],{"type":23,"value":243},"BAL：",{"type":17,"tag":92,"props":245,"children":248},{"href":246,"rel":247},"http://grail.cs.washington.edu/projects/bal/",[96],[249],{"type":23,"value":246},{"type":17,"tag":83,"props":251,"children":252},{},[],{"type":23,"value":254},"1DSFM：",{"type":17,"tag":92,"props":256,"children":259},{"href":257,"rel":258},"http://www.cs.cornell.edu/projects/1dsfm/",[96],[260],{"type":23,"value":257},{"type":17,"tag":25,"props":262,"children":263},{},[264],{"type":23,"value":265},"我们的非线性最小二乘优化器在BAL数据集上同其他SOTA方法的耗时对比(单位为秒)如下：其中Ours-G代表全局优化方案，Ours-B代表采用了随机域分解的方案，Ours-BG代表采用了随机域分解和全局重初始化策略的方案。可以看到对比SOTA方法，我们的算法在耗时上的优势十分明显。",{"type":17,"tag":25,"props":267,"children":268},{},[269,273,275],{"type":17,"tag":29,"props":270,"children":272},{"alt":7,"src":271},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/6076326f1f4f4afaa69c5f6cd7f3ee56.png",[],{"type":23,"value":274}," ",{"type":17,"tag":29,"props":276,"children":278},{"alt":7,"src":277},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/87f44c8620514d4a99da3530980db631.jpg",[],{"type":17,"tag":25,"props":280,"children":281},{},[282],{"type":23,"value":283},"通过随机域算法，我们的求解器可以解决城市级别的平差问题。如下例所示，我们联合求解了28万张照片以及超过12亿个残差项仅耗时6分钟。",{"type":17,"tag":25,"props":285,"children":286},{},[287],{"type":17,"tag":29,"props":288,"children":290},{"alt":7,"src":289},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/394f85ca3b9a4b30b3fa60ba28ad3d21.jpg",[],{"type":17,"tag":25,"props":292,"children":293},{},[294],{"type":17,"tag":44,"props":295,"children":296},{},[297],{"type":23,"value":298},"适用于多种问题的优化器",{"type":17,"tag":25,"props":300,"children":301},{},[302],{"type":23,"value":303},"我们提供了多个场景下使用我们非线性最小二乘优化器的案例。在拼接多张图像时，本优化器可用于颜色的均一化，如下所示：",{"type":17,"tag":25,"props":305,"children":306},{},[307],{"type":17,"tag":29,"props":308,"children":310},{"alt":7,"src":309},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/467d8125e2544421bcd285b5a06b8315.gif",[],{"type":17,"tag":25,"props":312,"children":313},{},[314],{"type":23,"value":315},"本方法还可以用于网格的精确变形，如下所示：",{"type":17,"tag":25,"props":317,"children":318},{},[319],{"type":17,"tag":29,"props":320,"children":322},{"alt":7,"src":321},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/de99c4cda23047f6acd323ff36159099.gif",[],{"type":17,"tag":25,"props":324,"children":325},{},[326],{"type":23,"value":327},"其他例如三维物体对齐、图像融合、函数拟合等经典问题，都可以使用本优化器来完成。",{"type":17,"tag":25,"props":329,"children":330},{},[331],{"type":17,"tag":29,"props":332,"children":334},{"alt":7,"src":333},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/3b5efae495f74e309dbb7225137a1833.jpg",[],{"type":17,"tag":25,"props":336,"children":337},{},[338],{"type":17,"tag":29,"props":339,"children":341},{"alt":7,"src":340},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/10526b6d2138425786b066b17474c293.png",[],{"type":17,"tag":25,"props":343,"children":344},{},[345,347],{"type":23,"value":346},"我们基于MindSpore r1.3版本(",{"type":17,"tag":92,"props":348,"children":351},{"href":349,"rel":350},"https://gitee.com/mindspore/mindspore/tree/r1.3/)%E5%AE%9E%E7%8E%B0%E6%97%B6%EF%BC%8C%E9%92%88%E5%AF%B9Tensor%E5%88%87%E7%89%87%E6%93%8D%E4%BD%9C%E3%80%81%E5%86%85%E5%AD%98%E7%9A%84%E5%88%86%E9%85%8D%E3%80%81%E5%8A%A8%E6%80%81%E5%9B%BE%E6%89%A7%E8%A1%8C%E6%80%A7%E8%83%BD%E7%AD%89%E5%81%9A%E4%BA%86%E7%9B%B8%E5%BA%94%E7%9A%84%E4%BC%98%E5%8C%96%EF%BC%8C%E5%9B%A0%E6%AD%A4%E5%9C%A8%E5%A4%A7%E8%A7%84%E6%A8%A1%E7%9A%84%E6%95%B0%E6%8D%AE%E9%9B%86%E4%B8%8A%E6%80%A7%E8%83%BD%E8%A1%A8%E7%8E%B0**%E6%AF%94Pytorch%E7%89%88%E6%9C%AC%E6%9B%B4%E5%8A%A0%E4%BC%98%E5%BC%82**%E3%80%82",[96],[352],{"type":23,"value":353},"https://gitee.com/mindspore/mindspore/tree/r1.3/)实现时，针对Tensor切片操作、内存的分配、动态图执行性能等做了相应的优化，因此在大规模的数据集上性能表现**比Pytorch版本更加优异**。",{"type":17,"tag":25,"props":355,"children":356},{},[357],{"type":23,"value":358},"在多达600多万次相机采集观察次数的航拍城市场景业务数据集上，MindSpore版本的代码性能相比Pytorch版本进一步提升了15.6%(90.87s VS 107.71s)。",{"type":17,"tag":73,"props":360,"children":361},{},[362],{"type":17,"tag":77,"props":363,"children":364},{},[365,367,370],{"type":23,"value":366},"相关代码：",{"type":17,"tag":83,"props":368,"children":369},{},[],{"type":17,"tag":92,"props":371,"children":374},{"href":372,"rel":373},"https://gitee.com/mindspore/mindspore",[96],[375],{"type":23,"value":372},{"type":17,"tag":25,"props":377,"children":378},{},[379,381,386,388,393],{"type":23,"value":380},"该代码基于MindSpore框架实现，运行的硬件环境为GPU。算法大大提升了城市级图片空间位姿问题的求解效率，",{"type":17,"tag":44,"props":382,"children":383},{},[384],{"type":23,"value":385},"对比之前的SOTA方法性能提升明显",{"type":23,"value":387},"，实验结果如上表达到",{"type":17,"tag":44,"props":389,"children":390},{},[391],{"type":23,"value":392},"业界领先水平",{"type":23,"value":71},{"type":17,"tag":25,"props":395,"children":396},{},[397],{"type":23,"value":398},"MindSpore官方资料",{"type":17,"tag":25,"props":400,"children":401},{},[402,404],{"type":23,"value":403},"GitHub : ",{"type":17,"tag":92,"props":405,"children":408},{"href":406,"rel":407},"https://github.com/mindspore-ai/mindspore",[96],[409],{"type":23,"value":406},{"type":17,"tag":25,"props":411,"children":412},{},[413],{"type":23,"value":414},"Gitee:https : //gitee.com/mindspore/mindspore",{"type":17,"tag":25,"props":416,"children":417},{},[418],{"type":23,"value":419},"官方QQ群 : 871543426",{"type":17,"tag":25,"props":421,"children":422},{},[423],{"type":23,"value":424},"长按下方二维码加入MindSpore项目↓",{"type":17,"tag":25,"props":426,"children":427},{},[428],{"type":17,"tag":29,"props":429,"children":431},{"alt":7,"src":430},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/07/23/b3d7eb00483542acbaf55e57952c1b7b.jpg",[],{"title":7,"searchDepth":433,"depth":433,"links":434},4,[],"markdown","content:technology-blogs:zh:660.md","content","technology-blogs/zh/660.md","technology-blogs/zh/660","md",1776506139315]