MindSpore Cases—Running YOLOv5 on Raspberry Pi for Real-Time Object Detection (2)
MindSpore Cases—Running YOLOv5 on Raspberry Pi for Real-Time Object Detection (2)
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).

Download the model: https://gitee.com/mindspore/models/tree/master/official/cv/YOLOv5
You can use the pre-trained weights, skipping the training process as it consumes much time and machine resources.
Download the pre-trained weights: https://download.mindspore.cn/models/r1.10/yolov5shape640_ascend_v1100_coco2017_official_cv_acc36.6.ckpt
After the required file is downloaded, export MindIR:
python export.py --ckpt_file [CKPT_PATH] --file_name [FILE_NAME] --file_format [FILE_FORMAT]
export.py --ckpt_file yolov5shape640_ascend_v1100_coco2017_official_cv_acc36.6.ckpt --file_name yolov5.mindir --file_format MINDIR
Note that file_name in the preceding example is not set correctly, which should be a name without a suffix. If yolov5.mindir is used, yolov5.mindir_yolov5s.mindir is generated finally.

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
pip install pyyaml

If an error indicating that the device target is incorrect is reported after the installation, check default_config.yaml under the directory.

The default device is Ascend. Change it to CPU.

When developing a new model, you need to copy some files to the execution directory and compile main.cc for execution.
cpp_infer of some models do not contain the common_inc folder. In this case, you need to copy this folder to the same directory as main.cc (varying with the makefile in different projects) for execution.
main.cc contains script files for model inference, performing the following functions:
● Model loading and building
● Dataset building/bin file loading
● Model inference
● Inference result saving
For example, copy common_inc to the same directory as build.sh in the Gitee repository (https://gitee.com/mindspore/models/tree/master/utils/cpp\_infer/example).

