[{"data":1,"prerenderedAt":511},["ShallowReactive",2],{"content-query-3kvyhWyF8Y":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":505,"_id":506,"_source":507,"_file":508,"_stem":509,"_extension":510},"/technology-blogs/zh/558","zh",false,"","开发者分享 | MindSpore高阶API工具TinyMS初体验！","MindSpore高阶API工具TinyMS初体验！","2021-05-18","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/19/c151b41b46464298a61d27ba2d907c3e.png","technology-blogs","开发者分享",{"type":15,"children":16,"toc":502},"root",[17,25,34,48,60,65,72,77,82,87,96,101,108,113,120,125,130,137,142,152,157,164,169,177,182,189,194,201,209,214,221,226,234,239,244,251,256,264,269,274,281,292,299,304,312,317,325,330,338,345,350,355,362,367,374,379,384,389,396,401,408,413,420,432,445,452,457,464,469,480,485,490,495],{"type":18,"tag":19,"props":20,"children":22},"element","h1",{"id":21},"开发者分享-mindspore高阶api工具tinyms初体验",[23],{"type":24,"value":8},"text",{"type":18,"tag":26,"props":27,"children":28},"p",{},[29],{"type":18,"tag":30,"props":31,"children":33},"img",{"alt":7,"src":32},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/0c73d3c8704e4a668da91c2c8684e2b6.gif",[],{"type":18,"tag":26,"props":35,"children":36},{},[37,39],{"type":24,"value":38},"本文来源于：",{"type":18,"tag":40,"props":41,"children":45},"a",{"href":42,"rel":43},"https://bbs.huaweicloud.com/forum/forum-1076-1.html",[44],"nofollow",[46],{"type":24,"value":47},"MindSpore论坛",{"type":18,"tag":26,"props":49,"children":50},{},[51,53],{"type":24,"value":52},"作者：",{"type":18,"tag":40,"props":54,"children":57},{"href":55,"rel":56},"https://bbs.huaweicloud.com/forum/home.php?mod=space&uid=204796&do=thread",[44],[58],{"type":24,"value":59},"胡琦",{"type":18,"tag":26,"props":61,"children":62},{},[63],{"type":24,"value":64},"大家好，我是 Copy攻城狮 ，专注“写” Hello World 30年，因此被亲切称为“HW工程师”。几个月前，有幸体验MindSpore新年新版本，前所未有的丝滑,3个月一个大版本，新版本又来了！今天，本大狮给小伙伴们带来了全新的体验，这是您没玩过的全新版本 -- 使用云编辑器 CloudIDE 运行 MindSpore 1.2，体验 MindSpore 新特性！",{"type":18,"tag":26,"props":66,"children":67},{},[68],{"type":18,"tag":30,"props":69,"children":71},{"alt":7,"src":70},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/6fe266de75e143d499a4fabd63bf6999.png",[],{"type":18,"tag":26,"props":73,"children":74},{},[75],{"type":24,"value":76},"首先，本大狮认为全宇宙最牛叉的 IDE 一定是 VSCode ，因此，众多云厂商的云编辑器都基于 VSCode Online 实现。华为云的 CloudIDE 也不例外。",{"type":18,"tag":26,"props":78,"children":79},{},[80],{"type":24,"value":81},"CloudIDE 是面向云原生的轻量级WebIDE，通过浏览器访问即可实现云端开发环境获取、代码编写、编译调试、运行预览、访问代码仓库、命令行执行等能力，同时支持丰富的插件扩展。",{"type":18,"tag":26,"props":83,"children":84},{},[85],{"type":24,"value":86},"在线体验地址：",{"type":18,"tag":26,"props":88,"children":89},{},[90],{"type":18,"tag":40,"props":91,"children":94},{"href":92,"rel":93},"https://devcloud.cn-north-4.huaweicloud.com/cloudide/trial",[44],[95],{"type":24,"value":92},{"type":18,"tag":26,"props":97,"children":98},{},[99],{"type":24,"value":100},"CloudIDE 入口：",{"type":18,"tag":26,"props":102,"children":103},{},[104],{"type":18,"tag":30,"props":105,"children":107},{"alt":7,"src":106},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/64870d28e551437bb23ae8c1fae958f3.jpg",[],{"type":18,"tag":26,"props":109,"children":110},{},[111],{"type":24,"value":112},"CloudIDE 实例：",{"type":18,"tag":26,"props":114,"children":115},{},[116],{"type":18,"tag":30,"props":117,"children":119},{"alt":7,"src":118},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/e91640984a9e4db2899dd365f92a9187.jpg",[],{"type":18,"tag":26,"props":121,"children":122},{},[123],{"type":24,"value":124},"到什么山唱什么歌，既然来到了 MindSpore 的地盘，先来个 Python 的环境。",{"type":18,"tag":26,"props":126,"children":127},{},[128],{"type":24,"value":129},"看看我使用的环境配置：",{"type":18,"tag":26,"props":131,"children":132},{},[133],{"type":18,"tag":30,"props":134,"children":136},{"alt":7,"src":135},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/39ef70b0eea8417d95b05fecbc8c3837.jpg",[],{"type":18,"tag":26,"props":138,"children":139},{},[140],{"type":24,"value":141},"在看看 Python 版本：",{"type":18,"tag":143,"props":144,"children":146},"pre",{"code":145},"user@ru76x7kqbuu-machine:~$ python --version\nPython 3.7.0\n",[147],{"type":18,"tag":148,"props":149,"children":150},"code",{"__ignoreMap":7},[151],{"type":24,"value":145},{"type":18,"tag":26,"props":153,"children":154},{},[155],{"type":24,"value":156},"勉强满足 MindSpore 推荐的 Python 3.7.5，至少大版本相同。",{"type":18,"tag":26,"props":158,"children":159},{},[160],{"type":18,"tag":30,"props":161,"children":163},{"alt":7,"src":162},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/625e6ea77be44005a84ad50d902cc64e.png",[],{"type":18,"tag":26,"props":165,"children":166},{},[167],{"type":24,"value":168},"这界面是不是像极了 VSCode ？终端命令行走起：",{"type":18,"tag":143,"props":170,"children":172},{"code":171},"pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/1.2.0-rc1/MindSpore/cpu/ubuntu_aarch64/mindspore-1.2.0rc1-cp37-cp37m-linux_aarch64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple\n# 注意参考下方安装指南，确保安装依赖以及环境变量配置正确\n",[173],{"type":18,"tag":148,"props":174,"children":175},{"__ignoreMap":7},[176],{"type":24,"value":171},{"type":18,"tag":26,"props":178,"children":179},{},[180],{"type":24,"value":181},"轻松Copy，一键安装，默认使用华为云的镜像，安装速度倍儿快。",{"type":18,"tag":26,"props":183,"children":184},{},[185],{"type":18,"tag":30,"props":186,"children":188},{"alt":7,"src":187},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/cfefaa234158461ab57b94336dd36be1.jpg",[],{"type":18,"tag":26,"props":190,"children":191},{},[192],{"type":24,"value":193},"再来一行代码检查一下是否安装正常：",{"type":18,"tag":26,"props":195,"children":196},{},[197],{"type":18,"tag":30,"props":198,"children":200},{"alt":7,"src":199},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/a0964471b846438fb0ecae5d166c1a65.jpg",[],{"type":18,"tag":143,"props":202,"children":204},{"code":203},"user@ru76x7kqbuu-machine:~$ python -c \"import mindspore;print(mindspore.__version__)\"\n1.2.0-rc1\n",[205],{"type":18,"tag":148,"props":206,"children":207},{"__ignoreMap":7},[208],{"type":24,"value":203},{"type":18,"tag":26,"props":210,"children":211},{},[212],{"type":24,"value":213},"哦，天哪，安装居然如此简单，如此丝滑。这里不得不吐槽一下 tf 1.15.0 的安装，直接白白浪费了本大狮一个多小时，各种报错。",{"type":18,"tag":26,"props":215,"children":216},{},[217],{"type":18,"tag":30,"props":218,"children":220},{"alt":7,"src":219},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/e8e747cd76014236be9ae07e08164e6b.png",[],{"type":18,"tag":26,"props":222,"children":223},{},[224],{"type":24,"value":225},"作为Copy攻城狮，最厉害的技能无非就是复制粘贴了，因此我们可以直接 clone MindSpore 的 docs 仓库：",{"type":18,"tag":143,"props":227,"children":229},{"code":228},"git clone https://gitee.com/mindspore/docs\n",[230],{"type":18,"tag":148,"props":231,"children":232},{"__ignoreMap":7},[233],{"type":24,"value":228},{"type":18,"tag":26,"props":235,"children":236},{},[237],{"type":24,"value":238},"好了，文档有了，代码也有了，还有 .ipynb 文件也有了，请开始学习吧！",{"type":18,"tag":26,"props":240,"children":241},{},[242],{"type":24,"value":243},"从 quick_start.ipynb 开始，开始我们的 MindSpore 学习之旅！",{"type":18,"tag":26,"props":245,"children":246},{},[247],{"type":18,"tag":30,"props":248,"children":250},{"alt":7,"src":249},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/010403a488334668b0ef0453f47233c3.jpg",[],{"type":18,"tag":26,"props":252,"children":253},{},[254],{"type":24,"value":255},"CloudIDE 默认支持解析.ipynb 文件，也许是我选用的 Python 开发环境自动安装的。这是一个手写数字识别的案例，运行 1875 步之后，我们获得的训练结果：",{"type":18,"tag":143,"props":257,"children":259},{"code":258},"epoch: 1 step: 1872, loss is 0.08411364\nepoch: 1 step: 1873, loss is 0.07816357\nepoch: 1 step: 1874, loss is 0.026486307\nepoch: 1 step: 1875, loss is 0.09032617\n{'Accuracy': 0.9582331730769231}\n",[260],{"type":18,"tag":148,"props":261,"children":262},{"__ignoreMap":7},[263],{"type":24,"value":258},{"type":18,"tag":26,"props":265,"children":266},{},[267],{"type":24,"value":268},"不得不感叹，云时代的到来，给我们带来了太多的便利。",{"type":18,"tag":26,"props":270,"children":271},{},[272],{"type":24,"value":273},"不过目前 MindSpore 新特性大部分集中在 GPU 和 Ascend 环境，因此本文不做过多体验。题外话，想体验 TinyMS ， 暂时只有 MindSpore 1.1.1 支持：",{"type":18,"tag":26,"props":275,"children":276},{},[277],{"type":18,"tag":30,"props":278,"children":280},{"alt":7,"src":279},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/45932c7254a046f190beb967f184550f.jpg",[],{"type":18,"tag":26,"props":282,"children":283},{},[284,286],{"type":24,"value":285},"TinyMS 文档地址：",{"type":18,"tag":40,"props":287,"children":290},{"href":288,"rel":289},"https://tinyms.readthedocs.io/zh_CN/latest/index.html",[44],[291],{"type":24,"value":288},{"type":18,"tag":26,"props":293,"children":294},{},[295],{"type":18,"tag":30,"props":296,"children":298},{"alt":7,"src":297},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/e1a3845feb9342a7967315af011826bf.png",[],{"type":18,"tag":26,"props":300,"children":301},{},[302],{"type":24,"value":303},"重新安装 MindSpore 1.1.1",{"type":18,"tag":143,"props":305,"children":307},{"code":306},"pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/1.1.1/MindSpore/cpu/ubuntu_aarch64/mindspore-1.1.1-cp37-cp37m-linux_aarch64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple\n",[308],{"type":18,"tag":148,"props":309,"children":310},{"__ignoreMap":7},[311],{"type":24,"value":306},{"type":18,"tag":26,"props":313,"children":314},{},[315],{"type":24,"value":316},"安装 TinyMS",{"type":18,"tag":143,"props":318,"children":320},{"code":319},"pip install tinyms\n",[321],{"type":18,"tag":148,"props":322,"children":323},{"__ignoreMap":7},[324],{"type":24,"value":319},{"type":18,"tag":26,"props":326,"children":327},{},[328],{"type":24,"value":329},"验证安装：",{"type":18,"tag":143,"props":331,"children":333},{"code":332},"import tinyms as ts\nfrom tinyms.primitives import tensor_add\n\nx = ts.ones([2, 3])\ny = ts.ones([2, 3])\nprint(tensor_add(x, y))\n",[334],{"type":18,"tag":148,"props":335,"children":336},{"__ignoreMap":7},[337],{"type":24,"value":332},{"type":18,"tag":26,"props":339,"children":340},{},[341],{"type":18,"tag":30,"props":342,"children":344},{"alt":7,"src":343},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/323d3da3779546719ecefec2c72798a7.jpg",[],{"type":18,"tag":26,"props":346,"children":347},{},[348],{"type":24,"value":349},"妥妥的！接下来就是按照官方文档，「在一分钟内实现一个图形分类应用」！",{"type":18,"tag":26,"props":351,"children":352},{},[353],{"type":24,"value":354},"依旧是Lenet手写数字识别，我们可以使用之前的数据集，也可以重新再下载，重新下载的话等待时间稍微有点久。不过使用 CloudIDE 的时候要留意文件夹权限，我们将源码中的 /root 替换为 ./data,规避文件夹权限不够的问题。",{"type":18,"tag":26,"props":356,"children":357},{},[358],{"type":18,"tag":30,"props":359,"children":361},{"alt":7,"src":360},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/11b899492b1f42b6a9cd585b7dce1584.jpg",[],{"type":18,"tag":26,"props":363,"children":364},{},[365],{"type":24,"value":366},"接着就是训练模型(操作总是惊人的相似，也修改了文件路径)：",{"type":18,"tag":26,"props":368,"children":369},{},[370],{"type":18,"tag":30,"props":371,"children":373},{"alt":7,"src":372},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/ab5dc112ab134a03a3ec4c60de34ca11.jpg",[],{"type":18,"tag":26,"props":375,"children":376},{},[377],{"type":24,"value":378},"等待训练完毕之后，为推理做准备，TinyMS推理是C/S（Client/Server）架构。TinyMS使用Flask这个轻量化的网页服务器架构作为C/S通讯的基础架构。",{"type":18,"tag":26,"props":380,"children":381},{},[382],{"type":24,"value":383},"……",{"type":18,"tag":26,"props":385,"children":386},{},[387],{"type":24,"value":388},"当我满怀期待想要尝试推理部署时，发现 servable_path暂时不能自定义，当我调用list_servables()时，由于在 CloudIDE 上没有权限写入文件到 /etc等目录，因此也无法读取到我定义的servable.json。体验到此告一段落！",{"type":18,"tag":26,"props":390,"children":391},{},[392],{"type":18,"tag":30,"props":393,"children":395},{"alt":7,"src":394},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/a0404b0d2b9a4c7cad86de2c4132087b.jpg",[],{"type":18,"tag":26,"props":397,"children":398},{},[399],{"type":24,"value":400},"后续我会尝试在 Linux 上再次体验！同时也期待在未来TinyMS可以支持更自由的配置。",{"type":18,"tag":26,"props":402,"children":403},{},[404],{"type":18,"tag":30,"props":405,"children":407},{"alt":7,"src":406},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/cc26de4a78254a748286b4c29edf1ce2.png",[],{"type":18,"tag":26,"props":409,"children":410},{},[411],{"type":24,"value":412},"TinyMS旨在基于MindSpore提供简单有效的高阶API、低运行开销、模块化开发以及敏捷部署。相较于市面上其他高阶API项目，TinyMS着重于提升开发者对已有框架即MindSpore的使用体验，尤其是面向全场景的开发和部署。",{"type":18,"tag":26,"props":414,"children":415},{},[416],{"type":18,"tag":30,"props":417,"children":419},{"alt":7,"src":418},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/fa47be9394a547658ed7df91680d6a09.png",[],{"type":18,"tag":26,"props":421,"children":422},{},[423,430],{"type":18,"tag":40,"props":424,"children":427},{"href":425,"rel":426},"https://www.bilibili.com/video/BV1Tp4y1b7UG/?spm_id_from=333.788.recommend_more_video.0",[44],[428],{"type":24,"value":429},"点击这里",{"type":24,"value":431},"进行观看",{"type":18,"tag":26,"props":433,"children":434},{},[435,437,443],{"type":24,"value":436},"感兴趣的小伙伴，可以加小助手微信（记得",{"type":18,"tag":438,"props":439,"children":440},"strong",{},[441],{"type":24,"value":442},"备注：追剧",{"type":24,"value":444},"）与小伙伴们一起学知识！",{"type":18,"tag":26,"props":446,"children":447},{},[448],{"type":18,"tag":30,"props":449,"children":451},{"alt":7,"src":450},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/ffa02cbfde034d348a7f7025acd14f2a.jpg",[],{"type":18,"tag":26,"props":453,"children":454},{},[455],{"type":24,"value":456},"小助手微信:mindspore0328",{"type":18,"tag":26,"props":458,"children":459},{},[460],{"type":18,"tag":30,"props":461,"children":463},{"alt":7,"src":462},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/1c0578cfe8934129bfa5b90278461584.png",[],{"type":18,"tag":26,"props":465,"children":466},{},[467],{"type":24,"value":468},"MindSpore官方资料",{"type":18,"tag":26,"props":470,"children":471},{},[472,474],{"type":24,"value":473},"GitHub : ",{"type":18,"tag":40,"props":475,"children":478},{"href":476,"rel":477},"https://github.com/mindspore-ai/mindspore",[44],[479],{"type":24,"value":476},{"type":18,"tag":26,"props":481,"children":482},{},[483],{"type":24,"value":484},"Gitee:[https : //gitee.com/mindspore/mindspore](https : //gitee.com/mindspore/mindspore)",{"type":18,"tag":26,"props":486,"children":487},{},[488],{"type":24,"value":489},"官方QQ群 : 871543426",{"type":18,"tag":26,"props":491,"children":492},{},[493],{"type":24,"value":494},"长按下方二维码加入MindSpore项目↓",{"type":18,"tag":26,"props":496,"children":497},{},[498],{"type":18,"tag":30,"props":499,"children":501},{"alt":7,"src":500},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/05/18/21db9c6ed7bc41709d04e15bd3f4bd8d.jpg",[],{"title":7,"searchDepth":503,"depth":503,"links":504},4,[],"markdown","content:technology-blogs:zh:558.md","content","technology-blogs/zh/558.md","technology-blogs/zh/558","md",1776506137797]