[{"data":1,"prerenderedAt":317},["ShallowReactive",2],{"content-query-QwLZWYiW0z":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":311,"_id":312,"_source":313,"_file":314,"_stem":315,"_extension":316},"/technology-blogs/en/2676","en",false,"","MindSpore Cases—Running YOLOv5 on Raspberry Pi for Real-Time Object Detection (2)","This blog focuses on the implementation and testing of YOLOv5 on Raspberry Pi 4B (4G)","2023-07-16","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/09/15/35944ce839724cb49cf8fb9ba3affb9a.png","technology-blogs","Practices",{"type":15,"children":16,"toc":308},"root",[17,25,31,39,52,57,68,73,78,87,113,126,131,139,146,158,165,184,196,208,238,247,252,257,262,267,294,301],{"type":18,"tag":19,"props":20,"children":22},"element","h1",{"id":21},"mindspore-casesrunning-yolov5-on-raspberry-pi-for-real-time-object-detection-2",[23],{"type":24,"value":8},"text",{"type":18,"tag":26,"props":27,"children":28},"p",{},[29],{"type":24,"value":30},"The previous blog introduces basic knowledge of YOLOv5, including its network and dataset. This blog focuses on its implementation and testing on Raspberry Pi 4B (4G).",{"type":18,"tag":26,"props":32,"children":33},{},[34],{"type":18,"tag":35,"props":36,"children":38},"img",{"alt":7,"src":37},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/07/31/b75018fe84e64fc3ab4e67fb0690eb7c.png",[],{"type":18,"tag":26,"props":40,"children":41},{},[42,44],{"type":24,"value":43},"Download the model: ",{"type":18,"tag":45,"props":46,"children":50},"a",{"href":47,"rel":48},"https://gitee.com/mindspore/models/tree/master/official/cv/YOLOv5",[49],"nofollow",[51],{"type":24,"value":47},{"type":18,"tag":26,"props":53,"children":54},{},[55],{"type":24,"value":56},"You can use the pre-trained weights, skipping the training process as it consumes much time and machine resources.",{"type":18,"tag":26,"props":58,"children":59},{},[60,62],{"type":24,"value":61},"Download the pre-trained weights: ",{"type":18,"tag":45,"props":63,"children":65},{"href":64},"%20https:/download.mindspore.cn/models/r1.10/yolov5shape640_ascend_v1100_coco2017_official_cv_acc36.6.ckpt",[66],{"type":24,"value":67},"https://download.mindspore.cn/models/r1.10/yolov5shape640_ascend_v1100_coco2017_official_cv_acc36.6.ckpt",{"type":18,"tag":26,"props":69,"children":70},{},[71],{"type":24,"value":72},"After the required file is downloaded, export MindIR:",{"type":18,"tag":26,"props":74,"children":75},{},[76],{"type":24,"value":77},"python export.py --ckpt_file [CKPT_PATH] --file_name [FILE_NAME] --file_format [FILE_FORMAT]",{"type":18,"tag":26,"props":79,"children":80},{},[81],{"type":18,"tag":82,"props":83,"children":84},"strong",{},[85],{"type":24,"value":86},"export.py --ckpt_file yolov5shape640_ascend_v1100_coco2017_official_cv_acc36.6.ckpt --file_name yolov5.mindir --file_format MINDIR",{"type":18,"tag":26,"props":88,"children":89},{},[90,92,97,99,104,106,111],{"type":24,"value":91},"Note that ",{"type":18,"tag":82,"props":93,"children":94},{},[95],{"type":24,"value":96},"file_name",{"type":24,"value":98}," in the preceding example is not set correctly, which should be a name without a suffix. If ",{"type":18,"tag":82,"props":100,"children":101},{},[102],{"type":24,"value":103},"yolov5.mindir",{"type":24,"value":105}," is used, ",{"type":18,"tag":82,"props":107,"children":108},{},[109],{"type":24,"value":110},"yolov5.mindir_yolov5s.mindir",{"type":24,"value":112}," is generated finally.",{"type":18,"tag":26,"props":114,"children":115},{},[116,120,122],{"type":18,"tag":35,"props":117,"children":119},{"alt":7,"src":118},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/07/31/0499cbb30f1d470995141d0356159b6f.png",[],{"type":24,"value":121}," ",{"type":18,"tag":35,"props":123,"children":125},{"alt":7,"src":124},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/07/31/7d9c8e1020a8441db494d52a43f698e6.png",[],{"type":18,"tag":26,"props":127,"children":128},{},[129],{"type":24,"value":130},"An error message is displayed, indicating a required dependency is missing. Replace the name of the module with the actual one to be installed in your environment",{"type":18,"tag":26,"props":132,"children":133},{},[134],{"type":18,"tag":82,"props":135,"children":136},{},[137],{"type":24,"value":138},"pip install pyyaml",{"type":18,"tag":26,"props":140,"children":141},{},[142],{"type":18,"tag":35,"props":143,"children":145},{"alt":7,"src":144},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/07/31/b813006bcd91430d8c9ba33676d2c328.png",[],{"type":18,"tag":26,"props":147,"children":148},{},[149,151,156],{"type":24,"value":150},"If an error indicating that the device target is incorrect is reported after the installation, check ",{"type":18,"tag":82,"props":152,"children":153},{},[154],{"type":24,"value":155},"default_config.yaml",{"type":24,"value":157}," under the directory.",{"type":18,"tag":26,"props":159,"children":160},{},[161],{"type":18,"tag":35,"props":162,"children":164},{"alt":7,"src":163},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/07/31/a75a26ec9d7f4d3f9c840dedcf7a80d7.png",[],{"type":18,"tag":26,"props":166,"children":167},{},[168,170,175,177,182],{"type":24,"value":169},"The default device is ",{"type":18,"tag":82,"props":171,"children":172},{},[173],{"type":24,"value":174},"Ascend",{"type":24,"value":176},". Change it to ",{"type":18,"tag":82,"props":178,"children":179},{},[180],{"type":24,"value":181},"CPU",{"type":24,"value":183},".",{"type":18,"tag":26,"props":185,"children":186},{},[187,191,192],{"type":18,"tag":35,"props":188,"children":190},{"alt":7,"src":189},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/07/31/5726ae966d3640aaacb649e617bdc3ac.png",[],{"type":24,"value":121},{"type":18,"tag":35,"props":193,"children":195},{"alt":7,"src":194},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/07/31/5546b05e7d3542689b1e2e3dd607e18b.png",[],{"type":18,"tag":26,"props":197,"children":198},{},[199,201,206],{"type":24,"value":200},"When developing a new model, you need to copy some files to the execution directory and compile ",{"type":18,"tag":82,"props":202,"children":203},{},[204],{"type":24,"value":205},"main.cc",{"type":24,"value":207}," for execution.",{"type":18,"tag":26,"props":209,"children":210},{},[211,216,218,223,225,229,231,236],{"type":18,"tag":82,"props":212,"children":213},{},[214],{"type":24,"value":215},"cpp_infer",{"type":24,"value":217}," of some models do not contain the ",{"type":18,"tag":82,"props":219,"children":220},{},[221],{"type":24,"value":222},"common_inc",{"type":24,"value":224}," folder. In this case, you need to copy this folder to the same directory as ",{"type":18,"tag":82,"props":226,"children":227},{},[228],{"type":24,"value":205},{"type":24,"value":230}," (varying with the ",{"type":18,"tag":82,"props":232,"children":233},{},[234],{"type":24,"value":235},"makefile",{"type":24,"value":237}," in different projects) for execution.",{"type":18,"tag":26,"props":239,"children":240},{},[241,245],{"type":18,"tag":82,"props":242,"children":243},{},[244],{"type":24,"value":205},{"type":24,"value":246}," contains script files for model inference, performing the following functions:",{"type":18,"tag":26,"props":248,"children":249},{},[250],{"type":24,"value":251},"● Model loading and building",{"type":18,"tag":26,"props":253,"children":254},{},[255],{"type":24,"value":256},"● Dataset building/bin file loading",{"type":18,"tag":26,"props":258,"children":259},{},[260],{"type":24,"value":261},"● Model inference",{"type":18,"tag":26,"props":263,"children":264},{},[265],{"type":24,"value":266},"● Inference result saving",{"type":18,"tag":26,"props":268,"children":269},{},[270,272,276,278,283,285,292],{"type":24,"value":271},"For example, copy ",{"type":18,"tag":82,"props":273,"children":274},{},[275],{"type":24,"value":222},{"type":24,"value":277}," to the same directory as ",{"type":18,"tag":82,"props":279,"children":280},{},[281],{"type":24,"value":282},"build.sh",{"type":24,"value":284}," in the Gitee repository (",{"type":18,"tag":45,"props":286,"children":289},{"href":287,"rel":288},"https://gitee.com/mindspore/models/tree/master/utils/cpp%5C_infer/example",[49],[290],{"type":24,"value":291},"https://gitee.com/mindspore/models/tree/master/utils/cpp\\_infer/example",{"type":24,"value":293},").",{"type":18,"tag":26,"props":295,"children":296},{},[297],{"type":18,"tag":35,"props":298,"children":300},{"alt":7,"src":299},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/07/31/4630839ae1ba4fcda7b9976f1fc28c58.png",[],{"type":18,"tag":26,"props":302,"children":303},{},[304],{"type":18,"tag":35,"props":305,"children":307},{"alt":7,"src":306},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/07/31/2effd33a72ed44e1ace16f1ee839a9b1.png",[],{"title":7,"searchDepth":309,"depth":309,"links":310},4,[],"markdown","content:technology-blogs:en:2676.md","content","technology-blogs/en/2676.md","technology-blogs/en/2676","md",1776506106852]