[{"data":1,"prerenderedAt":629},["ShallowReactive",2],{"content-query-wgXJSPcLGZ":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":623,"_id":624,"_source":625,"_file":626,"_stem":627,"_extension":628},"/technology-blogs/zh/3419","zh",false,"","基于昇思MindSpore与OrangePi AIpro的训推全流程指导","作者：LYQw 来源：昇思论坛","2024-10-08","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/11/28/f656bed4c2054fa28fe325c7930ab8b6.png","technology-blogs","基础知识",{"type":15,"children":16,"toc":620},"root",[17,25,44,52,57,62,67,75,80,100,114,119,129,137,149,154,168,179,184,192,200,208,213,220,228,236,241,249,256,264,269,277,284,289,296,301,308,316,321,329,337,342,351,358,366,374,379,386,394,399,407,414,422,427,432,437,442,449,456,464,469,494,502,510,518,523,531,536,547,554,562,567,574,582,587,594,602,607],{"type":18,"tag":19,"props":20,"children":22},"element","h1",{"id":21},"基于昇思mindspore与orangepi-aipro的训推全流程指导",[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},"LYQw",{"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":18,"tag":32,"props":48,"children":49},{},[50],{"type":24,"value":51},"OrangePi AIpro介绍",{"type":18,"tag":26,"props":53,"children":54},{},[55],{"type":24,"value":56},"OrangePi AIpro（香橙派 AIpro）采用昇腾AI技术路线，具体为4核64位处理器和AI处理器，集成图形处理器。",{"type":18,"tag":26,"props":58,"children":59},{},[60],{"type":24,"value":61},"目前已实现OrangePi AIpro开发板的系统镜像预置昇思MindSpore AI框架，并在后续版本迭代中持续演进，当前已支持昇思MindSpore官网教程涵盖的全部网络模型。OrangePi AIpro开发板向开发者提供的官方系统镜像有openEuler版本预ubuntu版本，两个镜像版本均已预置昇思MindSpore，便于用户体验软硬协同优化后带来的高效开发体验。同时，欢迎开发者自定义配置昇思MindSpore和CANN运行环境。",{"type":18,"tag":26,"props":63,"children":64},{},[65],{"type":24,"value":66},"接下来的教程将演示如何基于OrangePi AIpro进行自定义环境搭建，如何在OrangePi AIpro启动Jupyter Lab，并以ResNet50图像分类为例，介绍OrangePi AIpro上基于昇思MindSpore进行全流程（云端训练+离线推理）运行的步骤。",{"type":18,"tag":26,"props":68,"children":69},{},[70],{"type":18,"tag":32,"props":71,"children":72},{},[73],{"type":24,"value":74},"云端训练",{"type":18,"tag":26,"props":76,"children":77},{},[78],{"type":24,"value":79},"图像分类是最基础的计算机视觉应用，属于有监督学习类别，如给定一张图像(猫、狗、飞机、汽车等等)，判断图像所属的类别。本篇将介绍使用ResNet50网络对CIFAR-10数据集进行分类。",{"type":18,"tag":26,"props":81,"children":82},{},[83,88,89,94,95],{"type":18,"tag":32,"props":84,"children":85},{},[86],{"type":24,"value":87},"0****1",{"type":24,"value":38},{"type":18,"tag":32,"props":90,"children":91},{},[92],{"type":24,"value":93},"环境搭建",{"type":24,"value":38},{"type":18,"tag":32,"props":96,"children":97},{},[98],{"type":24,"value":99},"（1）华为云—贵阳一升级MindSpore2.3.1版本",{"type":18,"tag":26,"props":101,"children":102},{},[103,105],{"type":24,"value":104},"在华为云（",{"type":18,"tag":106,"props":107,"children":111},"a",{"href":108,"rel":109},"https://www.huaweicloud.com/product/modelarts.html%EF%BC%89%E6%90%AD%E5%BB%BA%E8%AE%AD%E7%BB%83%E7%8E%AF%E5%A2%83%EF%BC%9A",[110],"nofollow",[112],{"type":24,"value":113},"https://www.huaweicloud.com/product/modelarts.html）搭建训练环境：",{"type":18,"tag":26,"props":115,"children":116},{},[117],{"type":24,"value":118},"下载whl包进行安装，终端运行如下命令：",{"type":18,"tag":120,"props":121,"children":123},"pre",{"code":122},"wget https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/unified/aarch64/mindspore-2.3.1-cp39-cp39-linux_aarch64.whl\n# 在终端进入到whl包所在路径，执行pip install命令\npip install mindspore-2.3.1-cp39-cp39-linux_aarch64.whl\n",[124],{"type":18,"tag":125,"props":126,"children":127},"code",{"__ignoreMap":7},[128],{"type":24,"value":122},{"type":18,"tag":26,"props":130,"children":131},{},[132],{"type":18,"tag":32,"props":133,"children":134},{},[135],{"type":24,"value":136},"（2）OrangePi AIpro（香橙派 AIpro）：镜像烧录、升级MindSpore和CANN版本",{"type":18,"tag":26,"props":138,"children":139},{},[140,142],{"type":24,"value":141},"具体实现请参考香橙派开发中的环境搭建指南部分（",{"type":18,"tag":106,"props":143,"children":146},{"href":144,"rel":145},"https://www.mindspore.cn/docs/zh-CN/master/orange%5C_pi/environment%5C_setup.html%EF%BC%89%E3%80%82",[110],[147],{"type":24,"value":148},"https://www.mindspore.cn/docs/zh-CN/master/orange\\_pi/environment\\_setup.html）。",{"type":18,"tag":26,"props":150,"children":151},{},[152],{"type":24,"value":153},"注：开发板上的昇思MindSpore版本需要与云环境上的版本保持一致；CANN的版本需要与昇思MindSpore的版本相匹配。",{"type":18,"tag":26,"props":155,"children":156},{},[157,162,163],{"type":18,"tag":32,"props":158,"children":159},{},[160],{"type":24,"value":161},"02",{"type":24,"value":38},{"type":18,"tag":32,"props":164,"children":165},{},[166],{"type":24,"value":167},"训练代码文档下载",{"type":18,"tag":26,"props":169,"children":170},{},[171,173],{"type":24,"value":172},"进入昇思MindSpore官网，下载ResNet50案例的notebook文档，链接如下：",{"type":18,"tag":106,"props":174,"children":177},{"href":175,"rel":176},"https://www.mindspore.cn/tutorials/application/zh-CN/r2.3.0rc2/cv/resnet50.html",[110],[178],{"type":24,"value":175},{"type":18,"tag":26,"props":180,"children":181},{},[182],{"type":24,"value":183},"ResNet网络介绍、数据集准备和加载、网络构建、模型训练与评估等都有详细说明。",{"type":18,"tag":26,"props":185,"children":186},{},[187],{"type":18,"tag":188,"props":189,"children":191},"img",{"alt":7,"src":190},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/10/11/da40b57061354c75b68d581af8eb4d58.png",[],{"type":18,"tag":26,"props":193,"children":194},{},[195],{"type":18,"tag":32,"props":196,"children":197},{},[198],{"type":24,"value":199},"03",{"type":18,"tag":26,"props":201,"children":202},{},[203],{"type":18,"tag":32,"props":204,"children":205},{},[206],{"type":24,"value":207},"模型训练",{"type":18,"tag":26,"props":209,"children":210},{},[211],{"type":24,"value":212},"将2.2环节下载的训练代码文档上传到ModelArts开发平台。",{"type":18,"tag":26,"props":214,"children":215},{},[216],{"type":18,"tag":188,"props":217,"children":219},{"alt":7,"src":218},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/10/11/b3ece38ffa244638809309584963d647.png",[],{"type":18,"tag":26,"props":221,"children":222},{},[223],{"type":18,"tag":32,"props":224,"children":225},{},[226],{"type":24,"value":227},"训练前修改部分代码：",{"type":18,"tag":26,"props":229,"children":230},{},[231],{"type":18,"tag":32,"props":232,"children":233},{},[234],{"type":24,"value":235},"步骤1：添加数据下载权限",{"type":18,"tag":26,"props":237,"children":238},{},[239],{"type":24,"value":240},"在数据集准备与加载模块添加数据下载权限",{"type":18,"tag":120,"props":242,"children":244},{"code":243},"%env no_proxy='a.test.com,127.0.0.1,2.2.2.2'\n",[245],{"type":18,"tag":125,"props":246,"children":247},{"__ignoreMap":7},[248],{"type":24,"value":243},{"type":18,"tag":26,"props":250,"children":251},{},[252],{"type":18,"tag":188,"props":253,"children":255},{"alt":7,"src":254},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/10/11/19d1e79a2d094e1dab718aa94c97dfd2.png",[],{"type":18,"tag":26,"props":257,"children":258},{},[259],{"type":18,"tag":32,"props":260,"children":261},{},[262],{"type":24,"value":263},"步骤2：添加mindir模型导出代码",{"type":18,"tag":26,"props":265,"children":266},{},[267],{"type":24,"value":268},"在可视化模型预测部分添加导出mindir模型的代码",{"type":18,"tag":120,"props":270,"children":272},{"code":271},"Inputs = ms.Tensor(np.ones([4,3,32,32]).astype(np.float32))\nms.export(net, inputs, file_name= \"resnet50\", file_format= \"MINDIR\")\n",[273],{"type":18,"tag":125,"props":274,"children":275},{"__ignoreMap":7},[276],{"type":24,"value":271},{"type":18,"tag":26,"props":278,"children":279},{},[280],{"type":18,"tag":188,"props":281,"children":283},{"alt":7,"src":282},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/10/11/4e2c5912883c439089a22261b9c56e52.png",[],{"type":18,"tag":26,"props":285,"children":286},{},[287],{"type":24,"value":288},"在云环境上运行notebook文档，生成mindir模型文件。",{"type":18,"tag":26,"props":290,"children":291},{},[292],{"type":18,"tag":188,"props":293,"children":295},{"alt":7,"src":294},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/10/11/60872bb72121482ebffda7a883c6e321.png",[],{"type":18,"tag":26,"props":297,"children":298},{},[299],{"type":24,"value":300},"右键下载mindir模型文件至本地。",{"type":18,"tag":26,"props":302,"children":303},{},[304],{"type":18,"tag":188,"props":305,"children":307},{"alt":7,"src":306},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/10/11/f0587e71087c4ab1b9990c5b4d51ebfd.png",[],{"type":18,"tag":26,"props":309,"children":310},{},[311],{"type":18,"tag":32,"props":312,"children":313},{},[314],{"type":24,"value":315},"OrangePi AIpro上离****线推理",{"type":18,"tag":26,"props":317,"children":318},{},[319],{"type":24,"value":320},"本环节在香橙派AIpro开发板上，首先进行离线模型转换，使用convert命令将mindir模型转换为om模型，然后使用AscendCL开发推理代码，实现图像分类推理任务。",{"type":18,"tag":26,"props":322,"children":323},{},[324],{"type":18,"tag":32,"props":325,"children":326},{},[327],{"type":24,"value":328},"01",{"type":18,"tag":26,"props":330,"children":331},{},[332],{"type":18,"tag":32,"props":333,"children":334},{},[335],{"type":24,"value":336},"推理代码文档下载",{"type":18,"tag":26,"props":338,"children":339},{},[340],{"type":24,"value":341},"进入昇思MindSpore版的开发板离线推理代码仓，下载ResNet50的离线推理文件，下载地址如下：",{"type":18,"tag":26,"props":343,"children":344},{},[345],{"type":18,"tag":106,"props":346,"children":349},{"href":347,"rel":348},"https://github.com/mindspore-courses/orange-pi-mindspore/tree/master/infer/03-ResNet50",[110],[350],{"type":24,"value":347},{"type":18,"tag":26,"props":352,"children":353},{},[354],{"type":18,"tag":32,"props":355,"children":356},{},[357],{"type":24,"value":161},{"type":18,"tag":26,"props":359,"children":360},{},[361],{"type":18,"tag":32,"props":362,"children":363},{},[364],{"type":24,"value":365},"Convert命令获取om模型文件",{"type":18,"tag":26,"props":367,"children":368},{},[369],{"type":18,"tag":32,"props":370,"children":371},{},[372],{"type":24,"value":373},"步骤1：上传mindir模型文件",{"type":18,"tag":26,"props":375,"children":376},{},[377],{"type":24,"value":378},"在“/home/HwHiAiUser/samples/noteboooks”目录下创建ResNet50_2.2.14文件夹，将训练获得的mindir模型文件放入该文件夹。",{"type":18,"tag":26,"props":380,"children":381},{},[382],{"type":18,"tag":188,"props":383,"children":385},{"alt":7,"src":384},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/10/11/06af053ac4ed498b8686820732cfeac8.png",[],{"type":18,"tag":26,"props":387,"children":388},{},[389],{"type":18,"tag":32,"props":390,"children":391},{},[392],{"type":24,"value":393},"步骤2：mindir模型文件转换为om模型",{"type":18,"tag":26,"props":395,"children":396},{},[397],{"type":24,"value":398},"在“/home/HwHiAiUser/samples/noteboooks”目录下运行如下命令，生成om模型文件。",{"type":18,"tag":120,"props":400,"children":402},{"code":401},"#获取bash.sh文件\nwget https://mindspore-courses.obs.cn-north-4.myhuaweicloud.com/orange-pi-mindspore/package/bash.sh\n",[403],{"type":18,"tag":125,"props":404,"children":405},{"__ignoreMap":7},[406],{"type":24,"value":401},{"type":18,"tag":26,"props":408,"children":409},{},[410],{"type":18,"tag":188,"props":411,"children":413},{"alt":7,"src":412},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/10/11/3bb1d1e071214b54850188ba68e8bacf.png",[],{"type":18,"tag":120,"props":415,"children":417},{"code":416},"#执行bash.sh文件\nsource bash.sh /home/HwHiAiUser/samples/notebooks/ResNet50_2.2.14/resnet50.mindir resnet50\n",[418],{"type":18,"tag":125,"props":419,"children":420},{"__ignoreMap":7},[421],{"type":24,"value":416},{"type":18,"tag":26,"props":423,"children":424},{},[425],{"type":24,"value":426},"注：bash.sh文件执行时需要传入两个参数，如上述第二个命令所示：",{"type":18,"tag":26,"props":428,"children":429},{},[430],{"type":24,"value":431},"第一个参数是开发板上存放的mindir文件的绝对路径；",{"type":18,"tag":26,"props":433,"children":434},{},[435],{"type":24,"value":436},"第二个参数是生成的om文件的名称；",{"type":18,"tag":26,"props":438,"children":439},{},[440],{"type":24,"value":441},"运行完成后生成的om文件和bash.sh文件同目录。",{"type":18,"tag":26,"props":443,"children":444},{},[445],{"type":18,"tag":188,"props":446,"children":448},{"alt":7,"src":447},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/10/11/cca582664b274ff6863bfe0efb5ba207.png",[],{"type":18,"tag":26,"props":450,"children":451},{},[452],{"type":18,"tag":32,"props":453,"children":454},{},[455],{"type":24,"value":199},{"type":18,"tag":26,"props":457,"children":458},{},[459],{"type":18,"tag":32,"props":460,"children":461},{},[462],{"type":24,"value":463},"创建推理项目文件夹",{"type":18,"tag":26,"props":465,"children":466},{},[467],{"type":24,"value":468},"在“/home/HwHiAiUser/samples/noteboooks”目录下创建ResNet50文件夹，将3.1下载的推理代码文档放入该文件夹，并在ResNet50文件夹下创建model文件夹，将3.3.1生成的om模型放入model文件夹下。目录如下：",{"type":18,"tag":470,"props":471,"children":472},"ul",{},[473,479,484,489],{"type":18,"tag":474,"props":475,"children":476},"li",{},[477],{"type":24,"value":478},"ResNet50",{"type":18,"tag":474,"props":480,"children":481},{},[482],{"type":24,"value":483},"— main_resnet50.ipynb",{"type":18,"tag":474,"props":485,"children":486},{},[487],{"type":24,"value":488},"--resnet50.om",{"type":18,"tag":474,"props":490,"children":491},{},[492],{"type":24,"value":493},"— model",{"type":18,"tag":26,"props":495,"children":496},{},[497],{"type":18,"tag":32,"props":498,"children":499},{},[500],{"type":24,"value":501},"04",{"type":18,"tag":26,"props":503,"children":504},{},[505],{"type":18,"tag":32,"props":506,"children":507},{},[508],{"type":24,"value":509},"启动notebook运行环境执行推理应用",{"type":18,"tag":26,"props":511,"children":512},{},[513],{"type":18,"tag":32,"props":514,"children":515},{},[516],{"type":24,"value":517},"步骤1：运行start_notebook.sh文件",{"type":18,"tag":26,"props":519,"children":520},{},[521],{"type":24,"value":522},"使用如下命令运行start_notebook.sh文件",{"type":18,"tag":120,"props":524,"children":526},{"code":525},"./start_notebook.sh\n",[527],{"type":18,"tag":125,"props":528,"children":529},{"__ignoreMap":7},[530],{"type":24,"value":525},{"type":18,"tag":26,"props":532,"children":533},{},[534],{"type":24,"value":535},"打开notebook运行环境，可以看到创建的ResNet50项目文件夹。",{"type":18,"tag":26,"props":537,"children":538},{},[539,543],{"type":18,"tag":188,"props":540,"children":542},{"alt":7,"src":541},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/10/11/34cdb815fcee4a0fb1691d6075870be5.png",[],{"type":18,"tag":188,"props":544,"children":546},{"alt":7,"src":545},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/10/11/c5a7c9af366141c194c025668efa93fe.png",[],{"type":18,"tag":26,"props":548,"children":549},{},[550],{"type":18,"tag":188,"props":551,"children":553},{"alt":7,"src":552},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/10/11/8d0930686df646b8be2a315a4fead0c5.png",[],{"type":18,"tag":26,"props":555,"children":556},{},[557],{"type":18,"tag":32,"props":558,"children":559},{},[560],{"type":24,"value":561},"步骤2：修改推理代码",{"type":18,"tag":26,"props":563,"children":564},{},[565],{"type":24,"value":566},"打开main_resnet50.ipynb文档，在下载环节，注释掉om文件下载的代码，保留数据集下载的代码。",{"type":18,"tag":26,"props":568,"children":569},{},[570],{"type":18,"tag":188,"props":571,"children":573},{"alt":7,"src":572},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/10/11/5e9de2f9c4654fc38b0268f2c877dfb9.png",[],{"type":18,"tag":26,"props":575,"children":576},{},[577],{"type":18,"tag":32,"props":578,"children":579},{},[580],{"type":24,"value":581},"步骤3：执行推理应用",{"type":18,"tag":26,"props":583,"children":584},{},[585],{"type":24,"value":586},"运行main_resnet50.ipynb文档，进行图像分类推理应用。",{"type":18,"tag":26,"props":588,"children":589},{},[590],{"type":18,"tag":188,"props":591,"children":593},{"alt":7,"src":592},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/10/11/00c38d78f81c4bdf981e372e2a791f45.png",[],{"type":18,"tag":26,"props":595,"children":596},{},[597],{"type":18,"tag":32,"props":598,"children":599},{},[600],{"type":24,"value":601},"实验总结",{"type":18,"tag":26,"props":603,"children":604},{},[605],{"type":24,"value":606},"本实验实现基于昇思MindSpore的ResNet50图像分类离线推理全流程实践。训练环节，首先基于昇思MindSpore AI框架搭建ResNet50模型，完成代码开发，然后在华为云ModelArts平台，使用cifar-10数据集完成模型训练，获得mindir模型文件。推理环节，在香橙派AIpro开发板上，首先进行离线模型转换，使用convert命令将mindir模型转换为om模型，然后使用AscendCL开发推理代码，实现图像分类推理任务。",{"type":18,"tag":26,"props":608,"children":609},{},[610,612,618],{"type":24,"value":611},"更多基于MindSpore框架开发的全流程实验指导文档详见orange-pi-mindspore中的基于昇思MindSpore+OrangePi AIpro的训推全流程指导书(离线推理",{"type":18,"tag":106,"props":613,"children":616},{"href":614,"rel":615},"https://github.com/mindspore-courses/orange-pi-mindspore/tree/master/infer",[110],[617],{"type":24,"value":614},{"type":24,"value":619},")",{"title":7,"searchDepth":621,"depth":621,"links":622},4,[],"markdown","content:technology-blogs:zh:3419.md","content","technology-blogs/zh/3419.md","technology-blogs/zh/3419","md",1776506129643]