配置yolov5环境
创建一个python环境,直接按照文档配置好环境就行(https://github.com/ultralytics/yolov5)
(环境如果没有pytorch配置文件会自动安装最新版,可能会有版本不匹配的问题,建议先自己手动安装合适版本的pytorch)
git clone https://github.com/ultralytics/yolov5 # clone
cd yolov5
pip install -r requirements.txt # install
后面在4*1080ti上运行时遇到报错:RuntimeError: GET was unable to find an engine to execute this computation,
经过查资料应该是cuda版本和torch版本不匹配,使用nvidia-smi查看cuda版本,显示为11.4,然后去pytorch官网找老版本,没有11.4对应版本,查找资料说是可以使用11.3的,
然后卸载现有的torch,复制官网的安装代码重新安装torch后解决问题。
在双2080ti配置yolov5环境时无法安装新版本的库,并提示DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.
上述问题暂时还未解决,使用which python查看解释器位置没问题,使用which pip查看时发现与师兄不一样,应该是这个原因。
使用3090ti机器未遇到任何上述问题。
后台运行python程序
nohup 代码 & // 后台执行代码,并将自动将输出记录到nohup.out文件
nohup 代码 >> nohup.out 2>&1 & //效果同上,可以改.out文件名实现同时运行多个程序
ps -aux | grep python //可以检索正在运行的进程
kill -9 进程id //关闭进程
运行demo
单张图片检测运行速度很快,将要检测的图片复制到yolov5目录下(或者在图片前面写上路径),然后使用代码运行
python detect.py --weights yolov5s.pt --source 0 # webcam
img.jpg # image
vid.mp4 # video
screen # screenshot
path/ # directory
list.txt # list of images
list.streams # list of streams
'path/*.jpg' # glob
'https://youtu.be/Zgi9g1ksQHc' # YouTube
'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream
运行结果如下,生成一张新图片:增加bounding box及检测类型及其概率
运行coco128也很快
python train.py --img 640 --epochs 3 --data coco128.yaml --weights yolov5s.pt
运行结果如下
运行coco数据集时较慢,在双2080ti上每个epoch大概6分钟(yolov5s.yaml --batch-size 64),300个大概运行30小时(暂时还没运行完),使用1080机器运行每个epoch要十几分钟(yolov5n.yaml --batch-size 128)就关掉了。