在用树莓派部署yolov5的过程中我走了很多弯路,这里写一篇文章希望能帮助朋友们解决一些问题,不要像我一样走了很多弯路。如果说您遇到了其他关于树莓派的问题,可以在评论区提出来或者私信我,如果我会的话可以给您解答。
准备工作:64位的树莓派系统镜像
安装各种库的时候最好换国内源,国外源安装的太慢并且有时候会安装不上(安装时这里可以install后加一个 -i https://pypi.tuna.tsinghua.edu.cn/simple
一.安装pytroch
要点:1.必须要用64位的系统镜像,32位的系统镜像安装不了pytorch
2.pytorch一定不要用最新版,最新版的版本与树莓派的系统可能报错
3.pytorch的版本和pytorchvision的版本一定要对应
我这里pytorch的版本是1.8.1
pip install torch==1.8.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
pytorchvision的版本是0.9.1 大家可以和我用相同的版本
pip install torchvision==0.9.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
二.安装opencv
第一步:用树莓派64位安装opencv很简单,如果用32位的话会很复杂
这里咱们用的是64位的系统镜像,可以直接
pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple
第二步:更新numpy(这里一定要安装小于numpy2.0的版本,安装numpy>=2.0的版本会报错)
pip install numpy --upgrade -i https://pypi.tuna.tsinghua.edu.cn/simple
安装完后可以输入命令查看 pip show numpy
如果下载之后是>=2.0的版本
卸载numpy命令 pip uninstall numpy
安装指定版本的numpy命令 pip install -U numpy== 1.xx.xx (我这里用的是1.19.2)
三.安装yolov5
下载yolov5
https://doc.itprojects.cn/0007.zhishi.raspberrypi/03.download/yolov5-master.zip
下载完之后解压,传输文件到树莓派里
可以用WinSCP进行传输(个人比较爱用,大家随意,如果想用可以去官网下载,很简单)
接下来进入到yolov5-master文件夹,安装依赖
安装时间较长,大家耐心等待
将训练好的best.pt文件放到yolov5-master中并将测试图片放到对应的文件夹中,我问这里是data/bing/test
python3 detect.py --weight best.pt --source data/bing/test
测试结果在runs/detect/exp10中(我这里是随便训练的一个模型,识别率只有百分之27,大家如果说想要识别精度高一些,用labelimg标记的图片质量一定要高,对识别的精度有很大的影响)
四.关于各种报错的问题(我个人遇到的问题)
1.关于AttributeError: Can‘t get attribute ‘DetectionModel‘ on <module ‘models.yolo‘报错的问题,可以去直接搜 《[记录解决YOLOv5加载权重文件报错问题]AttributeError: Can‘t get attribute ‘DetectionModel‘ on <module ‘models.yolo‘》-weixin00000
2.关于NotImplementedError: cannot instantiate ‘WindowsPath‘ on your system报错的问题,可以去搜《成功解决NotImplementedError: cannot instantiate ‘WindowsPath‘ on your system》-逍遥x
3.如果你出现了RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd报错的问题,那就是你numpy版本的问题,一定要安装1.xx.xx版本的.
4.如果你出现了Can‘t get attribute ‘DetectionModel‘ on <module ‘models.yolo‘ from ‘D:\\PY-Documents\\YOLOv5的报错,去搜索《YOLOV5出现Can‘t get attribute ‘DetectionModel‘ on <module ‘models.yolo‘ from ‘D:\\PY-Documents\\YOLOv5》-真好xxx
5.如果出现AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from,搜索《运行YOLOv5出现报错找不到SPPF错误,进行解决AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from》-tt花xx