[{"data":1,"prerenderedAt":795},["ShallowReactive",2],{"content-query-95Kx9otV7C":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":789,"_id":790,"_source":791,"_file":792,"_stem":793,"_extension":794},"/technology-blogs/zh/3389","zh",false,"","基于ms香橙派AIpro实现垃圾回收AI识别方案五：香橙派OrangePi AIpro实践(基于MobileNetv2的垃圾分类)","六、香橙派OrangePi AIpro实践 - 基于MobileNetv2的垃圾分类","2024-08-04","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/11/28/5c67af5d428549f7ad2878565615cc5a.png","technology-blogs","调试调优",{"type":15,"children":16,"toc":776},"root",[17,25,38,48,58,68,77,87,91,97,106,111,117,122,142,145,151,156,174,182,187,194,199,217,224,229,236,239,245,250,255,264,269,274,279,284,289,294,299,304,309,314,319,324,329,334,339,344,349,354,359,364,371,379,382,388,402,409,417,436,441,454,461,464,470,475,485,490,497,505,510,518,523,531,538,543,551,558,563,566,572,580,585,590,595,602,607,612,620,625,632,637,655,660,678,683,686,692,700,705,712,717,725,732,740,745,753,759,764,771],{"type":18,"tag":19,"props":20,"children":22},"element","h1",{"id":21},"基于ms香橙派aipro实现垃圾回收ai识别方案五香橙派orangepi-aipro实践基于mobilenetv2的垃圾分类",[23],{"type":24,"value":8},"text",{"type":18,"tag":26,"props":27,"children":28},"p",{},[29],{"type":18,"tag":30,"props":31,"children":35},"a",{"href":32,"rel":33},"https://www.hiascend.com/developer/blog/details/0272157975874351541",[34],"nofollow",[36],{"type":24,"value":37},"基于ms香橙派AIpro实现垃圾回收AI识别方案一：昇思MindSpore介绍",{"type":18,"tag":26,"props":39,"children":40},{},[41],{"type":18,"tag":30,"props":42,"children":45},{"href":43,"rel":44},"https://www.hiascend.com/developer/blog/details/02111171533919729183",[34],[46],{"type":24,"value":47},"基于ms香橙派AIpro实现垃圾回收AI识别方案二：昇思MindSpore如何使用",{"type":18,"tag":26,"props":49,"children":50},{},[51],{"type":18,"tag":30,"props":52,"children":55},{"href":53,"rel":54},"https://www.hiascend.com/developer/blog/details/0272158138234394548",[34],[56],{"type":24,"value":57},"基于ms香橙派AIpro实现垃圾回收AI识别方案三：昇思大模型平台jupyter快速入门体验",{"type":18,"tag":26,"props":59,"children":60},{},[61],{"type":18,"tag":30,"props":62,"children":65},{"href":63,"rel":64},"https://www.hiascend.com/developer/blog/details/0272158143705280549",[34],[66],{"type":24,"value":67},"基于ms香橙派AIpro实现垃圾回收AI识别方案四：MindSpore应用实践 - 基于MobileNetv2的垃圾分类",{"type":18,"tag":26,"props":69,"children":70},{},[71],{"type":18,"tag":30,"props":72,"children":75},{"href":73,"rel":74},"https://www.hiascend.com/developer/blog/details/0272158155371368550",[34],[76],{"type":24,"value":8},{"type":18,"tag":26,"props":78,"children":79},{},[80],{"type":18,"tag":30,"props":81,"children":84},{"href":82,"rel":83},"https://www.hiascend.com/developer/blog/details/0265158167508388542",[34],[85],{"type":24,"value":86},"基于ms香橙派AIpro实现垃圾回收AI识别方案六：SOWT分析与总结",{"type":18,"tag":88,"props":89,"children":90},"hr",{},[],{"type":18,"tag":92,"props":93,"children":95},"h2",{"id":94},"六香橙派orangepi-aipro实践-基于mobilenetv2的垃圾分类",[96],{"type":24,"value":9},{"type":18,"tag":98,"props":99,"children":100},"blockquote",{},[101],{"type":18,"tag":26,"props":102,"children":103},{},[104],{"type":24,"value":105},"昇腾样例仓提供了一系列媒体数据处理（DVPP/AIPP）、算子开发与调用（Ascend C）、推理应用开发与部署（AscendCL）等场景的丰富代码样例给开发者进行参考学习，帮助开发者快速入门，进而熟练掌握CANN关键特性使用。",{"type":18,"tag":26,"props":107,"children":108},{},[109],{"type":24,"value":110},"上面章节通过官方的示例，基于昇腾软件栈的MobileNetV2垃圾分类的训练过程，通过使用mobilenetV2模型对输入图片进行分类推理，提供待推理的jpg图片，进行推理后，输出推理后的jpg图片。",{"type":18,"tag":92,"props":112,"children":114},{"id":113},"_61-orangepi-aipro的亮点",[115],{"type":24,"value":116},"6.1 OrangePi AIpro的亮点：",{"type":18,"tag":26,"props":118,"children":119},{},[120],{"type":24,"value":121},"OrangePi AIpro(8-12T)采用昇腾AI技术路线，具体为4核64位处理器+AI处理器，集成图形处理器，支持8-12TOPS AI算力，拥有8GB/16GB LPDDR4X，可以外接32GB/64GB/128GB/256GB eMMC模块，支持双4K高清输出。",{"type":18,"tag":123,"props":124,"children":125},"ul",{},[126,132,137],{"type":18,"tag":127,"props":128,"children":129},"li",{},[130],{"type":24,"value":131},"丰富的接口：包括两个HDMI输出、GPIO接口、Type-C电源接口、支持SATA/NVMe SSD 2280的M.2插槽、TF插槽、千兆网口、两个USB3.0、一个USB Type-C 3.0、一个Micro USB（串口打印调试功能）、两个MIPI摄像头、一个MIPI屏等，预留电池接口。",{"type":18,"tag":127,"props":133,"children":134},{},[135],{"type":24,"value":136},"广泛适的应用场景：可用于AI边缘计算、深度视觉学习及视频流AI分析、视频图像分析、自然语言处理、智能小车、机械臂、人工智能、无人机、云计算、AR/VR、智能安防、智能家居等领域，覆盖 AIoT各个行业。",{"type":18,"tag":127,"props":138,"children":139},{},[140],{"type":24,"value":141},"系统支持：Orange Pi AIpro支持Ubuntu、openEuler操作系统，满足大多数AI算法原型验证、推理应用开发的需求。",{"type":18,"tag":88,"props":143,"children":144},{},[],{"type":18,"tag":92,"props":146,"children":148},{"id":147},"_62-环境搭建",[149],{"type":24,"value":150},"6.2 环境搭建：",{"type":18,"tag":26,"props":152,"children":153},{},[154],{"type":24,"value":155},"在评测之前，除了官方提供了一些配件外，还有一些需要自行提前准备的东西，自行提供的配件清单：",{"type":18,"tag":123,"props":157,"children":158},{},[159,164,169],{"type":18,"tag":127,"props":160,"children":161},{},[162],{"type":24,"value":163},"TF读卡器",{"type":18,"tag":127,"props":165,"children":166},{},[167],{"type":24,"value":168},"HDMI显示器连接线",{"type":18,"tag":127,"props":170,"children":171},{},[172],{"type":24,"value":173},"串口测试线",{"type":18,"tag":26,"props":175,"children":176},{},[177],{"type":18,"tag":178,"props":179,"children":181},"img",{"alt":7,"src":180},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/6a4/0ed/bc6/0421bb776e6a40edbc68b6389cfec54d.20240804114834.26792269502534196645327163916388:20240913013531:2400:2D43224C618D326E7DFE686BB4B354D663388937D3A5C92489A61F7B7B6658F1.jpg",[],{"type":18,"tag":26,"props":183,"children":184},{},[185],{"type":24,"value":186},"首先打开balena烧录工具地址，因为个人办公是Mac电脑，借用了同事的Windows电脑来进行此次的测试，我们选择OS为“WINDOWS”的X86|X64版本下载。",{"type":18,"tag":26,"props":188,"children":189},{},[190],{"type":18,"tag":178,"props":191,"children":193},{"alt":7,"src":192},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/6a4/0ed/bc6/0421bb776e6a40edbc68b6389cfec54d.20240804114858.36349013151789996113647138308368:20240913013531:2400:F8400690366DCA7B82852A7BA47B49B5D2BD38D63C69133DEA8D88D137BF0C60.jpg",[],{"type":18,"tag":26,"props":195,"children":196},{},[197],{"type":24,"value":198},"打开下载的balena烧录工具，不用安装，直接就打开了，非常的方便，不用在电脑上安装软件：",{"type":18,"tag":123,"props":200,"children":201},{},[202,207,212],{"type":18,"tag":127,"props":203,"children":204},{},[205],{"type":24,"value":206},"点击“从文件烧录”选择好我们提前下载的镜像（百度云真的慢）",{"type":18,"tag":127,"props":208,"children":209},{},[210],{"type":24,"value":211},"点击“选择目标磁盘”选中我们插入的TF卡(我提前格式化了)",{"type":18,"tag":127,"props":213,"children":214},{},[215],{"type":24,"value":216},"点击“现在烧录”就可以开始进行烧录了",{"type":18,"tag":26,"props":218,"children":219},{},[220],{"type":18,"tag":178,"props":221,"children":223},{"alt":7,"src":222},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/6a4/0ed/bc6/0421bb776e6a40edbc68b6389cfec54d.20240804114927.11569824561629418915587204046854:20240913013531:2400:D251148ECA69DB444EF7656B57C7A3ADB41A731E310364E146E40EFBBD89A929.jpg",[],{"type":18,"tag":26,"props":225,"children":226},{},[227],{"type":24,"value":228},"经过2个阶段，一个是验证阶段，一个是烧录阶段，不过，可惜的是最后一步出错了，百度一下有人说可以不用管，先尝试一下可不可以开机。",{"type":18,"tag":26,"props":230,"children":231},{},[232],{"type":18,"tag":178,"props":233,"children":235},{"alt":7,"src":234},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/6a4/0ed/bc6/0421bb776e6a40edbc68b6389cfec54d.20240804114931.84942077829838435360581790524166:20240913013531:2400:3826C1AB5EA6F60D42A2FD7F1A31D5E88EF49DEEF6B68676D38221E80C0ECCC1.jpg",[],{"type":18,"tag":88,"props":237,"children":238},{},[],{"type":18,"tag":92,"props":240,"children":242},{"id":241},"_63-机器组装",[243],{"type":24,"value":244},"6.3 机器组装：",{"type":18,"tag":26,"props":246,"children":247},{},[248],{"type":24,"value":249},"插入USB的鼠标和键盘、显示器HDMI线、自带的type-c电源线后，即可以去插上电源了，一插入就自动启动了，没有什么开机键，即一通电就自动启动，但是有一个问题，等了5分钟除了风扇一直响外，显示器一直不显示，猜测是之前的烧录有问题。",{"type":18,"tag":26,"props":251,"children":252},{},[253],{"type":24,"value":254},"排查原因：",{"type":18,"tag":26,"props":256,"children":257},{},[258,260],{"type":24,"value":259},"|",{"type":18,"tag":178,"props":261,"children":263},{"alt":7,"src":262},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/6a4/0ed/bc6/0421bb776e6a40edbc68b6389cfec54d.20240804115004.24581280447501555431389942347084:20240913013531:2400:164A1491C0F6F3BD95A9763EDBB35E8A188F7986155BC02B727BDA3629CAD16E.jpg",[],{"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},"可能存在问题点",{"type":18,"tag":26,"props":275,"children":276},{},[277],{"type":24,"value":278},"解决方案",{"type":18,"tag":26,"props":280,"children":281},{},[282],{"type":24,"value":283},"难度",{"type":18,"tag":26,"props":285,"children":286},{},[287],{"type":24,"value":288},"1",{"type":18,"tag":26,"props":290,"children":291},{},[292],{"type":24,"value":293},"检查一下控制启动设备的两个拨码开关，要想从TF卡启动，需要都是右",{"type":18,"tag":26,"props":295,"children":296},{},[297],{"type":24,"value":298},"检查无问题",{"type":18,"tag":26,"props":300,"children":301},{},[302],{"type":24,"value":303},"1星",{"type":18,"tag":26,"props":305,"children":306},{},[307],{"type":24,"value":308},"2",{"type":18,"tag":26,"props":310,"children":311},{},[312],{"type":24,"value":313},"可能烧录的时候出现上面异常，导致无法亮灯",{"type":18,"tag":26,"props":315,"children":316},{},[317],{"type":24,"value":318},"可以尝试使用网友提供的ascend重新烧录一下",{"type":18,"tag":26,"props":320,"children":321},{},[322],{"type":24,"value":323},"2星",{"type":18,"tag":26,"props":325,"children":326},{},[327],{"type":24,"value":328},"3",{"type":18,"tag":26,"props":330,"children":331},{},[332],{"type":24,"value":333},"手里是否有备用TF卡，不过最好使用容量大点的，32G以上，推荐64G",{"type":18,"tag":26,"props":335,"children":336},{},[337],{"type":24,"value":338},"需要买一张备用卡",{"type":18,"tag":26,"props":340,"children":341},{},[342],{"type":24,"value":343},"3星",{"type":18,"tag":26,"props":345,"children":346},{},[347],{"type":24,"value":348},"4",{"type":18,"tag":26,"props":350,"children":351},{},[352],{"type":24,"value":353},"可能开发板子存在问题",{"type":18,"tag":26,"props":355,"children":356},{},[357],{"type":24,"value":358},"这个需要专业人员来解决",{"type":18,"tag":26,"props":360,"children":361},{},[362],{"type":24,"value":363},"4星",{"type":18,"tag":26,"props":365,"children":366},{},[367],{"type":18,"tag":178,"props":368,"children":370},{"alt":7,"src":369},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/6a4/0ed/bc6/0421bb776e6a40edbc68b6389cfec54d.20240804115133.64428920026313113780889705921852:20240913013531:2400:8D59F6A1F20487A816CEDB33EA0A8D42232BFD302BDAA89EC74F9DB48FE2F10F.jpg",[],{"type":18,"tag":98,"props":372,"children":373},{},[374],{"type":18,"tag":26,"props":375,"children":376},{},[377],{"type":24,"value":378},"因为手里没有备用的TF卡，只能通过第二种方案换一种工具来进行烧录试试，如果网友可以成功启动，就不需要下一步操作。",{"type":18,"tag":88,"props":380,"children":381},{},[],{"type":18,"tag":92,"props":383,"children":385},{"id":384},"_64-替换烧录工具",[386],{"type":24,"value":387},"6.4 替换烧录工具：",{"type":18,"tag":26,"props":389,"children":390},{},[391,393,400],{"type":24,"value":392},"在网友的推荐下，使用了另外一个烧录工具",{"type":18,"tag":30,"props":394,"children":397},{"href":395,"rel":396},"https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/Atlas%20200I%20DK%20A2/DevKit/tools/latest/Ascend-devkit-imager_latest_win-x86_64.exe",[34],[398],{"type":24,"value":399},"ascend",{"type":24,"value":401},"，不过这个工具需要下一步下一步安装，就不过多复述了。",{"type":18,"tag":26,"props":403,"children":404},{},[405],{"type":18,"tag":178,"props":406,"children":408},{"alt":7,"src":407},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/6a4/0ed/bc6/0421bb776e6a40edbc68b6389cfec54d.20240804115212.27288765372777869408486279485583:20240913013531:2400:09A49BD5324B6C3FF7A91492B02D25CAA1FD132DFECD271DBED7BE4ACEC42BA7.jpg",[],{"type":18,"tag":98,"props":410,"children":411},{},[412],{"type":18,"tag":26,"props":413,"children":414},{},[415],{"type":24,"value":416},"小细节：",{"type":18,"tag":418,"props":419,"children":420},"ol",{},[421,426,431],{"type":18,"tag":127,"props":422,"children":423},{},[424],{"type":24,"value":425},"烧录时，提示U盘找不到，需要重新插入，此时，不用管他的提示。",{"type":18,"tag":127,"props":427,"children":428},{},[429],{"type":24,"value":430},"在烧录完成后，提示要格式化，也不需要管，因为在烧录时，就已经开始写成linux的启动镜像盘了，此时，在windows系统是无法识别的，是正常的。",{"type":18,"tag":127,"props":432,"children":433},{},[434],{"type":24,"value":435},"第一次烧的时候，看到东西就点，点快了，结果重新烧录了一次，需要注意一下。",{"type":18,"tag":26,"props":437,"children":438},{},[439],{"type":24,"value":440},"通过重新烧录之后，我们的系统就可以正常启动了，启动时，需要输入一个用户名密码，非常的开心，后面使用SSH也需要使用到。",{"type":18,"tag":123,"props":442,"children":443},{},[444,449],{"type":18,"tag":127,"props":445,"children":446},{},[447],{"type":24,"value":448},"用户名：HwHiAiUser",{"type":18,"tag":127,"props":450,"children":451},{},[452],{"type":24,"value":453},"密码：Mind@123",{"type":18,"tag":26,"props":455,"children":456},{},[457],{"type":18,"tag":178,"props":458,"children":460},{"alt":7,"src":459},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/6a4/0ed/bc6/0421bb776e6a40edbc68b6389cfec54d.20240804115246.24445436868485076346395846160004:20240913013531:2400:5513AC121D87737BDC48CF534982B7085680191CD3B432D4536B631FD74506CC.jpg",[],{"type":18,"tag":88,"props":462,"children":463},{},[],{"type":18,"tag":92,"props":465,"children":467},{"id":466},"_65-链接wifi使用ssh登录",[468],{"type":24,"value":469},"6.5 链接Wifi，使用SSH登录：",{"type":18,"tag":26,"props":471,"children":472},{},[473],{"type":24,"value":474},"因为没有联网，所以，只能在显示器上进行Wifi的联网操作，联网后输入ifconfig查看Wifi的IP地址，在同一个局域网，使用ping ip地址保证网是能连通的情况下，我们就可以使用我工作的主机来SSH登录到开发板子上了，这样操作起来比较便捷。",{"type":18,"tag":476,"props":477,"children":479},"pre",{"code":478},"# 查看主机IP地址\nifconfig\n\n# 检查网络是否连通\nping 192.xx.xx.xx\n",[480],{"type":18,"tag":481,"props":482,"children":483},"code",{"__ignoreMap":7},[484],{"type":24,"value":478},{"type":18,"tag":26,"props":486,"children":487},{},[488],{"type":24,"value":489},"使用ssh远程链接到OrangePi AIpro开发板上，接下来可以进行环境的初始化，安装一些相关的依赖环境。",{"type":18,"tag":26,"props":491,"children":492},{},[493],{"type":18,"tag":178,"props":494,"children":496},{"alt":7,"src":495},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/6a4/0ed/bc6/0421bb776e6a40edbc68b6389cfec54d.20240804115308.61368568335343491634738715422005:20240913013531:2400:D8CE0253A8F13CB2CB24EAF00469117523B280FDC727C109A3CCAA9B217E29DE.jpg",[],{"type":18,"tag":98,"props":498,"children":499},{},[500],{"type":18,"tag":26,"props":501,"children":502},{},[503],{"type":24,"value":504},"硬件要求：因为样例使用到opencv，ffmpeg等第三方依赖进行图像等处理，所以需要在运行之前，根据本文指导安装第三方依赖并进行环境配置。 由于python的开发过程不依赖于编译，所以第三方依赖安装都在运行环境进行操作，第三方依赖python-acllite 请参考第三方依赖选择需要的依赖完成安装。",{"type":18,"tag":26,"props":506,"children":507},{},[508],{"type":24,"value":509},"配置编译依赖的头文件与库文件路径：",{"type":18,"tag":476,"props":511,"children":513},{"code":512},"export DDK_PATH=/usr/local/Ascend/ascend-toolkit/latest \nexport NPU_HOST_LIB=$DDK_PATH/runtime/lib64/stub\n",[514],{"type":18,"tag":481,"props":515,"children":516},{"__ignoreMap":7},[517],{"type":24,"value":512},{"type":18,"tag":26,"props":519,"children":520},{},[521],{"type":24,"value":522},"运行环境执行以下命令安装相关依赖及ffmpeg：",{"type":18,"tag":476,"props":524,"children":526},{"code":525},"sudo apt-get install ffmpeg libavcodec-dev libswscale-dev libavdevice-dev\n",[527],{"type":18,"tag":481,"props":528,"children":529},{"__ignoreMap":7},[530],{"type":24,"value":525},{"type":18,"tag":26,"props":532,"children":533},{},[534],{"type":18,"tag":178,"props":535,"children":537},{"alt":7,"src":536},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/6a4/0ed/bc6/0421bb776e6a40edbc68b6389cfec54d.20240804115332.18937983558365028746911649319276:20240913013531:2400:46037C79C52F96A018079F4F291F909031A2E2CF7B24666667B936BF13307762.jpg",[],{"type":18,"tag":26,"props":539,"children":540},{},[541],{"type":24,"value":542},"源码安装ACLLite库，获取ACLLite 源码，python acllite库以源码方式提供，安装时将acllite目录拷贝到运行环境的第三方库目录：",{"type":18,"tag":476,"props":544,"children":546},{"code":545},"git clone https://gitee.com/ascend/ACLLite.git\n# 进入到项目目录进行编译, 会编译到上面设置的lib 目录\nbash build_so.sh\n",[547],{"type":18,"tag":481,"props":548,"children":549},{"__ignoreMap":7},[550],{"type":24,"value":545},{"type":18,"tag":26,"props":552,"children":553},{},[554],{"type":18,"tag":178,"props":555,"children":557},{"alt":7,"src":556},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/6a4/0ed/bc6/0421bb776e6a40edbc68b6389cfec54d.20240804115600.68775856520046021787708656709981:20240913013531:2400:403A173C83A7D56B31FD83184BE838F5D43B652998EE6134118B77DF0F840DCF.jpg",[],{"type":18,"tag":26,"props":559,"children":560},{},[561],{"type":24,"value":562},"现在基本的初始化环境已经配置完成了，接下来就是拉取代码的准备和编译了。",{"type":18,"tag":88,"props":564,"children":565},{},[],{"type":18,"tag":92,"props":567,"children":569},{"id":568},"_66-模型转换",[570],{"type":24,"value":571},"6.6 模型转换：",{"type":18,"tag":98,"props":573,"children":574},{},[575],{"type":18,"tag":26,"props":576,"children":577},{},[578],{"type":24,"value":579},"注意：如果是昇腾软件栈的AI推理，需要把原始网络模型 (可能是 PyTorch 的、TensorFlow，也有可能是Caffe的等) 转换成 .om 模型，才能调用昇腾的aclmdlExecute 等模型执行接口在进行模型推理。",{"type":18,"tag":26,"props":581,"children":582},{},[583],{"type":24,"value":584},"这个模型转换的过程就要用到 ATC 工具，目前 ATC 工具直接支持从 Caffe、ONNX、TensorFlow 以及 MindSpore模型的转换，所以如果的训练框架是 PyTorch，则需要做 torch.onnx.export 操作导出成ONNX模型后才能使用ATC工具。",{"type":18,"tag":26,"props":586,"children":587},{},[588],{"type":24,"value":589},"什么是ATC：",{"type":18,"tag":26,"props":591,"children":592},{},[593],{"type":24,"value":594},"昇腾张量编译器（Ascend Tensor Compiler，简称ATC）是昇腾模型转换工具，它可以将开源框架的网络模型（例如TensorFlow、ONNX等）转换为昇腾AI处理器支持的模型文件（.om格式），用于后续的模型推理。",{"type":18,"tag":26,"props":596,"children":597},{},[598],{"type":18,"tag":178,"props":599,"children":601},{"alt":7,"src":600},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/6a4/0ed/bc6/0421bb776e6a40edbc68b6389cfec54d.20240804115627.48915236132391494522215361664044:20240913013531:2400:77E5BA43004E3E14D719A4FE020362EA2442078FFC8F60021B198B2492651EF4.jpg",[],{"type":18,"tag":26,"props":603,"children":604},{},[605],{"type":24,"value":606},"模型转换过程中，ATC会进行算子调度优化、权重数据重排、内存使用优化等操作，对开源框架的网络模型做进一步调优，使其高效地在昇腾AI处理器上执行。",{"type":18,"tag":26,"props":608,"children":609},{},[610],{"type":24,"value":611},"简单的来讲，就是可以将开源框架的网络模型（例如TensorFlow、ONNX等）转换为昇腾AI处理器支持的模型文件（.om格式），用于后续的模型推理，而Orange Ai pro 需要的是.om的格式，所以，需要把pt 的模型转成onnx 格式，再利用平台的 Atc工具转成.om的格式。",{"type":18,"tag":476,"props":613,"children":615},{"code":614},"# 为了方便下载，在这里直接给出原始模型下载及模型转换命令,可以直接拷贝执行\ncd model    \nwget https://obs-9be7.obs.cn-east-2.myhuaweicloud.com:443/003_Atc_Models/AE/ATC%20Model/garbage/mobilenetv2.air   \nwget https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/models/garbage_picture/insert_op_yuv.cfg\natc --model=./mobilenetv2.air --framework=1 --output=garbage_yuv --soc_version= Ascend310B4 --insert_op_conf=./insert_op_yuv.cfg --input_shape=\"data:1,3,224,224\" --input_format=NCHW\n",[616],{"type":18,"tag":481,"props":617,"children":618},{"__ignoreMap":7},[619],{"type":24,"value":614},{"type":18,"tag":26,"props":621,"children":622},{},[623],{"type":24,"value":624},"–framework：原始网络模型框架类型，0：Caffe，1：MindSpore，3：TensorFlow，5：ONNX –soc_version：模型转换时昇腾AI处理器的版本，例如含扩展名 –output：转换后的*.om模型文件路径，含文件名，转换成功后，模型文件名自动以.om后缀结尾 –insert_op_conf: 模型相关的配置文件，包含图像大小，预处理等参数",{"type":18,"tag":26,"props":626,"children":627},{},[628],{"type":18,"tag":178,"props":629,"children":631},{"alt":7,"src":630},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/6a4/0ed/bc6/0421bb776e6a40edbc68b6389cfec54d.20240804115655.90282203140051949543304541316119:20240913013531:2400:CA8F9898FE7102E334DA1B9CF3D046593CB5810A838DA0090CEB90D66F5D8314.jpg",[],{"type":18,"tag":26,"props":633,"children":634},{},[635],{"type":24,"value":636},"mobilenetv2.air文件是一个模型文件：",{"type":18,"tag":123,"props":638,"children":639},{},[640,645,650],{"type":18,"tag":127,"props":641,"children":642},{},[643],{"type":24,"value":644},"‌① . 通常是在模型转换过程中生成的。‌",{"type":18,"tag":127,"props":646,"children":647},{},[648],{"type":24,"value":649},"②. 这个文件包含了模型的架构和权重信息，‌可以用于在特定硬件或软件平台上进行推理。",{"type":18,"tag":127,"props":651,"children":652},{},[653],{"type":24,"value":654},"‌③. 将MobileNetV2模型从PyTorch格式转换为ONNX格式，‌然后再进一步转换为模型格式，‌最终生成了mobilenetv2.air文件。‌",{"type":18,"tag":26,"props":656,"children":657},{},[658],{"type":24,"value":659},"insert_op_yuv.cfg文件则是一个配置文件，：",{"type":18,"tag":123,"props":661,"children":662},{},[663,668,673],{"type":18,"tag":127,"props":664,"children":665},{},[666],{"type":24,"value":667},"①. 用于定义在模型转换或推理过程中需要插入的特定操作或配置。",{"type":18,"tag":127,"props":669,"children":670},{},[671],{"type":24,"value":672},"‌②. 这个文件可能包含了针对特定硬件或软件平台的优化设置，‌以确保模型能够在特定环境下高效运行。‌",{"type":18,"tag":127,"props":674,"children":675},{},[676],{"type":24,"value":677},"③. 可能包含了关于输入数据的预处理、‌输出数据的后处理以及可能的硬件加速指令等信息。 ‌- ④. ‌被用于Ascend芯片上的模型转换过程中，‌以实现模型的优化和加速。‌",{"type":18,"tag":26,"props":679,"children":680},{},[681],{"type":24,"value":682},"总结，通过使用Ascend的实例转换模型非常的快，只用了2分钟就完成了操作，而用香橙派OrangePi AIpro，由于硬件配置原因，转了半小时也没反应，果断换了实例。",{"type":18,"tag":88,"props":684,"children":685},{},[],{"type":18,"tag":92,"props":687,"children":689},{"id":688},"_67-官方的ai-demo项目",[690],{"type":24,"value":691},"6.7 官方的Ai Demo项目：",{"type":18,"tag":476,"props":693,"children":695},{"code":694},"# 开发环境，非root用户命令行中执行以下命令下载源码仓。    \ncd ${HOME}     \ngit clone https://gitee.com/ascend/samples.git\n# 将ZIP包上传到开发环境中的目录中，【例如：${HOME}/ascend-samples-master.zip】\nunzip ascend-samples-master.zip\n# 进入项目\ncd python/contrib/garbage_picture\n",[696],{"type":18,"tag":481,"props":697,"children":698},{"__ignoreMap":7},[699],{"type":24,"value":694},{"type":18,"tag":26,"props":701,"children":702},{},[703],{"type":24,"value":704},"在data中添加一些需要识别的图片：",{"type":18,"tag":26,"props":706,"children":707},{},[708],{"type":18,"tag":178,"props":709,"children":711},{"alt":7,"src":710},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/6a4/0ed/bc6/0421bb776e6a40edbc68b6389cfec54d.20240804115723.82687005062294280469218431933320:20240913013531:2400:C563E30077E89A181A6B27B6EC47A412ECB8901BBDFDF3E9028F81B8CD4A04B7.jpg",[],{"type":18,"tag":26,"props":713,"children":714},{},[715],{"type":24,"value":716},"运行可执行文件：",{"type":18,"tag":476,"props":718,"children":720},{"code":719},"python3 classify_test.py ../data/\n",[721],{"type":18,"tag":481,"props":722,"children":723},{"__ignoreMap":7},[724],{"type":24,"value":719},{"type":18,"tag":26,"props":726,"children":727},{},[728],{"type":18,"tag":178,"props":729,"children":731},{"alt":7,"src":730},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/6a4/0ed/bc6/0421bb776e6a40edbc68b6389cfec54d.20240804115747.69499638789489592245945087722915:20240913013531:2400:F0AF815FF5D225F9391AAF89207F6A66D09EA63CF1F469F159C069C7CB96B4A0.jpg",[],{"type":18,"tag":476,"props":733,"children":735},{"code":734},"#!/usr/bin/env python\n# encoding: utf-8\nimport sys\nimport os\npath = os.path.dirname(os.path.abspath(__file__))\nsys.path.append(os.path.join(path, \"..\"))\nsys.path.append(os.path.join(path, \"../../../common/\"))\nsys.path.append(os.path.join(path, \"../../../common/acllite\"))\n\nimport numpy as np\nimport acl\nimport base64\nimport acllite_utils as utils\nfrom PIL import Image, ImageDraw, ImageFont\nfrom acllite_imageproc import AclLiteImageProc\nimport constants as const\nfrom acllite_model import AclLiteModel\nfrom acllite_image import AclLiteImage\nfrom acllite_resource import AclLiteResource\n\nSRC_PATH = os.path.realpath(__file__).rsplit(\"/\", 1)[0]\nMODEL_PATH = os.path.join(SRC_PATH, \"../model/garbage_yuv.om\")\nMODEL_WIDTH = 224\nMODEL_HEIGHT = 224\nimage_net_classes = [\n \"Seashel\", \"Lighter\",\"Old Mirror\", \"Broom\",\"Ceramic Bowl\", \"Toothbrush\",\"Disposable Chopsticks\",\"Dirty Cloth\",\n     \"Newspaper\", \"Glassware\", \"Basketball\", \"Plastic Bottle\", \"Cardboard\",\"Glass Bottle\", \"Metalware\", \"Hats\", \"Cans\", \"Paper\",\n      \"Vegetable Leaf\",\"Orange Peel\", \"Eggshell\",\"Banana Peel\",\n    \"Battery\", \"Tablet capsules\",\"Fluorescent lamp\", \"Paint bucket\"]\n\n# 中文名列表（与class_en一一对应）\nclass_cn = [\n    '贝壳', '打火机', '旧镜子', '扫把', '陶瓷碗', '牙刷', '一次性筷子', '脏污衣服',\n    '报纸', '玻璃制品', '篮球', '塑料瓶', '硬纸板', '玻璃瓶', '金属制品', '帽子', '易拉罐', '纸张',\n    '菜叶', '橙皮', '蛋壳', '香蕉皮',\n    '电池', '药片胶囊', '荧光灯', '油漆桶'\n]\n\n# 垃圾分类字典\ngarbage_classes = {\n    '干垃圾': ['贝壳', '打火机', '旧镜子', '扫把', '陶瓷碗', '牙刷', '一次性筷子', '脏污衣服'],\n    '可回收物': ['报纸', '玻璃制品', '篮球', '塑料瓶', '硬纸板', '玻璃瓶', '金属制品', '帽子', '易拉罐', '纸张'],\n    '湿垃圾': ['菜叶', '橙皮', '蛋壳', '香蕉皮'],\n    '有害垃圾': ['电池', '药片胶囊', '荧光灯', '油漆桶']\n}\n\n# 建立从class_en到class_cn的映射\nen_to_cn_mapping = dict(zip(image_net_classes, class_cn))\n\n# 查找并推断垃圾分类的函数\ndef infer_garbage_class_for_en(en_class_name):\n    # 使用映射找到对应的中文名\n    cn_class_name = en_to_cn_mapping.get(en_class_name, None)\n    if cn_class_name is None:\n        return '未知'\n    \n    # 遍历所有垃圾分类以找到匹配的中文名\n    for category, classes in garbage_classes.items():\n        if cn_class_name in classes:\n            return category + '[' + cn_class_name + ']'\n    \n    # 如果没有找到匹配项（理论上不应该发生，因为映射是完整的），返回'未知'\n    return '未知'\n\ndef get_image_net_class(class_id):\n    if class_id >= len(image_net_classes):\n        return \"unknown\"\n    else:\n        return image_net_classes[class_id]\n\ndef pre_process(image, dvpp):\n    \"\"\"preprocess\"\"\"\n    image_input = image.copy_to_dvpp()\n    yuv_image = dvpp.jpegd(image_input)\n\n    print(\"decode jpeg end\")\n    resized_image = dvpp.resize(yuv_image,\n                    MODEL_WIDTH, MODEL_HEIGHT)\n\n    print(\"resize yuv end\")\n    return resized_image\n\ndef post_process(infer_output, image_file):\n    print(\"post process\")\n    data = infer_output[0]\n    vals = data.flatten()\n    top_k = vals.argsort()[-1:-6:-1]\n    object_class = get_image_net_class(top_k[0])\n    fontText = infer_garbage_class_for_en(object_class)\n    print(\"infer result: \" + fontText)\n    output_path = os.path.join(os.path.join(SRC_PATH, \"../out\"), os.path.basename(image_file))\n    origin_image = Image.open(image_file)\n    draw = ImageDraw.Draw(origin_image)\n    font = ImageFont.truetype(\"/usr/share/fonts/truetype/wqy/wqy-microhei.ttc\", size=20)\n    font.size =50\n    draw.text((10, 50), fontText, font=font, fill=255)\n    origin_image.save(output_path)\n    object_class = get_image_net_class(top_k[0])\n    return\n\ndef construct_image_info():\n    \"\"\"construct image info\"\"\"\n    image_info = np.array([MODEL_WIDTH, MODEL_HEIGHT,\n                           MODEL_WIDTH, MODEL_HEIGHT],\n                           dtype = np.float32)\n    return image_info\n\ndef main():\n    if (len(sys.argv) != 2):\n        print(\"The App arg is invalid\")\n        exit(1)\n\n    acl_resource = AclLiteResource()\n    acl_resource.init()\n    model = AclLiteModel(MODEL_PATH)\n    dvpp = AclLiteImageProc(acl_resource)\n\n    image_dir = sys.argv[1]\n    images_list = [os.path.join(image_dir, img)\n                   for img in os.listdir(image_dir)\n                   if os.path.splitext(img)[1] in const.IMG_EXT]\n\n    #Create a directory to store the inference results\n    if not os.path.isdir(os.path.join(SRC_PATH, \"../out\")):\n        os.mkdir(os.path.join(SRC_PATH, \"../out\"))\n\n    image_info = construct_image_info()\n    for image_file in images_list:\n        image = AclLiteImage(image_file)\n        resized_image = pre_process(image, dvpp)\n        print(\"pre process end\")\n\n        result = model.execute([resized_image,])\n        post_process(result, image_file)\n\n        print(\"process \"+image_file+\" end\")\nif __name__ == '__main__':\nmain()\n",[736],{"type":18,"tag":481,"props":737,"children":738},{"__ignoreMap":7},[739],{"type":24,"value":734},{"type":18,"tag":26,"props":741,"children":742},{},[743],{"type":24,"value":744},"提示：这里如果使用英文的字体是写不出来中文的，可以确认系统是否已经安装了中文字体，可以使用 fc-list 命令来查看当前系统上安装的所有字体，如下所示：",{"type":18,"tag":476,"props":746,"children":748},{"code":747},"fc-list\n",[749],{"type":18,"tag":481,"props":750,"children":751},{"__ignoreMap":7},[752],{"type":24,"value":747},{"type":18,"tag":92,"props":754,"children":756},{"id":755},"_68-查看结果",[757],{"type":24,"value":758},"6.8 查看结果：",{"type":18,"tag":26,"props":760,"children":761},{},[762],{"type":24,"value":763},"运行完成后，会在out目录下生成带推理结果的jpg图片。",{"type":18,"tag":26,"props":765,"children":766},{},[767],{"type":18,"tag":178,"props":768,"children":770},{"alt":7,"src":769},"https://fileserver.developer.huaweicloud.com/FileServer/getFile/cmtybbs/6a4/0ed/bc6/0421bb776e6a40edbc68b6389cfec54d.20240804115822.26570271874496442879963025453146:20240913013531:2400:B46BB48D4166252EB01E4EE38380512981E3218338071A33275DBC49F99199C0.jpg",[],{"type":18,"tag":26,"props":772,"children":773},{},[774],{"type":24,"value":775},"总结，通过上面的实验，可以看到我们可以很好的在香橙派OrangePi AIpro上运行基于MobileNetV2垃圾分类项目，可以看到有一个电池的图片没有识别正确，识别的结果为“牙刷”，可以增加多一点的图片，再自己训练一下。",{"title":7,"searchDepth":777,"depth":777,"links":778},4,[779,781,782,783,784,785,786,787,788],{"id":94,"depth":780,"text":9},2,{"id":113,"depth":780,"text":116},{"id":147,"depth":780,"text":150},{"id":241,"depth":780,"text":244},{"id":384,"depth":780,"text":387},{"id":466,"depth":780,"text":469},{"id":568,"depth":780,"text":571},{"id":688,"depth":780,"text":691},{"id":755,"depth":780,"text":758},"markdown","content:technology-blogs:zh:3389.md","content","technology-blogs/zh/3389.md","technology-blogs/zh/3389","md",1776506129294]